-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_nuke_fill_ping.lua
103 lines (91 loc) · 2.86 KB
/
unit_nuke_fill_ping.lua
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
function widget:GetInfo()
return {
name = "Nuke Ping",
desc = "Pings when nuke missile is ready",
author = "hihoman23",
date = "2023",
license = "GNU GPL, v3 or later",
layer = 0,
enabled = true -- loaded by default?
}
end
local makePingRed = true
local pingColor
if makePingRed then
pingColor = "\255"..string.char(255)..string.char(1)..string.char(1)
else
pingColor = ""
end
local nukePings = 0
local maxPings = 5
local nukes = {}
local nukeDefs = {
["armsilo"] = true,
["corsilo"] = true
}
local myTeam = Spring.GetMyTeamID()
local spGetUnitPosition = Spring.GetUnitPosition
local spGetUnitDefID = Spring.GetUnitDefID
--[[function widget:GameFrame()
for nukeID, prevStockpile in pairs(nukes) do
local stockpile = Spring.GetUnitStockpile(nukeID)
if prevStockpile > stockpile then
nukes[nukeID] = stockpile
end
if nukePings < maxPings then
if prevStockpile < stockpile then
nukes[nukeID] = stockpile
nukePings = nukePings + 1
local ux, uy, uz = spGetUnitPosition(nukeID)
Spring.MarkerAddPoint(ux, uy, uz, "nuke is ready", true)
end
end
end
end]]
function widget:StockpileChanged(nukeID, unitDefID, unitTeam, weaponNum, prevStockpile, stockpile)
if nukes[nukeID] and (nukePings < maxPings) then
if prevStockpile > stockpile then
nukes[nukeID] = stockpile
end
if prevStockpile < stockpile then
nukes[nukeID] = stockpile
nukePings = nukePings + 1
local ux, uy, uz = spGetUnitPosition(nukeID)
Spring.MarkerAddPoint(ux, uy, uz, pingColor .. "nuke is ready", true)
end
end
end
function AddUnit(unitID, unitDefID, unitTeam)
local def = UnitDefs[unitDefID]
if nukeDefs[def.name] then
if unitTeam == myTeam then
local stockpile = Spring.GetUnitStockpile(unitID)
nukes[unitID] = stockpile
end
end
end
function widget:UnitCreated(unitID, unitDefID, unitTeam)
AddUnit(unitID, unitDefID, unitTeam)
end
function widget:UnitGiven(unitID, unitDefID, unitTeam)
AddUnit(unitID, unitDefID, unitTeam)
end
function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
if nukes[unitID] then
nukes[unitID] = nil
end
end
function widget:Initialize()
if Spring.GetSpectatingState() then
widgetHandler:RemoveWidget(self)
do return end
end
for _, unitID in pairs(Spring.GetTeamUnits(myTeam)) do
AddUnit(unitID, spGetUnitDefID(unitID), myTeam)
end
end
function widget:PlayerChanged(playerID)
if Spring.GetSpectatingState() then
widgetHandler:RemoveWidget(self)
end
end