Esc to clear, Enter to open the best match, click an export to open it in its page
Inventory

Ground items

Items lying in the world: dropped or thrown by players, or left by your resource. Players pick them up; your server code creates, finds and deletes them.

Dropping, throwing and picking up

The pockets lose an item only as its ground item is made, so nothing is lost or copied. Players are sent the items in the Config.GroundItemCellSize (50 m) cells around them as they move, and their game draws props within Config.GroundItemStreamRange.

API#

CreateGroundItem({ item, amount?, coords, metadata?, heading?, reason? })SERVERWAITS#

Puts an item on the ground. It syncs to nearby players by itself.

FieldTypeDescription
itemstringA registered item key
amountnumber?A whole number, 1 or more (default 1)
coordsvector3|vector4World position (a vector4's w is the heading)
metadatatable?Custom metadata
headingnumber?Degrees
reasonstring?For the activity log, beside your resource's name
Returns: table: { id, item, amount, metadata, x, y, z, heading, createdAt }, or false, reason (not a table, an unknown item, a bad amount, no coordinates)
ThrowGroundItem({ item, amount?, from, target, power?, by?, metadata?, reason? })SERVERWAITS#

Throws an item from one point at another, the way a player throws one. It's a ground item from the moment it leaves from, so anyone in reach can grab it out of the air, and it lies wherever physics leaves it.

It's aimed as a player's throw is, on the arc that lands on target at that power. Too soft and it falls short of the target. Hard and it comes in flat and fast, so it skids or bounces on past, or off whatever is in the way. With no power it takes the gentlest throw that reaches the target, which comes down closest to it.

Only a player's game can run the physics, so one of them flies it: by when they're within 50 m of from, otherwise the nearest player who is. That player sees it fly smoothly at any ping, and everyone else sees it as they see any thrown item. Like a player's throw, it knocks over anyone it hits hard enough for its weight, that player included, since they didn't throw it. A heavy item thrown hard does; cash never does (Config.ThrowKnockdown). When nobody is that close, it's put down where the throw would have come down, already at rest.

One throw starts every 500 ms at most, whoever asks: faster than that the flying player's game can't keep up. A call that comes sooner waits its turn, in the order asked, and the server console warns that throws are being asked for too quickly. A spray of ten takes five seconds.

FieldTypeDescription
itemstringA registered item key
amountnumber?A whole number, 1 or more (default 1)
fromvector3Where it's thrown from, a little clear of anything solid so it doesn't bounce straight off
targetvector3|vector4Where it's aimed (a vector4's w is the heading it lies at when put down)
powernumber?How hard, 0 to 40. A player throws at 18, and 18 to 22 is recommended
bynumber|table?Whose game flies it: a server ID or { charId = n }
metadatatable?Custom metadata
reasonstring?For the activity log, beside your resource's name
Returns: table, how: the ground item and 'thrown' (in the air now) or 'ground' (put down, and why: nobody near enough, or that game's throw could not be checked), or false, reason (not a table, an unknown item, a bad amount, no from or target, a power outside 0 to 40)

It waits its turn and then for the flying player's game to make the throw, so several calls in a row come out one after another. In a SecureCallback, where the player's game gives up after 10 seconds, start it in a CreateThread and answer at once. A very hard throw can pass straight through thin walls and floors, as GTA objects do at speed.

-- The ATM spits the cash out on the pavement in front of it
local atm = vector4(147.4, -1035.8, 29.3, 160.0)   -- where it stands and the way it faces
local out = vector3(-math.sin(math.rad(atm.w)), math.cos(math.rad(atm.w)), 0.0)
exports.whip_core:ThrowGroundItem({
    item = 'cash', amount = 250,
    from = atm.xyz + out * 0.5 + vector3(0.0, 0.0, 1.0),
    target = atm.xyz + out * 2.0,
    by = source,   -- the robber: your robbery SecureEvent handler's source
    reason = 'ATM robbery',
})
DeleteGroundItem(id)SERVERWAITS#

Removes a ground item.

ParamTypeDescription
idnumberGround item ID
Returns: bool, string|nil
GetGroundItemsNearby(x, y, z, range?)SERVER#

Every ground item within a 3D radius.

ParamTypeDescription
x, y, znumberCentre, or a vector3 first and the range second
rangenumber?Metres (default 10)
Returns: table[]: { id, item, amount, metadata, x, y, z, heading, ... }
-- A street sweeper
for _, row in ipairs(exports.whip_core:GetGroundItemsNearby(vector3(x, y, z), 5.0)) do
    exports.whip_core:DeleteGroundItem(row.id)
end
GetGroundItem(id)SERVER#

One ground item by id, or nil once it's picked up or deleted.

Returns: table|nil: { id, item, amount, metadata, x, y, z, heading, ... }