Soldier.addItemToInventory 41
Puts an item in the soldier's inventory: a weapon, a magazine, an attachment, a bandage, a helmet, anything with an id in the items database. Online the change is sent to the owner of the soldier.Items of a DLC the executing player does not own are skipped with a line in the F3 console. Nothing is added when the inventory has no room.
Return value
| Return Type | Description |
|---|---|
| void | True if the item is now in the inventory. False if the id is unknown or is not an item, the DLC is not owned, or there is no room. |
Parameters
| Parameter | Type | Description |
|---|---|---|
| 1 | string | The item to add, using the keys of the items database, for example bandages or garand. |
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