er2.spawnItem ▲ 41

Available from Easy Red 2 2.1.1

Puts an item on the ground, with physics, as if someone had dropped it there. Any soldier can walk up and pick it up.Multiplayer: only the master client spawns it; the others receive it automatically and whoever picks it up removes it for everyone. Players joining later do not see items spawned before they arrived. On the other clients the call returns false and does nothing, so it is safe to call it from a script that runs on everyone.Items of a DLC the executing player does not own are skipped with a line in the F3 console.


Return value

Return TypeDescription
voidTrue if the item is on the ground. False if the id is unknown or is not an item, the DLC is not owned, or this is not the master client.

Parameters

ParameterTypeDescription
1stringThe item to drop, using the keys of the items database.
2voidWhere to put it, in world coordinates. Drop it a little above the ground: it falls with physics.
3voidRotation in Euler degrees. vec3(0, 0, 0) is fine for most items.

Examples

Supplies for the player and a crate on the ground

-- two bandages and rifle ammo for the player
local player = er2.getPlayer()
if player ~= nil then
    player:addItemToInventory("bandages")
    player:addItemToInventory("bandages")
    player:addItemToInventory("ammo_30_06")
end

-- a refill crate left on the ground near the bunker (only the master client spawns it online)
local bunker = vec3(220, 18.5, 640)
er2.spawnItem("droppable_refill_crate", vec3(222, 19, 640), vec3(0, 0, 0))

-- ammo in the cargo of the closest truck
local truck = er2.getNearestVehicle(bunker, 100)
if truck ~= nil then
    truck:addNewItemToCargo("ammo_30_06")
end

Back to Scripting API