-
Notifications
You must be signed in to change notification settings - Fork 0
/
better_rezbots.lua
81 lines (68 loc) · 2.07 KB
/
better_rezbots.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
function widget:GetInfo()
return {
name = "Better(greedy) Rezbots",
desc = "Adds toggle(alt + w) to rezbots that allows them to rezzurect units and then immediately reclaim them.",
author = "hihoman23",
date = "2023",
license = "GNU GPL, v2 or later",
layer = 0,
enabled = true -- loaded by default?
}
end
local rezNames = {
["armrectr"] = true,
["cornecro"] = true
}
local rezzers = {}
local reclaimAfterRez = true
local myTeam = Spring.GetMyTeamID()
function widget:KeyPress(key, mods, isRepeat)
if (key == 119) and (mods.alt) then -- alt + w
reclaimAfterRez = not reclaimAfterRez
if reclaimAfterRez then
Spring.Echo("reclaiming rezzurected units activated")
else
Spring.Echo("reclaiming rezzurected units disabled")
end
end
end
function InitUnit(unitID, unitDefID, unitTeam)
if unitTeam == myTeam then
local def = UnitDefs[unitDefID]
if rezNames[def.name] then
rezzers[unitID] = true
end
end
end
function widget:UnitCreated(unitID, unitDefID, unitTeam, bID)
if rezzers[bID] and reclaimAfterRez then
Spring.GiveOrderToUnit(bID,
CMD.INSERT,
{0,CMD.RECLAIM,CMD.OPT_SHIFT,unitID},
{"alt"}
)
end
InitUnit(unitID, unitDefID, unitTeam)
end
function widget:UnitGiven(unitID, unitDefID, unitTeam)
InitUnit(unitID, unitDefID, unitTeam)
end
function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
if rezzers[unitID] then
rezzers[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
InitUnit(unitID, Spring.GetUnitDefID(unitID), myTeam)
end
end
function widget:PlayerChanged(playerID)
if Spring.GetSpectatingState() then
widgetHandler:RemoveWidget(self)
end
end