scripts for a triggered air strike
(at player's location at time of triggering - you'll have to modify it if you want a different target)
0. change the settings in airstrike_bomber.lua as you wish (travel speeds etc)
1. place a trigger zone and give it airstrike_trigger.lua
1.a name it something (e.g. airstrike1)
2. place the plane / entity to do the bombing and give it airstrike_bomber.lua
2.a name it the same as the zone (so you can have more than 1 air strike easily using unique names)
3. place an explodable entity with the script airstrike_bomb.lua near to the bomber entity (needs to be near for the script to register them as belonging to this bomber - no need to rename, script will automatically handle this)
3.a extract and repeat placing bombs for as many as you wish the bomber to drop (given he has enough time to drop them all in 1 pass)
(4) repeat for all desired air strikes but use a new name (note you will need to stack zones (with different names) to get multiple bombers to drop in the same location - you can only have 1 bomber per zone.
(4.a) tweak the settings at step 0
note the bomber allows for a general flyby noise at slot 0 and an unloading noise at slot 1
*remember to set all models to always active = yes and the bombs to explodable*
*this script is a 1 time use, once the run is complete that is the end of that air strike regardless of if it misses or still has bombs etc*
*edit* updated to work correctly with multiple drops and edited the dropping so it now doesnt rely on the player still being in range to drop (so it will always drop even if you move away)
(only bomber script is changed)
you can grab the files from the attachment but for any1 who wants to check the code
bomber:
state = {}
first_bomb = nil
last_bomb = nil
local bombs = {}
local bomb = {}
local dropped = {}
local distance = {}
local new_speed = 0
local b = 0
local c = 0
--bomber travel speed
bomber_speed = 1000
--how fast the bombs fall
drop_speed = 400
--height to start bomber at
local height = 1000
--how far away from player to start dropping bombs (note they will travel forwards a bit still)
local drop_range = 1750
--delay between each bomb being unloaded
local time_between_drops = 1000
function airstrike_bomber_init_name(e,name)
weapon_name[e] = name
state[e] = "wait"
Hide(e)
dropped[e] = 0
end
function airstrike_bomber_main(e)
--optional scale if your bomber model is big
--Scale(e,20)
if bombs[e] == nil then
Prompt("no bombs for bomber "..weapon_name[e])
for a = 1,9999 do
if g_Entity[a] ~= nil then
if weapon_name[a] ~= nil then
if GetFlatDistance(e,a) < 600 then
if weapon_name[a] == "air strike bomb" then
b = b + 1
bomb[b] = a
c = b
bombs[e] = 1
end
end
end
end
if a == max_bomb then
end
end
CollisionOff(e)
SetPosition(e,g_Entity[e]['x'],g_Entity[e]['y']+height,g_Entity[e]['z'])
else
if state[e] == "active" then
LoopSound(e,0)
Show(e)
RotateToPlayer(e)
for a = 1,c do
RotateToPlayer(bomb[a])
end
state[e] = "fly"
new_speed = bomber_speed
distance[e] = GetPlayerDistance(e)
elseif state[e] == "fly" then
MoveForward(e,new_speed)
if GetPlayerFlatDistance(e) < drop_range and dropped[e] == 0 then
new_speed = bomber_speed / 2
for a = 1,c do
if state[bomb[a]] == "wait" then
if GetTimer(e) > time_between_drops then
StartTimer(e)
state[bomb[a]] = "dropped"
PlaySound(e,1)
if a == c then
dropped[e] = 1
new_speed = bomber_speed
end
break
end
end
end
end
for a = 1,c do
if state[bomb[a]] == "wait" then
SetPosition(bomb[a],g_Entity[e]['x'],g_Entity[e]['y'],g_Entity[e]['z'])
end
end
if dropped[e] == 1 then
if GetPlayerDistance(e) > distance[e] then
StopSound(e,0)
Hide(e)
Destroy(e)
end
end --dropped
end --state
end --bombs loaded
end --main
function airstrike_bomber_exit(e)
end
function GetFlatDistance(e,v)
if g_Entity[e] ~= nil and g_Entity[v] ~= nil then
local distDX = g_Entity[e]['x'] - g_Entity[v]['x']
local distDZ = g_Entity[e]['z'] - g_Entity[v]['z']
return math.sqrt((distDX*distDX)+(distDZ*distDZ));
end
end
function GetPlayerFlatDistance(e)
tPlayerDX = (g_Entity[e]['x'] - g_PlayerPosX)
tPlayerDZ = (g_Entity[e]['z'] - g_PlayerPosZ)
return math.sqrt(math.abs(tPlayerDX*tPlayerDX)+math.abs(tPlayerDZ*tPlayerDZ));
end
trigger:
local bomber = {}
function airstrike_trigger_init_name(e,name)
weapon_name[e] = name
state[e] = "wait"
end
function airstrike_trigger_main(e)
if bomber[e] == nil then
Prompt("no bomber for airstrike "..weapon_name[e])
for a = 1,9999 do
if g_Entity[a] ~= nil then
if a ~= e then
if weapon_name[a] ~= nil then
if weapon_name[a] == weapon_name[e] then
bomber[e] = a
break
end
end
end
end
end
else
if GetPlayerInZone(e) == 1 and state[bomber[e]] == "wait" then
state[bomber[e]] = "active"
Destroy(e)
end --in zone
end --bomber check
end --main
function airstrike_trigger_exit(e)
end
bomb:
function airstrike_bomb_init(e)
weapon_name[e] = "air strike bomb"
state[e] = "wait"
if first_bomb == nil then
first_bomb = e
end
max_bomb = e
CollisionOff(e)
Hide(e)
end
function airstrike_bomb_main(e)
if state[e] == "dropped" then
Show(e)
drop_speed = drop_speed * 1.0001
MoveUp(e,-drop_speed)
MoveForward(e,bomber_speed/4)
if g_Entity[e]['y'] < 605 then
SetEntityHealth(e,0)
Destroy(e)
end
end
end
function airstrike_bomb_exit(e)
end
happy bombing
life\'s one big game
windows vista ultimate
i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11