forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGiveTask.lua
More file actions
60 lines (51 loc) · 1.86 KB
/
GiveTask.lua
File metadata and controls
60 lines (51 loc) · 1.86 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
57
58
59
60
local ScriptTask = import('/lua/sim/ScriptTask.lua').ScriptTask
local TASKSTATUS = import('/lua/sim/ScriptTask.lua').TASKSTATUS
local AIRESULT = import('/lua/sim/ScriptTask.lua').AIRESULT
local GiveUnitsToPlayer = import('/lua/simutils.lua').GiveUnitsToPlayer
local SpawnPing = import('/lua/SimPing.lua').SpawnPing
local transferList = {}
GiveTask = Class(ScriptTask) {
OnCreate = function(self, commandData)
ScriptTask.OnCreate(self, commandData)
local unit = self:GetUnit()
local from = unit.Army
local to = commandData.To
self.Army = from
transferList[from] = transferList[from] or {}
transferList[from][to] = transferList[from][to] or {}
table.insert(transferList[from][to], unit)
self.first = true
end,
TaskTick = function(self)
if self.first then
-- Wait a tick to let all GiveTask commands execute
self.first = false
return TASKSTATUS.Wait
end
for to, array in transferList[self.Army] or {} do
local units = {}
for _, unit in array do
if not unit.Dead and unit.Army == self.Army then
table.insert(units, unit)
end
end
if units[1] then
GiveUnitsToPlayer({To=to}, units)
local data = {
Type='alert',
Location=units[1]:GetPosition(),
Lifetime=10,
Owner=self.Army,
To=to,
Ring='/game/marker/ring_yellow02-blur.dds',
Sound='UEF_Select_Radar',
Mesh='alert_marker',
ArrowColor='yellow',
}
SpawnPing(data)
end
end
transferList[self.Army] = {}
return TASKSTATUS.Done
end,
}