Hello guys,
I created a script when you use tokens (gold, platinum, etc..) you have certain amount o tibia coin but what I did isn't the right way.
Could someone help me to get it better?
I created a script when you use tokens (gold, platinum, etc..) you have certain amount o tibia coin but what I did isn't the right way.
Could someone help me to get it better?
Lua:
local setting = {
[25376] = {Type = "iron", count = 1000},
[25377] = {Type = "gold", count = 1500},
[25378] = {Type = "cooper", count = 2000},
[25379] = {Type = "platinum", count = 2500},
[25380] = {Type = "titanium", count = 3000}
}
local tibiaCoin = Action()
function tibiaCoin.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local foundItem = setting[item.itemid]
if not(foundItem) then
return
end
if foundItem.Type == "iron" then
db.query("UPDATE `accounts` SET `coins` = `coins` + " ..foundItem.count.. " WHERE id=" ..player:getAccountId())
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have received '..foundItem.count..' tibia coins.')
elseif foundItem.Type == "gold" then
db.query("UPDATE `accounts` SET `coins` = `coins` + " ..foundItem.count.. " WHERE id=" ..player:getAccountId())
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have received '..foundItem.count..' tibia coins.')
elseif foundItem.Type == "cooper" then
db.query("UPDATE `accounts` SET `coins` = `coins` + " ..foundItem.count.. " WHERE id=" ..player:getAccountId())
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have received '..foundItem.count..' tibia coins.')
elseif foundItem.Type == "platinum" then
db.query("UPDATE `accounts` SET `coins` = `coins` + " ..foundItem.count.. " WHERE id=" ..player:getAccountId())
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have received '..foundItem.count..' tibia coins.')
elseif foundItem.Type == "titanium" then
db.query("UPDATE `accounts` SET `coins` = `coins` + " ..foundItem.count.. " WHERE id=" ..player:getAccountId())
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have received '..foundItem.count..' tibia coins.')
end
item:remove(1)
return true
end
tibiaCoin:id(25376, 25377, 25378, 25379, 25380)
tibiaCoin:register()