• 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 Changing gold doesn't work correctly.

Benna

Member
Joined
Jul 3, 2008
Messages
150
Reaction score
7
Alright so if i right click any stack that's on the floor with etc 100 gold coin, platinum, crystal coin i will receive the changing amount to my main backpack but the money will still be on the floor.

So how do i fix it? This is my current goldchanger action lua.


Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == ITEM_GOLD_COIN and item.type == ITEMCOUNT_MAX then
        doPlayerRemoveItem(cid, ITEM_GOLD_COIN, ITEMCOUNT_MAX)
        doPlayerAddItem(cid, ITEM_PLATINUM_COIN, 1)
    elseif item.itemid == ITEM_PLATINUM_COIN and item.type == ITEMCOUNT_MAX then
        doPlayerRemoveItem(cid, ITEM_PLATINUM_COIN, ITEMCOUNT_MAX)
        doPlayerAddItem(cid, ITEM_CRYSTAL_COIN, 1)
    elseif item.itemid == ITEM_PLATINUM_COIN and item.type < ITEMCOUNT_MAX then
        doPlayerRemoveItem(cid, ITEM_PLATINUM_COIN, 1)
        doPlayerAddItem(cid, ITEM_GOLD_COIN, ITEMCOUNT_MAX)
    elseif item.itemid == ITEM_CRYSTAL_COIN then
        doPlayerRemoveItem(cid, ITEM_CRYSTAL_COIN, 1)
        doPlayerAddItem(cid, ITEM_PLATINUM_COIN, ITEMCOUNT_MAX)
    else
        return FALSE
    end
    return TRUE
end
 
And you have capacity and room in backpack?
Yes, that's not the issue. The issue is that they can gain more cash with this method -> put 100 gold coin on floor -> right click on it -> they receive 1 platinum coin for each click to their main backpack and the gold is still there on the ground.
 
try use
doRemoveItem(item.uid)

instead of
doPlayerRemoveItem(cid, ITEM_GOLD_COIN, ITEMCOUNT_MAX)
 
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == ITEM_GOLD_COIN and item.type == ITEMCOUNT_MAX then
        doPlayerAddItem(cid, ITEM_PLATINUM_COIN, 1)
    elseif item.itemid == ITEM_PLATINUM_COIN and item.type == ITEMCOUNT_MAX then
        doPlayerAddItem(cid, ITEM_CRYSTAL_COIN, 1)
    elseif item.itemid == ITEM_PLATINUM_COIN and item.type < ITEMCOUNT_MAX then
        doPlayerAddItem(cid, ITEM_GOLD_COIN, ITEMCOUNT_MAX)
    elseif item.itemid == ITEM_CRYSTAL_COIN then
        doPlayerAddItem(cid, ITEM_PLATINUM_COIN, ITEMCOUNT_MAX)
    else
        return FALSE
    end
    doRemoveItem(item.uid)
    return TRUE
end
 
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == ITEM_GOLD_COIN and item.type == ITEMCOUNT_MAX then
        doPlayerAddItem(cid, ITEM_PLATINUM_COIN, 1)
    elseif item.itemid == ITEM_PLATINUM_COIN and item.type == ITEMCOUNT_MAX then
        doPlayerAddItem(cid, ITEM_CRYSTAL_COIN, 1)
    elseif item.itemid == ITEM_PLATINUM_COIN and item.type < ITEMCOUNT_MAX then
        doPlayerAddItem(cid, ITEM_GOLD_COIN, ITEMCOUNT_MAX)
    elseif item.itemid == ITEM_CRYSTAL_COIN then
        doPlayerAddItem(cid, ITEM_PLATINUM_COIN, ITEMCOUNT_MAX)
    else
        return FALSE
    end
    doRemoveItem(item.uid)
    return TRUE
end
It works, however now when you click on on etc 100 crystal coins in the backpack the money disapears.
 
Move doRemoveItem(item.uid) above
if item.itemid == ITEM_GOLD_COIN and item.type == ITEMCOUNT_MAX then

Like this:

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    doRemoveItem(item.uid)
    if item.itemid == ITEM_GOLD_COIN and item.type == ITEMCOUNT_MAX then
        doPlayerAddItem(cid, ITEM_PLATINUM_COIN, 1)
    elseif item.itemid == ITEM_PLATINUM_COIN and item.type == ITEMCOUNT_MAX then
        doPlayerAddItem(cid, ITEM_CRYSTAL_COIN, 1)
    elseif item.itemid == ITEM_PLATINUM_COIN and item.type < ITEMCOUNT_MAX then
        doPlayerAddItem(cid, ITEM_GOLD_COIN, ITEMCOUNT_MAX)
    elseif item.itemid == ITEM_CRYSTAL_COIN then
        doPlayerAddItem(cid, ITEM_PLATINUM_COIN, ITEMCOUNT_MAX)
    else
        return FALSE
    end
    return TRUE
