Soldier.setCallback 54
Register a callback for a specific event Id on a specific Soldier. Only a callback can be tied to an event Id, so when this is called again on the same Id, the new callback reference will override previous one.
Callback Ids are specified at this page.
Return value
Return Type | Description |
---|---|
bool | True if the callback was correctly set on the specific Soldier |
Parameters
Parameter | Type | Description |
---|---|---|
1 | string | Id of the callback (check callback Id database) |
2 | function | Function that gets called when the callback is triggered |
Examples
Example 178
-- Define any Lua function as your callback.
function OnSoldierDie()
print('Soldier died: ' .. myself().getName())
end
-- spawn a German soldier with leutenant rank at position 0,0,0
local soldier = spawnSoldier(vec3(0,0,0), "Germany_axis", 8, "ger_infantry_tankcrew_leader")
-- Register the OnSoldierDie callback from Lua.
soldier.setCallback("soldier_died", OnSoldierDie)