• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Tibia Coins on level advance (Reward)

Delev

New Member
Joined
Dec 16, 2019
Messages
3
Reaction score
0
I wanted a system that would add coins to the players account when the character reaches a specific level.

I found something similar, but it gives items, I want to give the coins straight into the account.

Lua:
function onAdvance(cid, skill, oldLevel, newLevel)

local config = {
[50] = {item = 2160, count = 1},
}

if skill == 8 then
for level, info in pairs(config) do
if newLevel >= level and (getPlayerStorageValue(cid, 30700) == -1 or not (string.find(getPlayerStorageValue(cid, 30700), "'" .. level .. "'"))) then
doPlayerAddItem(cid, info.item, info.count)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Parabéns, você atingiu o level "..newLevel.." e ganhou "..info.count.." "..getItemNameById(info.item)..".")
local sat = getPlayerStorageValue(cid, 30700) == -1 and "Values: '" .. level .. "'" or getPlayerStorageValue(cid, 30700) .. ",'" .. level .. "'"
setPlayerStorageValue(cid, 30700, sat)
end
end
end

return TRUE
end

While researching I found a tibia coins action that adds to the database when using the item, the code includes:

Lua:
local count = 50
db.query('UPDATE accounts SET coins = coins+'.. count ..' WHERE id = ' .. getAccountNumberByPlayerName(getCreatureName(cid)))

How can I replace the additem with this query without destroying the logic?
 
change line 10 with the one you found

Like this?

Lua:
function onAdvance(cid, skill, oldLevel, newLevel)

local config = {
[50] = {count = 50},
[100] = {count = 50},
}

if skill == 8 then
for level, info in pairs(config) do
if newLevel >= level and (getPlayerStorageValue(cid, 30700) == -1 or not (string.find(getPlayerStorageValue(cid, 30700), "'" .. level .. "'"))) then
db.query('UPDATE accounts SET coins = coins+'.. info.count ..' WHERE id = ' .. getAccountNumberByPlayerName(getCreatureName(cid)))
local sat = getPlayerStorageValue(cid, 30700) == -1 and "Values: '" .. level .. "'" or getPlayerStorageValue(cid, 30700) .. ",'" .. level .. "'"
setPlayerStorageValue(cid, 30700, sat)
end
end
end

return TRUE
end
 
Back
Top