-- Tracks only smoke rockets (HYDRA_70_M156) and triggers WP-style impact effect.
--assert(loadfile('C:\Users\hindsas\Saved Games\DCS.openbeta\Missions\Vietnam Islands\LUA\willie_pete_effect.lua'))()
if not _G.__williePeteRocketHandler then
_G.__williePeteRocketHandler = true
_G.__williePeteTrackedRockets = _G.__williePeteTrackedRockets or {}
local function wpSmokeEffect(heading, point)
if not (point and point.x and point.z) then
return
end
local effectPoint = {
x = point.x,
y = land.getHeight({ x = point.x, y = point.z }) + 1,
z = point.z
}
trigger.action.explosion(effectPoint, 1)
trigger.action.smoke(effectPoint, 2)
for i = 1, math.random(0, 4) do
local variation = math.rad(math.random(-90, 90))
trigger.action.signalFlare(effectPoint, 2, (heading or 0) + variation)
end
end
local function scheduleDelayedWPEffect(baseHeading, point)
local p = { x = point.x, y = point.y, z = point.z }
timer.scheduleFunction(function(args)
local variation = math.rad(math.random(-10, 10))
wpSmokeEffect((args.heading or 0) + variation, args.point)
return nil
end, { heading = baseHeading or 0, point = p }, timer.getTime() + 0.2)
end
local function checkTrackedRockets()
for i = #_G.__williePeteTrackedRockets, 1, -1 do
local tracked = _G.__williePeteTrackedRockets[i]
local rocket = tracked and tracked.weapon
if rocket and rocket:isExist() then
local p = rocket:getPoint()
if p then
tracked.lastPos = { x = p.x, y = p.y, z = p.z }
end
else
if tracked and tracked.lastPos then
scheduleDelayedWPEffect(tracked.heading, tracked.lastPos)
end
table.remove(_G.__williePeteTrackedRockets, i)
end
end
return timer.getTime() + 0.1
end
timer.scheduleFunction(checkTrackedRockets, nil, timer.getTime() + 0.1)
world.addEventHandler({
onEvent = function(self, event)
if not event or event.id ~= world.event.S_EVENT_SHOT or not event.weapon then
return
end
local desc = event.weapon:getDesc()
if not desc or desc.category ~= Weapon.Category.ROCKET then
return
end
if desc.typeName ~= "weapons.nurs.HYDRA_70_M156" then
return
end
local p = event.weapon:getPoint()
local initialPos = nil
if p then
initialPos = { x = p.x, y = p.y, z = p.z }
end
local vel = event.weapon:getVelocity()
local initHeading = 0
if vel and (vel.x ~= 0 or vel.z ~= 0) then
initHeading = math.atan2(vel.x, vel.z)
end
table.insert(_G.__williePeteTrackedRockets, {
weapon = event.weapon,
heading = initHeading,
lastPos = initialPos
})
end
})
Example WP script that implements flares, the magic is as follows
trigger.action.signalFlare(effectPoint, colour, heading)
illum bomb example
trigger.action.illuminationBomb(table vec3 , number power )
example script
-- Tracks only smoke rockets (HYDRA_70_M156) and triggers WP-style impact effect.
--assert(loadfile('C:\Users\hindsas\Saved Games\DCS.openbeta\Missions\Vietnam Islands\LUA\willie_pete_effect.lua'))()
if not _G.__williePeteRocketHandler then
_G.__williePeteRocketHandler = true
_G.__williePeteTrackedRockets = _G.__williePeteTrackedRockets or {}
end