Vehicle.isDestroyed 31

Check if vehicle is fully destroyed


Return value

Return TypeDescription
boolTrue if vehicle is destroyed forever

No parameters defined for this function.


Examples

Example 118

--[[ Editable Section: Spawn Vehicle Variables ]]
local VEHICLE_ID  = "Panzer iii J"         -- Vehicle Id from the Id tables
local POSITION    = vec3(0, 1.5, 0)        -- Spawn position for the vehicle
local ROTATION    = vec3(0, 90, 0)         -- Vehicle rotation

-- Spawn a basic vehicle
local vehicle1 = spawnVehicle(VEHICLE_ID, POSITION, ROTATION)
if vehicle1 then
    print("Basic vehicle spawned! Destroy it to complete the mission.", 3)
end

-- Wait for the spawned vehicle to be destroyed
while vehicle1 and not vehicle1.isDestroyed() do
    -- Do the check every 3 seconds not to cause lag spikes
    sleep(3)
end

print("Vehicle destroyed, mission complete!", 3)
er2.nextPhase()

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

Back to Scripting API