Zum Inhalt springen
Gothic Multiplayer
Gothic MP Wiki

ItemsGround

Items lying on the ground kept by the server: the ones near the local player, their place and their game object.

since 0.1.41-alpha

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 dropItem event 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 with itemGroundDespawn ("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:

FieldTypeDescription
idintegerNumber of the item on the server's list - the same in every player's game.
instanceItemClassItem class, e.g. "ItMw_1H_Torch"; nil once the item left this game.
amountintegerHow many pieces lie there; nil once gone.
droppedByintegerId 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

since 0.1.41-alpha
ItemsGround.getById(id)

Returns the item with this number, if this game has it.

ParameterTypeDescription
idintegerNumber of the item (item.id).

Returns: ItemGround | nil

getAll

since 0.1.41-alpha
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())
end

Returns: 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

since 0.1.41-alpha
item:getPosition()

Returns the position of the item (where it is now while a throw still flies).

Returns:

ValueTypeDescription
xnumber | nilX coordinate (cm), or nil when the item left this game.
ynumber | nilY coordinate (cm).
znumber | nilZ coordinate (cm).

getRotation

since 0.1.41-alpha
item:getRotation()

Returns the rotation of the item.

Returns:

ValueTypeDescription
pitchnumber | nilPitch in degrees, or nil when the item left this game.
yawnumber | nilYaw in degrees.
rollnumber | nilRoll in degrees.

getObject

since 0.1.41-alpha
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

since 0.1.41-alpha
item:isValid()

Tells whether the item is still in this game.

Returns: boolean - false after it was taken, destroyed or went out of range.