• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Problem removing an item

Scarlet Ayleid

Advanced OT User
Senator
Joined
Jul 7, 2007
Messages
4,049
Reaction score
240
Hey

I'm at the moment experiencing an error that doesn't seem to make any sense to me

As an example of my problem, I am using a talkaction to create an item and another to destroy that same item(not pickupable)
Code:
local var = nil


function onSay(cid, words, param, channel)
    if param == "create" then
        var = doCreateItem(1614, getCreaturePosition(cid))
        print("Item UID: " .. var)
    elseif param == "destroy" then
        print("Var: " .. var)
        doRemoveItem(var, 1)
        var = nil
    end
end

When I create an item, everything is fine, but when I use the doRemoveItem it says it can't find the item..
Console:
Item UID: 70045
Var: 70045


[1:23:05.944] [Error - TalkAction Interface]
[1:23:05.945] data/talkactions/scripts/test.lua: onSay
[1:23:05.947] Description:
[1:23:05.948] (luaDoRemoveItem) Item not found

As you can see from the prints, the ID's the same, so I'm really clueless here..

Thanks in Advance :)
Scarlet
 
LUA:
    if param == "create" then
        var = doCreateItem(1614, getCreaturePosition(cid))
        print("Item UID: " .. var)
    elseif param == "destroy" then
        print("Var: " .. var)
        doRemoveItem(var, 1)
        var = nil
    end

For the param "create", var is assigned as doCreateItem(1614, getCreaturePosition(cid))
but for "destroy" it is still assigned to nil
also, you don't need to assign var back to nil at the end :)

SOLUTION (untested)

LUA:
    if param == "create" then
        var = doCreateItem(1614, getCreaturePosition(cid))
        print("Item UID: " .. var)
    elseif param == "destroy" then
        var = getThingFromPos({x = getCreaturePosition(cid).x, y = getCreaturePosition(cid).y, z = getCreaturePosition(cid).z, stackpos = 2}).uid
        print("Var: " .. var)
        doRemoveItem(var, 1)
    end
 
I never use destroy without using create and I never use 2 creates or 2 destroys in a row, and like I said, this is just a small example of my real problem

@Shinmaru
Yes it does, that's why I added the prints, to make sure the var had something, and since it can print the value that was saved in it, it should also be able to remove it

@Radium
var is global on that script, so it doesn't reset back to nil when the script finishes, that also wouldnt work because I want to be able to destroy the item anywhere in the world and since I have its uid(like it shows on the prints) I should be able to delete it from anywhere


EDIT: Managed to fix it by storing the position and then getting the item from the position, Thanks Fallen :)
 
Last edited:
Back
Top