Forum

> > CS2D > Scripts > How to detect item amount in a tile?
Forums overviewCS2D overview Scripts overviewLog in to reply

English How to detect item amount in a tile?

4 replies
To the start Previous 1 Next To the start

old How to detect item amount in a tile?

ReVoltage
User Off Offline

Quote
Hello us ,
I want to make a drop system, but i want to prevent too much item in a tile and make a player disconnected from server when pick it up.
I want to know, is it possible to detect amount of item in a tile? If it possible, please tell me how
Thx before.

Sorry if i had bad english.

old Re: How to detect item amount in a tile?

Apache uwu
User Off Offline

Quote
Looping through the item list should suffice. cs2d lua cmd item.

There could be more than one item at a tile though, so you should account for that in your script:

Example of concept:

1
2
3
4
5
6
local itemlist=item(0,"table")
for _,id in ipairs(itemlist) do
    if item(id,"x")==TILE_X and item(id,"y")==TILEY then
        //item(id,"type") exists on TILE_X,TILE_Y
    end
end

old Re: How to detect item amount in a tile?

ReVoltage
User Off Offline

Quote
@user Apache uwu: :Thank you very much, i will try to use the code
And i have 1 more question(I post it here, i dont want to make another thread)
Can i damage a NPC with a custom value (damageobject) WITHOUT objectdamage addhook? im trying using Hit addhook but its not work

old Re: How to detect item amount in a tile?

Avo
User Off Offline

Quote
You can use object(0, "table") and use for loop to find certain NPC.

http://www.cs2d.com/help.php?luacat=object&luacmd=object has written
1
2
3
4
local objectlist=object(0,"table")
for _,id in pairs(objectlist) do
   print(id)
end

old Re: How to detect item amount in a tile?

ReVoltage
User Off Offline

Quote
I mean, like when you hit an NPC then damage the NPC with custom value. I trying use objectdamage and using parse damageobject (with return 1) but its cause LUA error (C stack overflow) in console every i hit the NPC

EDIT: I have a way to do this, but idk if it work or not. I still need help if this way not work.

EDIT2: Its work, my way work, thx all for help.
edited 1×, last 05.07.13 02:21:20 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview