It depends on what type of script it is. (action, movement, talkaction, globalevent etc...)Whats the best way to detect if there is a item 1740 for example
On item counter (1621)
I need this base to make some scripts
local itemPos = getTileItemById({x=1000, y=1000, z=7}, 1740)
if itemPos.itemid == 1740 then
print("itemid = 1740, found at position")
end
It depends on what type of script it is. (action, movement, talkaction, globalevent etc...)
here is a simple example
LUA:local itemPos = getTileItemById({x=1000, y=1000, z=7}, 1740) if itemPos.itemid == 1740 then print("itemid = 1740, found at position") end
it check if itemid 1740 is at postionin 1000, 1000, 7 if that is true then it will print "itemid = 1740, found at position" to the console
<movevent type="AddItem" tileitem="1" itemid="7955" event="script" value="postman_parcel.lua"/>
function onAddItem(moveitem, tileitem, position, cid)
local postmanPos = {x=1732, y=558, z=4} -- north dp kazz
if(position == postmanPos) then
doRemoveItem(item.uid, 1)
end
return 1
end
changeWhat do i doing wrong?
PHP:<movevent type="AddItem" tileitem="1" itemid="7955" event="script" value="postman_parcel.lua"/>
PHP:function onAddItem(moveitem, tileitem, position, cid) local postmanPos = {x=1732, y=558, z=4} -- north dp kazz if(position == postmanPos) then doRemoveItem(item.uid, 1) end return 1 end
doRemoveItem(item.uid, 1)
doRemoveItem(moveitem.uid, 1)
print("Test - script is executed")
change
toLUA:doRemoveItem(item.uid, 1)
LUA:doRemoveItem(moveitem.uid, 1)
since "item.uid" is not assigned anywhere, the script dont know what to remove. But if you change it to "moveitem.uid" the script know what item you are pointing towards and should be able to remove the item.
I hope that explains something even though im not the greatest to explain
edit:
An other good way is to test if the script is working at all is to useand then check server log/console, that way you know you got the script to execute.LUA:print("Test - script is executed")
if position.x == postmanPos.x and position.y == postmanPos.y and position.z == postmanPos.z then
You're right, im testing it at the moment. I'll report back when i found out why, im not sure if it has to do whit it using itemid instead of action/unique id. But that would be very strange if that was the case.It's not even printing...
Ye thats true, but it still wont print anything anyways so there is something strange going on.== operator doesn't compare every single value in the table with another, it compares the memory location of both tables
you need to compare x, y, and z of both tables
LUA:if position.x == postmanPos.x and position.y == postmanPos.y and position.z == postmanPos.z then
<movevent type="AddItem" tileitem="1" actionid="1234" event="script" value="postman_parcel.lua"/>
function onAddItem(moveitem, tileitem, position, cid)
if moveitem.itemid == 7955 and tileitem.actionid == 1234 then
doRemoveItem(moveitem.uid)
return true
end
end
Ye thats true, but it still wont print anything anyways so there is something strange going on.
even if you put an print as first line in the onAddItem function
edit:
Seems like the best way to solve the problem is to set an actionid to the item at the position, and then use this method instead. That way you dont have to hardcode the cordinates aswell.
remember to change the "1234" to an empty/free actionid
XML:<movevent type="AddItem" tileitem="1" actionid="1234" event="script" value="postman_parcel.lua"/>
LUA:function onAddItem(moveitem, tileitem, position, cid) if moveitem.itemid == 7955 and tileitem.actionid == 1234 then doRemoveItem(moveitem.uid) return true end end
because the script would only run if you did put an item ontop of the parcel and not if you put the parcel ontop of something else, i did also learn something new by helping you out![]()