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

!aor with storage!

RogaliS

New Member
Joined
Jul 27, 2016
Messages
18
Reaction score
1
Hello i need help to buy aol when player have storage.

Code:
local cost = 40000000 -- How much does it cost?
function onTalk(cid, word, param)
        playerstorage = getPlayerStorageValue(cid,7522)
        if playerstorage == 1 then
        doPlayerRemoveMoney(cid, cost)
         doPlayerAddItem(cid,2196,1) 
         doPlayerSendTextMessage(cid,22,"You bought AOR for 40 scarab coins!")
    else
        doPlayerSendTextMessage(cid,22,"You need to complete mission to use this command!")
end
     else
        doPlayerSendTextMessage(cid,22,"you dont have money!")
        end
    return TRUE
end

This scripts its not work ;/
 
b1hyTdf.png


Vb1JnS1.png


This is why proper tabbing is important and should be the first thing you learn above anything else.
The moment you properly tab a script, the issue becomes readily apparent. (and also makes it easier to read.. but hey.)


try this.
Lua:
local config = {
    cost = 40000000, -- How much does it cost?
    aor = 2196,
    amount = 1,
    storage = 7522
}

function onTalk(cid, word, param)
    if getPlayerStorageValue(cid, config.storage) < 1 then
        doPlayerSendTextMessage(cid, MESSAGE_DAMAGE_RECEIVED, "You need to complete a mission to use this command!")
        return true
    end
    if getPlayerMoney(cid) < config.cost then
        doPlayerSendTextMessage(cid, MESSAGE_DAMAGE_RECEIVED, "You don't have enough money!")
        return true
    end
    doPlayerRemoveMoney(cid, config.cost)
    doPlayerAddItem(cid, config.aor, config.amount)
    doPlayerSendTextMessage(cid, MESSAGE_DAMAGE_RECEIVED, "You bought AOR for 40 scarab coins!")
    return true
end
 
Last edited:
Code:
if getPlayerMoney(cid) < config.cost then
i have dont declared in my source.
Have only
Code:
getPlayerItemCount
I using 7.6 distro XML version.
 
Honestly, I have no idea if this is even the best way to do this..

and you'll have to edit it for whatever weird currency your server has

Lua:
local function getPlayerMoney(cid)
    local amount = 0
    local player_gold = getPlayerItemCount(cid, ITEM_GOLD_COIN)
    local player_plat = getPlayerItemCount(cid, ITEM_PLATINUM_COIN) * 100
    local player_crys = getPlayerItemCount(cid, ITEM_CRYSTAL_COIN) * 10000
    amount = player_gold + player_plat + player_crys
    return amount
end

local function doPlayerRemoveMoney(cid, amount)
    local total_gold = getPlayerMoney(cid)
    if total_gold < amount then
        return false
    end
 
    -- remove gold coins
    local gold_count = getPlayerItemCount(cid, ITEM_GOLD_COIN)
    if gold_count > 0 then
        if gold_count >= amount then
            doPlayerRemoveItem(cid, ITEM_GOLD_COIN, amount)
            return true
        else
            doPlayerRemoveItem(cid, ITEM_GOLD_COIN, gold_count)
            amount = amount - gold_count
        end
    end
 
    -- remove platinum coins
    local platinum_count = getPlayerItemCount(cid, ITEM_PLATINUM_COIN)
    if platinum_count > 0 then
        if platinum_count * 100 >= amount then
            if amount >= 100 then
                local plat_1 = 0
                repeat
                    plat_1 = plat_1 + 1
                    amount = amount - 100
                until amount < 100
                doPlayerRemoveItem(cid, ITEM_PLATINUM_COIN, plat_1)
                if amount == 0 then
                    return true
                end
            end
            -- give change (gold)
            doPlayerRemoveItem(cid, ITEM_PLATINUM_COIN, 1)
            amount = 100 - amount
            doPlayerAddItem(cid, ITEM_GOLD_COIN, amount)
            return true
        else
            doPlayerRemoveItem(cid, ITEM_PLATINUM_COIN, platinum_count)
            amount = amount - (platinum_count * 100)
        end
    end

    -- remove crystal coins
    if amount >= 10000 then
        local crys = 0
        repeat
            crys = crys + 1
            amount = amount - 10000
        until amount < 10000
        doPlayerRemoveItem(cid, ITEM_CRYSTAL_COIN, crys)
        if amount == 0 then
            return true
        end
    end
 
    doPlayerRemoveItem(cid, ITEM_CRYSTAL_COIN, 1)
    amount = 10000 - amount
    -- give change (platinum)
    if amount >= 100 then
        local plat_2 = 0
        repeat
            plat_2 = plat_2 + 1
            amount = amount - 100
        until amount < 100
        doPlayerAddItem(cid, ITEM_PLATINUM_COIN, plat_2)
        if amount == 0 then
            return true
        end
    end
    -- give change (gold)
    doPlayerAddItem(cid, ITEM_GOLD_COIN, amount)
    return true
end
Lua:
if getPlayerMoney(cid) >= 10000000 then
    doPlayerRemoveMoney(cid, 10000000)
end

-- Edit
Found a ton of problems with my original script, and took like 8 hours doing different stuff until I came up with a pretty good system. lmao
 
Last edited:
Back
Top