• 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 set playertotalmoney

carlinhous1996

New Member
Joined
Apr 14, 2022
Messages
54
Reaction score
3
I need help creating a code that changes the character's total money value, taking into account backpack money and bank money.

I need it to be something like this:
setPlayerTotalMoney(who)

my friend helped me by creating the following code:
Lua:
--[[
    O que preciso que o script faça:
        Preciso que ele me retorne o valor do resultado da soma entre bankBalance e playerMoney
]]

function getPlayerTotalMoney(who)
    local bankBalance, playerMoney = getPlayerBalance(who), getPlayerMoney(who)
    if ((bankBalance > 0) or (playerMoney > 0)) then
        return bankBalance + playerMoney
    else
        return 0
    end
end
-- print(getPlayerTotalMoney())

my friend said that to create the setPlayerTotalMoney(who) code you need to use Query
Can someone help me?
 
Hi!
I understand. You want a function to remove the player's money regardless of whether it's in the backpack or the bank.
Try this:
Lua:
--[[
    Function to remove the player's money, regardless of whether it is in the backpack or in the bank.
    Note: It will always give priority to the money located in the backpack.
]]
function doPlayerRemoveTotalMoney(who, value)
    local bankBalance, playerMoney = getPlayerBalance(who), getPlayerMoney(who)
    if playerMoney >= value then
        doPlayerRemoveMonney(who, value)
    elseif bankBalance >= value then
        db.executeQuery("UPDATE `players` SET `balance` = ".. getPlayBalance(who) .." - ".. value .." WHERE `id` = " .. getPlayerGUID(who) .. ";")
    end

    return true
end
 
I created a script with predetermined variables to do tests.
In this case, bankBalance is at 20000, and playerMoney is at 9000.
The problem with this script is that it will not remove from the backpack and also from the bank.
He will only remove it from the backpack if he has the money, otherwise he will only remove it from the bank.

Lua:
function doPlayerRemoveTotalMoney(value)
    bankBalance = 20000
    playerMoney = 9000
    totalMoney = bankBalance + playerMoney

    if totalMoney >= value then
        if playerMoney >= value then
            playerMoney = playerMoney - value
        elseif playerMoney < value and bankBalance >= value then
            bankBalance = bankBalance - value
        end
    else
        return false
    end
end

If anyone knows how to do this algorithm, it will help the guy who asked for help a lot. haha
 
I created a script with predetermined variables to do tests.
In this case, bankBalance is at 20000, and playerMoney is at 9000.
The problem with this script is that it will not remove from the backpack and also from the bank.
He will only remove it from the backpack if he has the money, otherwise he will only remove it from the bank.

Lua:
function doPlayerRemoveTotalMoney(value)
    bankBalance = 20000
    playerMoney = 9000
    totalMoney = bankBalance + playerMoney

    if totalMoney >= value then
        if playerMoney >= value then
            playerMoney = playerMoney - value
        elseif playerMoney < value and bankBalance >= value then
            bankBalance = bankBalance - value
        end
    else
        return false
    end
end

If anyone knows how to do this algorithm, it will help the guy who asked for help a lot. haha
What remove means? Delete forever?
 
Maybe this will work:
Lua:
--[[
    Function to remove the player's money, regardless of whether it is in the backpack or in the bank.
    Note: It will always give priority to the money located in the backpack.
]]
function doPlayerRemoveTotalMoney(who, value)
    if getPlayerTotalMoney(who) >= value then
        local playerMoney = getPlayerMoney(who)
        payment = playerMoney - value
        doPlayerRemoveMoney(who, payment)
        if playerMoney == 0 then
            db.executeQuery("UPDATE `players` SET `balance` = " ..
                getPlayerBalance(who) .. " - " .. payment .. " WHERE `id` = " .. getPlayerGUID(who) .. ";")
        end
    else
        return false
    end

    return true
end
 
Lua:
function getPlayerTotalMoney(cid)
    return getPlayerMoney(cid) + getPlayerBalance(cid)
end

Lua:
function doRemovePlayerTotalMoney(cid, amount)

    local bankGold = getPlayerBalance(cid)
    local playerGold = getPlayerMoney(cid)

    if (bankGold + playerGold) < amount then
        return false
    end

    if playerGold > 0 then
        local removeGold = math.min(playerGold, amount)
        doPlayerRemoveMoney(cid, removeGold)

        amount = amount - removeGold
    end

    if amount > 0 then
        doPlayerSetBalance(cid, bankGold - amount)
    end

    return true
end
 
Back
Top