ItemsGround
Items lying on the ground kept by the server: the ones near the local player, their place and their game object.
Items on the ground belong to the server: it keeps their list and decides who gets them (see the server-side ItemsGround page). This game shows the ones near the local player as the game's own items - they look, burn (torches) and are picked up exactly like the game's items, and every player sees them in the same place.
How it works
- Throwing / dropping - when the local player throws or drops an item (drops it from the inventory, throws a torch away, or grabs a winch with a torch in hand), the
dropItemevent comes first:cancelEvent()keeps the item in the inventory. Otherwise the item flies in this game and the server puts it on its list; the other players near it see it fly and land. - Picking up - the player picks an item up the usual way. The server decides: the first player wins; when someone was faster (or a server script cancelled the pick) the item leaves the inventory again.
- Appearing and leaving - an item comes into this game with
itemGroundSpawn(thrown nearby, created by a server script, or the local player walked up to it) and leaves withitemGroundDespawn("taken","destroyed"or"streamedOut"- out of range, it comes back when the player returns). - Items placed in the map by the game itself (plants, ore, loot lying in the world) are not on the list.
Client scripts read the items; only server scripts create, move and remove them.
addEventHandler("itemGroundSpawn", function(item)
if item.instance == "ItMi_Orenugget" then
addChatMessage(0xFFD700, item.amount .. " ore lies somewhere near you!")
end
end)Fields of ItemGround
In the examples below item is any ItemGround.
The object stays usable after the item left this game - then its fields are nil and isValid() returns
false. Two objects of the same item are equal (==). Its fields can only be read - items are changed by the
server's scripts:
| Field | Type | Description |
|---|---|---|
id | integer | Number of the item on the server's list - the same in every player's game. |
instance | ItemClass | Item class, e.g. "ItMw_1H_Torch"; nil once the item left this game. |
amount | integer | How many pieces lie there; nil once gone. |
droppedBy | integer | Id of the player who dropped it, -1 for an item created by a server script; nil once gone. |
ItemsGround
The global table: the items on the ground this game has (the ones near the local player).
getById
ItemsGround.getById(id)Returns the item with this number, if this game has it.
| Parameter | Type | Description |
|---|---|---|
id | integer | Number of the item (item.id). |
Returns: ItemGround | nil
getAll
ItemsGround.getAll()Returns every item on the ground this game has (the ones near the local player).
addChatMessage("Items on the ground near you: " .. #ItemsGround.getAll())
for _, item in ipairs(ItemsGround.getAll()) do
print(item.id, item.instance, item.amount, item:getPosition())
endReturns: ItemGround[]
ItemGround
One item on the ground (item below): its place and its game object. Objects come from ItemsGround and from the events "itemGroundSpawn" / "itemGroundDespawn".
getPosition
item:getPosition()Returns the position of the item (where it is now while a throw still flies).
Returns:
| Value | Type | Description |
|---|---|---|
x | number | nil | X coordinate (cm), or nil when the item left this game. |
y | number | nil | Y coordinate (cm). |
z | number | nil | Z coordinate (cm). |
getRotation
item:getRotation()Returns the rotation of the item.
Returns:
| Value | Type | Description |
|---|---|---|
pitch | number | nil | Pitch in degrees, or nil when the item left this game. |
yaw | number | nil | Yaw in degrees. |
roll | number | nil | Roll in degrees. |
getObject
item:getObject()Returns the game object of the item - the same kind as the objects of "interactionStart" - or nil when the
game has no object for it (it left this game, or its item class does not exist here).
Returns: WorldObject | nil
isValid
item:isValid()Tells whether the item is still in this game.
Returns: boolean - false after it was taken, destroyed or went out of range.