end
 
It works, however now when you click on on etc 100 crystal coins in the backpack the money disapears.

idk if it works give it a shot :)
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == ITEM_GOLD_COIN and item.type == ITEMCOUNT_MAX then
        doRemoveItem(item.uid)
        doPlayerAddItem(cid, ITEM_PLATINUM_COIN, 1)
    elseif item.itemid == ITEM_PLATINUM_COIN and item.type == ITEMCOUNT_MAX then
      doRemoveItem(item.uid)
        doPlayerAddItem(cid, ITEM_CRYSTAL_COIN, 1)
    elseif item.itemid == ITEM_PLATINUM_COIN and item.type < ITEMCOUNT_MAX then
      doRemoveItem(item.uid)
        doPlayerAddItem(cid, ITEM_GOLD_COIN, ITEMCOUNT_MAX)
    elseif item.itemid == ITEM_CRYSTAL_COIN then
      doRemoveItem(item.uid)
        doPlayerAddItem(cid, ITEM_PLATINUM_COIN, ITEMCOUNT_MAX)
    else
        return FALSE
    end
    return TRUE
end
 
idk if it works give it a shot :)
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == ITEM_GOLD_COIN and item.type == ITEMCOUNT_MAX then
        doRemoveItem(item.uid)
        doPlayerAddItem(cid, ITEM_PLATINUM_COIN, 1)
    elseif item.itemid == ITEM_PLATINUM_COIN and item.type == ITEMCOUNT_MAX then
      doRemoveItem(item.uid)
        doPlayerAddItem(cid, ITEM_CRYSTAL_COIN, 1)
    elseif item.itemid == ITEM_PLATINUM_COIN and item.type < ITEMCOUNT_MAX then
      doRemoveItem(item.uid)
        doPlayerAddItem(cid, ITEM_GOLD_COIN, ITEMCOUNT_MAX)
    elseif item.itemid == ITEM_CRYSTAL_COIN then
      doRemoveItem(item.uid)
        doPlayerAddItem(cid, ITEM_PLATINUM_COIN, ITEMCOUNT_MAX)
    else
        return FALSE
    end
    return TRUE
end
Still same problem, you have 100 crystal coins in your backpack when you rightclick it disapears.
 
I borrowed this code from a other pack, now it doesn't work at all but i rather having it not working at all than people abusing the bugs.


Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == ITEM_GOLD_COIN and item.type == ITEMCOUNT_MAX then
        doChangeTypeItem(item.uid, item.type - item.type)
        doPlayerAddItem(cid, ITEM_PLATINUM_COIN, 1)
    elseif item.itemid == ITEM_PLATINUM_COIN and item.type == ITEMCOUNT_MAX then
        doChangeTypeItem(item.uid, item.type - item.type)
        doPlayerAddItem(cid, ITEM_CRYSTAL_COIN, 1)
    elseif item.itemid == ITEM_PLATINUM_COIN and item.type < ITEMCOUNT_MAX then
        doChangeTypeItem(item.uid, item.type - 1)
        doPlayerAddItem(cid, ITEM_GOLD_COIN, ITEMCOUNT_MAX)
    elseif item.itemid == ITEM_CRYSTAL_COIN then
        doChangeTypeItem(item.uid, item.type - 1)
        doPlayerAddItem(cid, ITEM_PLATINUM_COIN, ITEMCOUNT_MAX)
    else
        return FALSE
    end
    return TRUE
end
 
Doesn't make sense. I scripted this from scratch just now, test it

Code:
function onUse(cid, item, topos, frompos)
 
    local gold, platinum, crystal, max = 2148, 2152, 2160, 100
 
    if item.itemid == gold and item.type == max then
        doRemoveItem(item.uid, max)
        doPlayerAddItem(cid, platinum, 1)
    elseif item.itemid == platinum and item.type == 1 then
        doRemoveItem(item.uid, 1)
        doPlayerAddItem(cid, gold, max)
    elseif item.itemid == platinum and item.type == max then
        doRemoveItem(item.uid, max)
        doPlayerAddItem(cid, crystal, 1)
    elseif item.itemid == crystal and item.type == 1 then
        doRemoveItem(item.uid, max)
        doPlayerAddItem(cid, platinum, max)
    else
        doPlayerSendCancel(cid, "Sorry, not possible.")
    end
    return TRUE
