er2.explosion 80

Generates an explosion


Return value

Return TypeDescription
voidThis function doesn't return anything

Parameters

ParameterTypeDescription
1vec3The position of the explosion
2floatThe maximum damage the explosion can cause. The damage calculation is based by the distance of each objects inside the explosion radius
3floatThe maximum penetration capacity against armored vehicles. The value is measured in Millimeters
4floatExplosion radius

Examples

Example 104

-- Get the AI soldier running this script
local soldier = myself()

-- Ensure the soldier is alive before proceeding
if soldier and soldier:isAlive() then
    -- Wait 5 seconds
    sleep(5)

    -- Get the soldier's position
    local pos = soldier:getPosition()

    -- Create an explosion at the soldier's location
    er2.explosion(pos, 100, 50, 5)
end

Double artillery barrage example

 --[[======== USER CONFIGURATION ========]]
-- Get positions in-game by pressing P
local TARGET_POSITION_1 = vec3(752.8079,3.657072,-368.0378)
local TARGET_POSITION_2 = vec3(814.9021,4.861425,-429.9956)
local BARRAGE_RADIUS = 175         -- Area effect radius in meters
local NUM_SHELLS = 35              -- Shells per target
local SHELL_INTERVAL = 1         -- Seconds between shells
local MAX_DAMAGE = 10            -- Max damage per explosion
local WARNING_TIME = 15            -- Warning time before barrage
--[[====== END USER CONFIGURATION ======]]

if not er2.isMasterClient() then return end -- Only run on host

-- Check initialization state
if not global.get("barrage_initialized") then
    global.set(true, "barrage_initialized")
else
    return -- don't run twice
end

-- Wait initial warning period
local phaseStart = er2.time()
while er2.time() - phaseStart < WARNING_TIME do
    sleep(1)
end

-- Artillery strike function
local function fireBarrage(targetPos)
    for i = 1, NUM_SHELLS do
        -- Calculate random position in circular area
        local angle = math.random() * math.pi * 2
        local radius = math.random() * BARRAGE_RADIUS
        local x = targetPos.x + math.cos(angle) * radius
        local z = targetPos.z + math.sin(angle) * radius
        local y = er2.getTerrainHeight(vec3(x, 0, z))
        
        -- Create explosion with random timing variation
        er2.explosion(vec3(x, y, z), MAX_DAMAGE, 10, 10)
        sleep(SHELL_INTERVAL + math.random() * 0.3 - 0.15)
    end
end

local co1 = coroutine.create(function() fireBarrage(TARGET_POSITION_1) end)
local co2 = coroutine.create(function() fireBarrage(TARGET_POSITION_2) end)

coroutine.resume(co1)
coroutine.resume(co2)


while coroutine.status(co1) ~= "dead" or coroutine.status(co2) ~= "dead" do
    sleep(1)
end
 

Back to Scripting API