• 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 if item is removed then create new one...

okurde

New Member
Joined
Jan 28, 2009
Messages
134
Reaction score
1
Hello, I want to prevent put items on teleport and I have this script:
Code:
function onAddItem(moveitem, tileitem, position, cid)
        doRemoveItem(moveitem.uid)
        doPlayerSendCancel(cid, "You may not throw items here.") -- Sends cancel message
        if(doPlayerAddItemEx(cid, doCreateItemEx(moveitem.itemid, moveitem.type)) == RETURNVALUE_NOERROR) then
            return true
        end
    return true
end

When I was testing this script everything was ok - when item is put on the teleport then item disappers and is created in backpack of player who had thrown it.
But... sometimes I have this error:
Code:
[Error - MoveEvents Interface] 
data/movements/scripts/no_add.lua:onAddItem
Description: 
(luaDoRemoveItem) Item not found

It means that thrown item is not removed. In this situation - is item given to player? or script ends?
If item is not removed and is given to player that player has 2 items... :/

Maybe there can be done something like this - check if the item is removed, if not than do not make doPlayerAddItem?
 
So:
Code:
function onAddItem(moveitem, tileitem, position, cid)
        doRemoveItem(moveitem.uid)
        doPlayerSendCancel(cid, "You may not throw items here.") 
        if(doPlayerAddItemEx(cid, doCreateItemEx(moveitem.itemid, moveitem.type)) == RETURNVALUE_NOERROR) then
            return false
        end
    return true
end

I have not idea how it works. If player know a bug and can put any item in TP that will not be removed then I will have error "(luaDoRemoveItem) Item not found" so item will not be removed. Next line - doPlayerAddItemEx will return "RETURNVALUE_NOERROR" so the whole script will return false.
Can you exlain me what does it mean and how it will work?
 
So:
Code:
function onAddItem(moveitem, tileitem, position, cid)
        doRemoveItem(moveitem.uid)
        doPlayerSendCancel(cid, "You may not throw items here.")
        if(doPlayerAddItemEx(cid, doCreateItemEx(moveitem.itemid, moveitem.type)) == RETURNVALUE_NOERROR) then
            return false
        end
    return true
end

I have not idea how it works. If player know a bug and can put any item in TP that will not be removed then I will have error "(luaDoRemoveItem) Item not found" so item will not be removed. Next line - doPlayerAddItemEx will return "RETURNVALUE_NOERROR" so the whole script will return false.
Can you exlain me what does it mean and how it will work?

Fail, as always I forget the simple things...
You removed the item and can therefor not take any parameters from it.

Code:
function onAddItem(moveitem, tileitem, position, cid)
     doPlayerAddItemEx(cid, doCreateItemEx(moveitem.itemid, moveitem.type))
     doRemoveItem(moveitem.uid)
     doPlayerSendCancel(cid, "You may not throw items here.")
     return true
end
 
Fail, as always I forget the simple things...
You removed the item and can therefor not take any parameters from it.

Code:
function onAddItem(moveitem, tileitem, position, cid)
     doPlayerAddItemEx(cid, doCreateItemEx(moveitem.itemid, moveitem.type))
     doRemoveItem(moveitem.uid)
     doPlayerSendCancel(cid, "You may not throw items here.")
     return true
end
that script will create the same item and then remove the old one ya?
 
that script will create the same item and then remove the old one ya?

Yes, it will remove the item that we are moving and create a new one and give it to the character.
Mainly since we don't have the fromPosition parameter and idk if 0.x has an item:moveTo(player) function.
But maybe the thread creator uses 1.x, people never post enough info these days...
 
Back
Top