-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflak-barrage.lua
More file actions
56 lines (47 loc) · 1.55 KB
/
flak-barrage.lua
File metadata and controls
56 lines (47 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
-- Put this script in a "Mission Start" trigger
-- Create a trigger zone to barrage with flak, named eg. "FlakZone1"
-- Start the barrage with conditions of your choice by calling:
-- startBarrage("FlakZone1", minAlt, maxAlt, roundsPerMinute)
-- End the barrage by calling:
-- endBarrage("FlakZone1")
local PI = math.pi
local random = math.random
local cos = math.cos
local sin = math.sin
local sqrt = math.sqrt
local barrageIDs = {}
function startBarrage(zoneName, minAlt, maxAlt, roundsPerMinute)
barrageIDs[zoneName] = timer.scheduleFunction(
barrage,
{
["zoneName"] = zoneName,
["minAlt"] = minAlt,
["maxAlt"] = maxAlt,
["roundsPerMinute"] = roundsPerMinute
},
timer.getTime() + 1
)
end
function endBarrage(zoneName)
timer.removeFunction(barrageIDs[zoneName])
end
function barrage(params, time)
local zoneName = params["zoneName"]
local minAlt = params["minAlt"]
local maxAlt = params["maxAlt"]
local roundsPerMinute = params["roundsPerMinute"]
local zone = trigger.misc.getZone(zoneName)
--get a random point in the zone
local t = 2 * PI * random()
local r = random()
--taking into account terrain height generate a vec3 position at the
-- random point in the zone at a random altitude
local firevec3 = {
x = zone.point.x + (zone.radius * r * cos(t)),
y = land.getHeight(zone.point) + random(minAlt, maxAlt),
z = zone.point.z + (zone.radius * r * sin(t))
}
-- create a single flak explosion at the position
trigger.action.explosion(firevec3, 9)
return time + (60/roundsPerMinute)
end