end
 
Doesn't make sense. I scripted this from scratch just now, test it

Code:
function onUse(cid, item, topos, frompos)

    local gold, platinum, crystal, max = 2148, 2152, 2160, 100

    if item.itemid == gold and item.type == max then
        doRemoveItem(item.uid, max)
        doPlayerAddItem(cid, platinum, 1)
    elseif item.itemid == platinum and item.type == 1 then
        doRemoveItem(item.uid, 1)
        doPlayerAddItem(cid, gold, max)
    elseif item.itemid == platinum and item.type == max then
        doRemoveItem(item.uid, max)
        doPlayerAddItem(cid, crystal, 1)
    elseif item.itemid == crystal and item.type == 1 then
        doRemoveItem(item.uid, max)
        doPlayerAddItem(cid, platinum, max)
    else
        doPlayerSendCancel(cid, "Sorry, not possible.")
    end
    return TRUE
end
Tried it, still when you have 100 coins on the floor and right click it doesn't remove it from the tile and you get cash to your main backpack anyway...
 
This is crazy. Am I blind today or what is wrong? Okay last try, different type of script, no variables used:

Code:
function onUse(cid, item, topos, frompos)
 
    if item.type == 100 then
        if item.itemid == 2148 then
            doPlayerAddItem(cid, 2152, 1)
        elseif item.itemid == 2152 then
            doPlayerAddItem(cid, 2160, 1)
        end
        doRemoveItem(item.uid, 100)
    elseif item.type == 1 then
        if item.itemid == 2152 then
            doPlayerAddItem(cid, 2148, 100)
        elseif item.itemid == 2160 then
            doPlayerAddItem(cid, 2152, 100)
        end
        doRemoveItem(item.uid, 1)
    end
    return TRUE
end
 
Last edited:
This is crazy. Am I blind today or what is wrong? Okay last try, different type of script, no variables used:

Code:
function onUse(cid, item, topos, frompos)

    if item.type == 100 then
        if item.itemid == 2148 then
            doPlayerAddItem(cid, 2152, 1)
        elseif item.itemid == 2152 then
            doPlayerAddItem(cid, 2160, 1)
        end
        doRemoveItem(item.uid, 100)
    elseif item.type == 1 then
        if item.itemid == 2152 then
            doPlayerAddItem(cid, 2148, 100)
        elseif item.itemid == 2160 then
            doPlayerAddItem(cid, 2152, 100)
        end
        doRemoveItem(item.uid, 1)
    end
    return TRUE
end
etc 100 crystal coin -> right click it disapears from the bag.
 
Try this one, should work.
Code:
local coins = {
    [ITEM_GOLD_COIN] = {
        to = ITEM_PLATINUM_COIN, effect = TEXTCOLOR_YELLOW
    },
    [ITEM_PLATINUM_COIN] = {
        from = ITEM_GOLD_COIN, to = ITEM_CRYSTAL_COIN, effect = TEXTCOLOR_LIGHTBLUE
    },
    [ITEM_CRYSTAL_COIN] = {
        from = ITEM_PLATINUM_COIN, effect = TEXTCOLOR_TEAL
    }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(getPlayerFlagValue(cid, PLAYERFLAG_CANNOTPICKUPITEM)) then
        return false
    end

    local coin = coins[item.itemid]
    if(not coin) then
        return false
    end

    if(coin.to ~= nil and item.type == ITEMCOUNT_MAX) then
        doChangeTypeItem(item.uid, item.type - item.type)
        doPlayerAddItem(cid, coin.to, 1)
        doSendAnimatedText(fromPosition, "$$$", coins[coin.to].effect)
    elseif(coin.from ~= nil) then
        doChangeTypeItem(item.uid, item.type - 1)
        doPlayerAddItem(cid, coin.from, ITEMCOUNT_MAX)
        doSendAnimatedText(fromPosition, "$$$", coins[coin.from].effect)
    end
    return true
end
 
Nope doesn't work i get the following error in console;
Lua Script Error: [Action Interface]
data/actions/scripts/other/changegold.lua:eek:nUse
data/actions/scripts/other/changegold.lua:28: attempt to call global 'doChangeTypeItem' (a nil value)
stack traceback:
[C]: in function 'doChangeTypeItem'
data/actions/scripts/other/changegold.lua:28: in function <data/actions/scripts/other/changegold.lua:13>
 
Back
Top