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

Solved Cannot Remove Player Items

mackerel

Well-Known Member
Joined
Apr 26, 2017
Messages
398
Solutions
18
Reaction score
72
XML:
<action itemid="7724" script="item.lua"/>


Lua:
function onUse(cid, item, frompos, item2, topos)
    doPlayerRemoveItem(cid, item, 1)
end

On item click, the item should be removed from player's inventory but instead I am getting this error:

attempt to call global 'doPlayerRemoveItem' (a nil value)
 
Solution
What do you mean by not the correct way :eek:

Anyway, I did as you said and, well.. similar error:

Oh read 1.2 insted of 1.0, in that case this is the correct way.
The functions you used are the legacy functions = no longer in use.
But they have compat functions in compat.lua so you still can use the server, but you should update the scripts.

Lua:
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local item = Item(item.uid)
    if item then
        item:remove(1)
    end
    return true
end

The diffrence with 1.0 and 1.1/1.2 is that insted of the unique id getting pushed (as cid or item.uid etc) a userdata value is sent, you can read more about meta tags and userdata values on the Lua websites :p
Code:
doPlayerRemoveItem(cid, item.uid, 1)

The same error, TFS 1.0

EDIT// SOLVED

Missing the following line in compat.lua

Code:
function doPlayerRemoveItem(cid, itemid, count, ...) local p = Player(cid) return p ~= nil and p:removeItem(itemid, count, ...) or false end
 
Last edited:
The same error, TFS 1.0

EDIT// SOLVED

Missing the following line in compat.lua

Code:
function doPlayerRemoveItem(cid, itemid, count, ...) local p = Player(cid) return p ~= nil and p:removeItem(itemid, count, ...) or false end

That isn't the correct way to solve this "issue"
This is what you should use in your script;
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item then
        item:remove(1)
    end
    return true
end

Adding more compat functions won't really help the server, update your existing scripts insted.
 
That isn't the correct way to solve this "issue"
This is what you should use in your script;
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item then
        item:remove(1)
    end
    return true
end

Adding more compat functions won't really help the server, update your existing scripts insted.

What do you mean by not the correct way :eek:

Anyway, I did as you said and, well.. similar error:

attempt to call method 'remove' (a nil value)
 
What do you mean by not the correct way :eek:

Anyway, I did as you said and, well.. similar error:

Oh read 1.2 insted of 1.0, in that case this is the correct way.
The functions you used are the legacy functions = no longer in use.
But they have compat functions in compat.lua so you still can use the server, but you should update the scripts.

Lua:
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local item = Item(item.uid)
    if item then
        item:remove(1)
    end
    return true
end

The diffrence with 1.0 and 1.1/1.2 is that insted of the unique id getting pushed (as cid or item.uid etc) a userdata value is sent, you can read more about meta tags and userdata values on the Lua websites :p
 
Solution
Back
Top