Vehicle.setCallback 33
Register a callback for a specific event Id on a specific Vehicle. 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 Vehicle |
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 181
-- Define any Lua function as your callback.
function OnUnitEnteredVehicle(soldier, seat)
print('Soldier '..soldier.getName()..' entered vehicle '..myself().getName()..' on seat number '..tostring(seat))
end
-- spawn a German soldier with leutenant rank at position 0,0,0
local vehicle = spawnVehicle("JeepWillys", vec3(0, 1.5, 0), vec3(0, 90, 0))
-- Register the OnSoldierDie callback from Lua.
vehicle.setCallback("vehicle_entered", OnUnitEnteredVehicle)