local config = {
daysToAdd = 14, -- How many days do you want to add?
maxDays = 500, -- If the player has greater than or equal to (>=) this many days send him a cancel to prevent wasting the item
failEffect = CONST_ME_POFF, -- What type of magic effect do you want to send upon FAILURE?
successEffect = CONST_ME_MAGIC_RED, -- What type of magic effect do you want to send upon SUCCESS?
msgType = MESSAGE_INFO_DESCR -- message type
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
-- establish the variables that we used more than once
local premDays = getPlayerPremiumDays(cid)
local playerPos = getCreaturePosition(cid)
-- Check to see if the player doesn't already have plenty of days left
if premDays >= config.maxDays then
doPlayerSendTextMessage(cid, config.msgType, config.msgType, 'You currently have ' .. premDays .. ' premium day' .. (premDays > 1 and 's' or '') .. ' left. You many only add more premium time once you are below ' .. config.maxDays .. ' premium day' .. (config.maxDays > 1 and 's' or '') .. '.')
doSendMagicEffect(playerPos, config.failEffect)
return false
end
-- If all checks have passed then go ahead and remove the item and add the days
doRemoveItem(item.uid, 1)
doPlayerAddPremiumDays(cid, config.daysToAdd)
doSendMagicEffect(playerPos, config.successEffect)
doPlayerSendTextMessage(cid, config.msgType, 'Congratulations, you have successfully added ' .. config.daysToAdd .. ' premium day' .. (config.daysToAdd > 1 and 's' or '') .. ' to your account!')
return true
end