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

TFS 0.X Detect a item on another to make a if

zabuzo

Well-Known Member
Joined
Jun 10, 2016
Messages
238
Reaction score
54
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
 
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
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
 
Last edited:
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

What 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
 
What 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
change
Lua:
doRemoveItem(item.uid, 1)
to
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 use
Lua:
print("Test - script is executed")
and then check server log/console, that way you know you got the script to execute.
 
Last edited:
change
Lua:
doRemoveItem(item.uid, 1)
to
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 use
Lua:
print("Test - script is executed")
and then check server log/console, that way you know you got the script to execute.

It's not even printing...
 
== 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
 
It's not even printing...
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.

== 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
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 :D
 
Last edited by a moderator:
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 :D

Works! Thank you!
 
Back
Top