er2.findSoldier 70

Find a soldier from it's unique Id (network safe).
Useful in case you have to reference a specific soldier across different phases or players, based on it's unique Id, for example, passed trough a global variable


Return value

Return TypeDescription
SoldierSoldier corresponding to the provided Id

Parameters

ParameterTypeDescription
1integerUnique Id of the searched soldier

Examples

Example 168

-- Spawn a soldier
local soldier = spawnSoldier(vec3(10, 1.5, 10), "Germany_axis", 8, "ger_infantry_tankcrew_leader")
-- Acquire the unique id of the spawned soldier
local soldierUniqueId = soldier.getUniqueId()

-- Retrieve the soldier using its unique id
local foundSoldier = er2.findSoldier(soldierUniqueId)

Example 169

-- Spawn a soldier
local soldier = spawnSoldier(vec3(10, 1.5, 10), "Germany_axis", 8, "ger_infantry_tankcrew_leader")
if soldier then
    -- Acquire the unique id of the spawned soldier
    local soldierUniqueId = soldier.getUniqueId()
    print("Soldier Unique ID: " .. soldierUniqueId, 3)

    -- ... (later in the script or in a subsequent phase)

    -- Retrieve the soldier using its unique id
    local foundSoldier = er2.findSoldier(soldierUniqueId)
    if foundSoldier then
        print("Soldier found using unique id!", 3)
    else
        print("Soldier not found.", 3)
    end
end

Back to Scripting API