• 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!

Lua TFS 1.3 BUY FOR TIBIA COINS COMMAND

Cys9211

Sencor!
Joined
Aug 21, 2008
Messages
102
Reaction score
4
Location
Poland (Bełchatów)
Hello, are you able to rewrite this script to buy "AOL" for Tibia Coins?
TFS 1.3
Tibia Coins taken from the Account table from "Coins"

Lua:
local aol= TalkAction("!aol")
local price_aol = 50000

function aol.onSay(player, words, param)
  
    if player:removeMoneyNpc(price_aol) then
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
        player:addItem(2173, 1)
else
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:sendCancelMessage("You dont have enought money.")
    end
        logCommand(player, words, param)
end
aol:separator(" ")
aol:register()
 
Solution
Lua:
function getAccountCoins(account_id)
    local coins = 0
    local resultId = db.storeQuery("SELECT `coins` FROM `accounts` WHERE `id`='"..tonumber(account_id).."' LIMIT 1;")
    if resultId ~= false then
        coins = result.getDataInt(resultId, "coins")
        result.free(resultId)
    end
    return coins
end

function setAccountCoins(account_id, coins)
    db.query("UPDATE `accounts` SET `coins`='"..tonumber(coins).."' WHERE `id`='"..tonumber(account_id).."' LIMIT 1;")
end

function removeAccountCoins(account_id, removeCoins)
    local remainingCoins = getAccountCoins(account_id) - removeCoins
    if remainingCoins < 0 then
        return false
    end
    setAccountCoins(account_id, remainingCoins)
    return true
end


local...
Lua:
function getAccountCoins(account_id)
    local coins = 0
    local resultId = db.storeQuery("SELECT `coins` FROM `accounts` WHERE `id`='"..tonumber(account_id).."' LIMIT 1;")
    if resultId ~= false then
        coins = result.getDataInt(resultId, "coins")
        result.free(resultId)
    end
    return coins
end

function setAccountCoins(account_id, coins)
    db.query("UPDATE `accounts` SET `coins`='"..tonumber(coins).."' WHERE `id`='"..tonumber(account_id).."' LIMIT 1;")
end

function removeAccountCoins(account_id, removeCoins)
    local remainingCoins = getAccountCoins(account_id) - removeCoins
    if remainingCoins < 0 then
        return false
    end
    setAccountCoins(account_id, remainingCoins)
    return true
end


local aol = TalkAction("!aol")
local price_aol = 50000

function aol.onSay(player, words, param)
    local account_id = player:getAccountId()
    if removeAccountCoins(account_id, price_aol) then
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
        player:addItem(2173, 1)
    else
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:sendCancelMessage("You dont have enought coins. (missing: "..price_aol - getAccountCoins(account_id)..")")
    end
    logCommand(player, words, param)
end
aol:separator(" ")
aol:register()
 
Solution
Back
Top