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
- Drop: drag an item to the Ground panel and it lands in front of the player.
- Throw: in give mode, aim and release. It's a ground item as it leaves the hand: anyone in reach can grab it from the air, and it settles where it lands.
- Pick up: E puts it in the best slot, or drag it from the Ground panel. If two players grab one item at once, one gets it.
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#
Puts an item on the ground. It syncs to nearby players by itself.
| Field | Type | Description |
|---|---|---|
| item | string | A registered item key |
| amount | number? | A whole number, 1 or more (default 1) |
| coords | vector3|vector4 | World position (a vector4's w is the heading) |
| metadata | table? | Custom metadata |
| heading | number? | Degrees |
| reason | string? | For the activity log, beside your resource's name |
table: { id, item, amount, metadata, x, y, z, heading, createdAt }, or false, reason (not a table, an unknown item, a bad amount, no coordinates)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.
| Field | Type | Description |
|---|---|---|
| item | string | A registered item key |
| amount | number? | A whole number, 1 or more (default 1) |
| from | vector3 | Where it's thrown from, a little clear of anything solid so it doesn't bounce straight off |
| target | vector3|vector4 | Where it's aimed (a vector4's w is the heading it lies at when put down) |
| power | number? | How hard, 0 to 40. A player throws at 18, and 18 to 22 is recommended |
| by | number|table? | Whose game flies it: a server ID or { charId = n } |
| metadata | table? | Custom metadata |
| reason | string? | For the activity log, beside your resource's name |
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',
})
Removes a ground item.
| Param | Type | Description |
|---|---|---|
| id | number | Ground item ID |
bool, string|nilEvery ground item within a 3D radius.
| Param | Type | Description |
|---|---|---|
| x, y, z | number | Centre, or a vector3 first and the range second |
| range | number? | Metres (default 10) |
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
One ground item by id, or nil once it's picked up or deleted.
table|nil: { id, item, amount, metadata, x, y, z, heading, ... }