-
Notifications
You must be signed in to change notification settings - Fork 28
/
DiscordPing.lua
384 lines (346 loc) · 12.8 KB
/
DiscordPing.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
--[[
Tab in Misc -> Discord Ping
]]
local References = {
Menu = gui.Reference('Menu'),
Misc = gui.Reference('Misc')
}
local Tab = gui.Tab(References.Misc, 'discordping', 'Discord Ping')
local Groupbox = {
General = gui.Groupbox(Tab, 'General', 16, 16, 295)
}
local GUIObjects = {
Ping = {
EndMatch = {}
},
Webhook = {}
}
-- Master Switch
GUIObjects.MasterSwitch = gui.Checkbox(Groupbox.General, 'enable', 'Enable', 0)
GUIObjects.MasterSwitch:SetDescription('Enable Discord Ping.') -- Set Master Switch Description
-- Ping Options
GUIObjects.Ping.MultiBox = gui.Multibox(Groupbox.General, 'Send Info')
GUIObjects.Ping.StartMatch = gui.Checkbox(GUIObjects.Ping.MultiBox, 'matchstart', 'At Match Start', 1)
GUIObjects.Ping.EndMatch.Enabled = gui.Checkbox(GUIObjects.Ping.MultiBox, 'matchend', 'At Match End', 0)
GUIObjects.Ping.EndMatch.MultiBox = gui.Multibox(Groupbox.General, 'At Match End')
GUIObjects.Ping.EndMatch.Send = {
Rank = gui.Checkbox(GUIObjects.Ping.EndMatch.MultiBox, 'matchend.rank', 'Send Rank', 1),
Kills = gui.Checkbox(GUIObjects.Ping.EndMatch.MultiBox, 'matchend.kills', 'Send Kills', 1),
Assists = gui.Checkbox(GUIObjects.Ping.EndMatch.MultiBox, 'matchend.assists', 'Send Assists', 0),
Deaths = gui.Checkbox(GUIObjects.Ping.EndMatch.MultiBox, 'matchend.deaths', 'Send Deaths', 1),
MVPs = gui.Checkbox(GUIObjects.Ping.EndMatch.MultiBox, 'matchend.mvps', 'Send MVPs', 0),
Score = gui.Checkbox(GUIObjects.Ping.EndMatch.MultiBox, 'matchend.score', 'Send Score', 0)
}
GUIObjects.Ping.RankShortName = gui.Checkbox(Groupbox.General, 'rankshortname', 'Use Short Names For Rank', 1)
-- Webhook
GUIObjects.Webhook.Window = gui.Window('misc.discordping.webhook', 'Discord Webhook', 0, 0, 860, 100)
GUIObjects.Webhook.Button = gui.Button(Groupbox.General, 'Webhook', function()
GUIObjects.Webhook.Window:SetActive(not GUIObjects.Webhook.Window:IsActive())
end)
GUIObjects.Webhook.Text = gui.Editbox(GUIObjects.Webhook.Window, 'text', '')
GUIObjects.Webhook.Window:SetActive(false) -- Disable Window By Default
GUIObjects.Webhook.Button:SetWidth(265) -- Set Webhook Button Width
-- You can add your webhook here as well so you won't need to add it all the time.
GUIObjects.Webhook.Text:SetValue('')
-- Menu Objects Handler
callbacks.Register('Draw', function()
GUIObjects.Ping.EndMatch.MultiBox:SetInvisible(not GUIObjects.Ping.EndMatch.Enabled:GetValue()) -- Hide End Match Multibox if it's disabled.
if not References.Menu:IsActive() then -- Hide webhook window if cheat menu is hidden
GUIObjects.Webhook.Window:SetActive(false)
end
end)
-- Main
local MapNames = {
['ar_baggage'] = 'Baggage',
['ar_dizzy'] = 'Dizzy',
['ar_lunacy'] = 'Lunacy',
['ar_monastery'] = 'Monastery',
['ar_shoots'] = 'Shoots',
['cs_agency'] = 'Agency',
['cs_assault'] = 'Assault',
['cs_italy'] = 'Italy',
['cs_militia'] = 'militia',
['cs_office'] = 'Office',
['de_anubis'] = 'Anubis',
['de_bank'] = 'Bank',
['de_cache'] = 'Cache',
['de_cbble'] = 'Cobblestone',
['de_chlorine'] = 'Chlorine',
['de_dust2'] = 'Dust II',
['de_inferno'] = 'Inferno',
['de_lake'] = 'Lake',
['de_mirage'] = 'Mirage',
['de_nuke'] = 'Nuke',
['de_overpass'] = 'Overpass',
['de_safehouse'] = 'Safehouse',
['de_shortdust'] = 'Shortdust',
['de_shortnuke'] = 'Shortnuke',
['de_stmarc'] = 'St. Marc',
['de_sugarcane'] = 'Sugarcane',
['de_train'] = 'Train',
['de_vertigo'] = 'Vertigo',
['dz_blacksite'] = 'Blacksite',
['dz_junglety'] = 'Junglety',
['dz_sirocco'] = 'Sirocco',
['gd_cbble'] = 'Cobblestone',
['gd_rialto'] = 'Rialto'
}
local Ranks = {
DangerZone = {
'Lab Rat I',
'Lab Rat II',
'Sprinting Hare I',
'Sprinting Hare II',
'Wild Scout I',
'Wild Scout II',
'Wild Scout Elite',
'Hunter Fox I',
'Hunter Fox II',
'Hunter Fox III',
'Hunter Fox Elite',
'Timber Wolf',
'Ember Wolf',
'Wildfire Wolf',
'The Howling Alpha'
},
Matchmaking = {
Names = {
'Silver I',
'Silver II',
'Silver III',
'Silver IV',
'Silver Elite',
'Silver Elite Master',
'Gold Nova I',
'Gold Nova II',
'Gold Nova III',
'Gold Nova Master',
'Master Guardian I',
'Master Guardian II',
'Master Guardian Elite',
'Distinguished Master Guardian',
'Legendary Eagle',
'Legendary Eagle Master',
'Supreme Master First Class',
'Global Elite'
},
ShortNames = {
'SI',
'S2',
'S3',
'S4',
'SE',
'SEM',
'GN1',
'GN2',
'GN3',
'GNM',
'MG1',
'MG2',
'MGE',
'DMG',
'LE',
'LEM',
'SMFC',
'GE'
}
}
}
local Get = {}
Get.CompetitiveRank = function(PlayerIndex)
local PlayerRank = entities.GetPlayerResources():GetPropInt('m_iCompetitiveRanking', PlayerIndex)
return (string.find(engine.GetMapName(), 'dz') and (Ranks.DangerZone[PlayerRank] or 'Unranked'))
or (GUIObjects.Ping.RankShortName:GetValue() and (Ranks.Matchmaking.ShortNames[PlayerRank] or 'Unranked'))
or (Ranks.Matchmaking.Names[PlayerRank] or 'Unranked')
end
Get.GameMode = function()
local GameMode, GameType = tonumber(client.GetConVar('game_mode')), tonumber(client.GetConVar('game_type'))
if GameMode == 0 and GameType == 0 then
return 'Casual'
elseif GameMode == 1 and GameType == 0 then
return 'Competitive'
elseif GameMode == 2 and GameType == 0 then
return 'Wingman'
elseif GameMode == 0 and GameType == 1 then
return 'Arms Race'
elseif GameMode == 1 and GameType == 1 then
return 'Demolition'
elseif GameMode == 2 and GameType == 1 then
return 'Deathmatch'
elseif (GameMode >= 0 or GameMode <= 0) and GameType == 3 then
return 'Custom'
elseif GameMode == 0 and GameType == 4 then
return 'Guardian'
elseif GameMode == 1 and GameType == 4 then
return 'Co-op Strike'
elseif GameMode == 0 and GameType == 6 then
return 'Danger Zone'
end
end
Get.Team = function(PlayerIndex)
return entities.GetPlayerResources():GetPropInt('m_iTeam', PlayerIndex)
end
Get.TeamInitials = function(bool)
local MyTeam = Get.Team(client.GetLocalPlayerIndex())
local EnemyTeam = (MyTeam == 3) and 2 or 3
if bool then
return EnemyTeam == 3 and 'CT' or 'T'
else
return MyTeam == 3 and 'CT' or 'T'
end
end
Get.MatchStartInfo = function(bool)
local String = ''
local TotalPlayers = 0
local MyTeam = Get.Team(client.GetLocalPlayerIndex())
for PlayerIndex=1, globals.MaxClients() do
local PlayerInfo = client.GetPlayerInfo(PlayerIndex)
if PlayerInfo ~= nil then
local PlayerName = PlayerInfo['Name']
local PlayerSteamID = PlayerInfo['SteamID']
local IsPlayerBot = PlayerInfo['IsBot']
local PlayerRank = Get.CompetitiveRank(PlayerIndex)
local PlayerTeam = Get.Team(PlayerIndex)
if PlayerTeam == 2 or PlayerTeam == 3 then
if (PlayerTeam == MyTeam and bool) or (PlayerTeam ~= MyTeam and not bool) then
if IsPlayerBot then
String = String .. [[\n\t● ]] .. PlayerName .. ' (Bot)'
else
if Get.GameMode() == 'Competitive' or Get.GameMode() == 'Wingman' or Get.GameMode() == 'Danger Zone' then
String = String .. [[\n\t● ]] .. '[' .. PlayerName .. '](' .. '<https://steamcommunity.com/profiles/[U:1:' .. PlayerSteamID .. ']/>' .. ')' .. ' | ' .. PlayerRank
else
String = String .. [[\n\t● ]] .. '[' .. PlayerName .. '](' .. '<https://steamcommunity.com/profiles/[U:1:' .. PlayerSteamID .. ']/>' .. ')'
end
end
TotalPlayers = TotalPlayers + 1
end
end
end
end
if TotalPlayers == 0 then
String = String .. [[\n\tN/A]]
end
return String .. [[\n\n]]
end
Get.MatchEndInfo = function(bool)
local String = ''
local Players = {}
for PlayerIndex=1, globals.MaxClients() do
if entities.GetPlayerResources():GetPropBool('m_bConnected', PlayerIndex) then
local PlayerTeam = Get.Team(PlayerIndex)
if PlayerTeam == 2 or PlayerTeam == 3 then
local MyTeam = Get.Team(client.GetLocalPlayerIndex())
local PlayerScore = entities.GetPlayerResources():GetPropInt('m_iScore', PlayerIndex)
if (MyTeam == PlayerTeam and bool) or (MyTeam ~= PlayerTeam and not bool) then
table.insert(Players, {
player = PlayerIndex,
score = PlayerScore
})
end
end
end
end
table.sort(Players, function(a,b)
return a.score > b.score
end)
for _, v in pairs(Players) do
local PlayerIndex = v.player
local PlayerInfo = client.GetPlayerInfo(PlayerIndex)
local PlayerName = PlayerInfo['Name']
local PlayerSteamID = PlayerInfo['SteamID']
local IsPlayerBot = PlayerInfo['IsBot']
local PlayerRank = Get.CompetitiveRank(PlayerIndex)
local PlayerKills = entities.GetPlayerResources():GetPropInt('m_iKills', PlayerIndex)
local PlayerAssists = entities.GetPlayerResources():GetPropInt('m_iAssists', PlayerIndex)
local PlayerDeaths = entities.GetPlayerResources():GetPropInt('m_iDeaths', PlayerIndex)
local PlayerMVPs = entities.GetPlayerResources():GetPropInt('m_iMVPs', PlayerIndex)
local PlayerScore = v.score
if IsPlayerBot then
String = String .. [[\n\t● ]] .. PlayerName .. ' (Bot)'
else
if (GUIObjects.Ping.EndMatch.Send.Rank:GetValue() and (Get.GameMode() == 'Competitive' or Get.GameMode() == 'Wingman' or Get.GameMode() == 'Danger Zone')) then
String = String .. [[\n\t● ]] .. '[' .. PlayerName .. '](' .. '<https://steamcommunity.com/profiles/[U:1:' .. PlayerSteamID .. ']/>' .. ')' .. ' | ' .. PlayerRank
else
String = String .. [[\n\t● ]] .. '[' .. PlayerName .. '](' .. '<https://steamcommunity.com/profiles/[U:1:' .. PlayerSteamID .. ']/>' .. ')'
end
end
if GUIObjects.Ping.EndMatch.Send.Kills:GetValue() then
String = String .. ' | ' .. PlayerKills .. ' Kills'
end
if GUIObjects.Ping.EndMatch.Send.Assists:GetValue() then
String = String .. ' | ' .. PlayerAssists .. ' Assists'
end
if GUIObjects.Ping.EndMatch.Send.Deaths:GetValue() then
String = String .. ' | ' .. PlayerDeaths .. ' Deaths'
end
if GUIObjects.Ping.EndMatch.Send.MVPs:GetValue() then
String = String .. ' | ' .. PlayerMVPs .. ' MVPs'
end
if GUIObjects.Ping.EndMatch.Send.Score:GetValue() then
String = String .. ' | ' .. PlayerScore .. ' Score'
end
end
if (#Players == 0) then
String = String .. [[\n\tn/a]]
end
return String .. [[\n\n]]
end
callbacks.Register('FireGameEvent', function(Event)
if not gui.GetValue('misc.master') or not GUIObjects.MasterSwitch:GetValue() or GUIObjects.Webhook.Text:GetValue() == '' then
return
end
-- At Match Start
if GUIObjects.Ping.StartMatch:GetValue() and Event:GetName() == 'round_announce_match_start' then
local MyTeam = Get.Team(client.GetLocalPlayerIndex())
if MyTeam ~= 2 and MyTeam ~= 3 then
print('DiscordPing: Send Info -> At Match Start: Team not found')
return
end
local Content = '-------------------------' .. [[\n]]
Content = Content .. '**CS:GO Match Started**' .. [[\n-------------------------\n\n]]
Content = Content .. '**' .. Get.GameMode() .. ' | ' .. (MapNames[engine.GetMapName()] or engine.GetMapName()) .. '**'.. [[\n\n]]
Content = Content .. '**Your Team**: ' .. Get.TeamInitials(false) .. Get.MatchStartInfo(true)
Content = Content .. '**Enemy Team**: ' .. Get.TeamInitials(true) .. Get.MatchStartInfo(false)
panorama.RunScript([[
$.AsyncWebRequest(']] .. GUIObjects.Webhook.Text:GetValue() .. [[', {
type: 'POST',
data: {
content: ']] .. Content .. [['
}
});
]])
end
-- At Match End
if GUIObjects.Ping.EndMatch.Enabled:GetValue() and Event:GetName() == 'cs_win_panel_match' then
local MyTeam = Get.Team(client.GetLocalPlayerIndex())
if MyTeam ~= 2 and MyTeam ~= 3 then
print('DiscordPing: Send Info -> At Match End: Team not found')
return
end
local Content = '--------------------------' .. [[\n]]
Content = Content .. '**CS:GO Match Finished**' .. [[\n--------------------------\n\n]]
Content = Content .. '**' .. Get.GameMode() .. ' | ' .. (MapNames[engine.GetMapName()] or engine.GetMapName()) .. '**'.. [[\n\n]]
Content = Content .. '**Your Team**: ' .. Get.TeamInitials(false) .. Get.MatchEndInfo(true)
Content = Content .. '**Enemy Team**: ' .. Get.TeamInitials(true) .. Get.MatchEndInfo(false)
panorama.RunScript([[
function GetGameScore() {
const LocalPlayerTeamNumber = ']] .. tostring( Get.Team(client.GetLocalPlayerIndex()) ) .. [[';
const GameScore = () => {
CTScore = GameStateAPI.GetScoreDataJSO()['teamdata']['CT']['score'];
TScore = GameStateAPI.GetScoreDataJSO()['teamdata']['TERRORIST']['score'];
return LocalPlayerTeamNumber == 2 ? `**Score**: T: ${TScore} | CT: ${CTScore}` : `**Score**: CT: ${CTScore} | T: ${TScore}`;
};
const GameMode = GameStateAPI.GetGameModeInternalName(false);
return (GameMode != 'gungameprogressive' && GameMode != 'deathmatch' && GameMode != 'survival') ? GameScore() : null;
}
$.AsyncWebRequest(']] .. GUIObjects.Webhook.Text:GetValue() .. [[', {
type: 'POST',
data: {
content: GetGameScore() ? ']] .. Content .. [[' + GetGameScore() : ']] .. Content .. [['
}
});
]])
end
end)
client.AllowListener('round_announce_match_start')
client.AllowListener('cs_win_panel_match')