spawnMissionObjective 34

Spawn a Scriptable Mission Objective on current active phase and it's relative 3D Marker on the current phase. Only the master client can spawn and handle a Mission Objective.
A Scriptable Objective doesn't do anything in particular on it's own. The user must make sure to update it's progress value, text, and other parameters on it's own, otherwise it will just act as a 3D Marker.
For icon Ids see setIcon.


Return value

Return TypeDescription
ObjectiveA reference to the created Mission Objective

Parameters

ParameterTypeDescription
1vec3Position where to create the objective
2floatRadius of the objective in meters
3stringText to display when inside the objective radius
4integerId of the icon to display (see setIcon function)
5boolSet whenever you want default AI to attack inside the area

Examples

Example of a mission objective that spawns a vehicle and an objective, and waits for the vehicle to be destroyed in order to progress to the next phase (network safe)

local VEHICLE_ID = "Flak38 AA"
local SPAWN_POS = vec3(0, 2, 0)
local SPAWN_ROT = vec3(0, 90, 0)
local OBJECTIVE_TEXT = "Destroy Flak 38"
local OBJECTIVE_ICON = 4

-- network initialize vehicle and objectives and save their ids
if not global.get("target_initialized") then
    if er2.isMasterClient() then
        local objective = spawnMissionObjective(SPAWN_POS, 20, "Destroy Flak 38", 2, true)
        global.set(objective.getUniqueId(), "target_objective")

        local vehicle = spawnVehicle(VEHICLE_ID, SPAWN_POS, SPAWN_ROT)
        global.set(vehicle.getUniqueId(), "target_vehicle")
        log(vehicle.getUniqueId())
    end
    global.set(true, "target_initialized")
end

-- acquire the vehicle and objective variables - network safe (either spawned by me or previous master client)
local vehicle = er2.findVehicle(global.get("target_vehicle"))
local objective = er2.findObjective(global.get("target_objective"))

local phaseCompleted = false
while not phaseCompleted do
    sleep(3) -- goot for performance

    if vehicle and objective then -- make sure they still exists
        if vehicle.isDestroyed() then -- nice
            objective.complete()
            phaseCompleted = true
        else
            -- update objective position to follow the vehicle
            objective.setPosition(vehicle.getPosition())
        end
    else
        -- if they don't exists anymore for whatever reason, cosnider the phase complete
        log("Skipping phase because objective or vehicle can't be found anymore!")
        phaseCompleted = true
    end
end

print ("The Flak have been destroyed!")
sleep(3)


if er2.isMasterClient() and objective then
   objective.setProgress(1)
end

Simple objective spawn and progress update

-- spawn the objective at pos 0,2,0 with radius 30, text "Example objective", icon Id 1 (see setIcon function), and Ai set to attack the area
local objective = spawnMissionObjective(vec3(0,2,0), 30, "Example objective", 1, true)

-- do something here...

-- set the objective as completed (when all objectives are completed, next phase is automatically triggered)
objective.setProgress(1)

Back to Scripting API