-
Notifications
You must be signed in to change notification settings - Fork 0
/
snd_mapmark_ping.lua
134 lines (112 loc) · 3.51 KB
/
snd_mapmark_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
function widget:GetInfo()
return {
name = "Mapmark Ping",
desc = "Plays a sound when a point mapmark is placed by an allied player.",
author = "hihoman23",
date = "June 2024",
license = "GNU GPL, v2 or later",
layer = 0,
enabled = true
}
end
------------ config --------------
local mapmarkFile = "sounds/ui/mappoint2.wav"
local priorityPing = "sounds/ui/priority.wav"
local volume = 0.6
local range = 100
----------- local variables -------------
local isSpec = false
local airCount = 0
---------- Spring functions ---------------
local myTeam = Spring.GetMyTeamID()
local GetTeamAllyTeamID = Spring.GetTeamAllyTeamID
local myAllyTeam = GetTeamAllyTeamID(myTeam)
local GetUnitsInCylinder = Spring.GetUnitsInCylinder
local GetUnitTeam = Spring.GetUnitTeam
local GetUnitDefID = Spring.GetUnitDefID
local GetAllUnits = Spring.GetAllUnits
local GetUnitAllyTeam = Spring.GetUnitAllyTeam
local aircraft = {}
for unitDefID, def in pairs(UnitDefs) do
if def.isAirUnit and not def.isBuilder then
aircraft[unitDefID] = true
end
end
function widget:PlayerChanged()
isSpec = Spring.GetSpectatingState()
myTeam = Spring.GetMyTeamID()
myAllyTeam = GetTeamAllyTeamID(myTeam)
end
local function initUnit(unitID, unitDefID, team)
if aircraft[unitDefID] and team == myTeam then
airCount = airCount + 1
end
end
function widget:Initialize()
widget:PlayerChanged()
WG['mapmarkping'] = {}
WG['mapmarkping'].getMapmarkVolume = function()
return volume
end
WG['mapmarkping'].setMapmarkVolume = function(value)
volume = value
end
for _, uID in ipairs(GetAllUnits()) do
initUnit(uID, GetUnitDefID(uID), GetUnitTeam(uID))
end
end
function checkForAircraft(...)
local units = GetUnitsInCylinder(...)
for _, uID in ipairs(units) do
if not (myAllyTeam == GetUnitAllyTeam(uID)) and aircraft[GetUnitDefID(uID)] then
return true
end
end
return false
end
function widget:MapDrawCmd(playerID, cmdType, x, y, z, a, b, c)
if cmdType == "point" then
local allUnits = GetUnitsInCylinder(x, z, range)
local unitFound = false
for _, unit in ipairs(allUnits) do
if GetUnitTeam(unit) == myTeam then
unitFound = true
break
end
end
if not unitFound and airCount > 0 then
unitFound = string.find(string.lower(a), "air") or checkForAircraft(x, z, range)
end
if unitFound and (not isSpec) then
Spring.PlaySoundFile(priorityPing, volume*0.5, nil, "ui")
else
Spring.PlaySoundFile( mapmarkFile, volume*20, x, y, z, nil, nil, nil, "ui")
Spring.PlaySoundFile( mapmarkFile, volume*0.3, nil, "ui" ) -- to make sure it's still somewhat audible when far away
end
end
end
function widget:UnitCreated(...)
initUnit(...)
end
function widget:UnitGiven(...)
initUnit(...)
local _, unitDefID, _, oldTeam = ...
if oldTeam == myTeam and aircraft[unitDefID] then
airCount = airCount - 1
end
end
function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
if unitTeam == myTeam and aircraft[unitDefID] then
airCount = airCount - 1
end
end
function widget:GetConfigData(data)
return {
volume = volume,
}
end
function widget:SetConfigData(data)
if data.volume ~= nil then
volume = data.volume
end
end