Skip to content

Commit 6561b4d

Browse files
committed
src(verifications): Add verifications.
1 parent 2091b98 commit 6561b4d

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

plugins/admins_commands/commands.lua

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ commands:Register("slay", function(playerid, args, argsCount, silent, prefix)
2929
for i = 1, #players do
3030
local pl = players[i]
3131
pl:Kill()
32+
if not pl:CBasePlayerController():IsValid() then return end
3233
ReplyToCommand(playerid, config:Fetch("admins.prefix"),
3334
FetchTranslation("admins.slay.message"):gsub("{ADMIN_NAME}",
3435
admin and admin:CBasePlayerController().PlayerName or "CONSOLE"):gsub("{PLAYER_NAME}",
@@ -68,13 +69,15 @@ commands:Register("slap", function(playerid, args, argsCount, silent, prefix)
6869

6970
for i = 1, #players do
7071
local pl = players[i]
72+
if not pl:CBaseEntity():IsValid() then return end
7173
local vel = pl:CBaseEntity().AbsVelocity
7274
vel.x = vel.x + math.random(50, 230) * (math.random(0, 1) == 1 and -1 or 1)
7375
vel.y = vel.y + math.random(50, 230) * (math.random(0, 1) == 1 and -1 or 1)
7476
vel.z = vel.z + math.random(100, 300)
7577
pl:CBaseEntity().AbsVelocity = vel
7678
pl:CBaseEntity().Health = pl:CBaseEntity().Health - health
7779

80+
if not pl:CBasePlayerController():IsValid() then return end
7881
ReplyToCommand(playerid, config:Fetch("admins.prefix"),
7982
FetchTranslation("admins.slap.message"):gsub("{ADMIN_NAME}",
8083
admin and admin:CBasePlayerController().PlayerName or "CONSOLE"):gsub("{PLAYER_NAME}",
@@ -108,6 +111,7 @@ commands:Register("rename", function(playerid, args, argsCount, silent, prefix)
108111

109112
local pl = players[1]
110113
local name = args[2]
114+
if not pl:CBasePlayerController():IsValid() then return end
111115
if name == pl:CBasePlayerController().PlayerName then
112116
return ReplyToCommand(playerid, config:Fetch("admins.prefix"), "Same name.") -- translation
113117
end
@@ -117,9 +121,10 @@ commands:Register("rename", function(playerid, args, argsCount, silent, prefix)
117121
admin = GetPlayer(playerid)
118122
end
119123

124+
120125
local oldname = pl:CBasePlayerController().PlayerName
121126
pl:CBasePlayerController().PlayerName = name
122-
127+
if not admin:CBasePlayerController():IsValid() then return end
123128
ReplyToCommand(playerid, config:Fetch("admins.prefix"),
124129
FetchTranslation("admins.rename.message"):gsub("{ADMIN_NAME}", admin:CBasePlayerController().PlayerName):gsub(
125130
"{PLAYER_NAME}", pl:CBasePlayerController().PlayerName)) -- translation
@@ -150,6 +155,7 @@ commands:Register("csay", function(playerid, args, argsCount, silent, prefix)
150155
end
151156

152157
local message = table.concat(args, " ")
158+
if not player:CBasePlayerController():IsValid() then return end
153159
playermanager:SendMsg(MessageType.Center,
154160
string.format("%s: %s", player:CBasePlayerController().PlayerName, message))
155161
end
@@ -227,7 +233,9 @@ commands:Register("addslapmenu", function(playerid, args, argc, silent, prefix)
227233
local pl = GetPlayer(i)
228234
if pl then
229235
if not pl:IsFakeClient() then
230-
table.insert(players, { pl:CBasePlayerController().PlayerName, "sw_addslapmenu_selectplayer " .. i })
236+
if pl:CBasePlayerController():IsValid() then
237+
table.insert(players, { pl:CBasePlayerController().PlayerName, "sw_addslapmenu_selectplayer " .. i })
238+
end
231239
end
232240
end
233241
end
@@ -297,6 +305,7 @@ commands:Register("addslapmenu_selecthealth", function (playerid, args, argc, si
297305
return
298306
end
299307

308+
if not pl:CBaseEntity():IsValid() then return end
300309
local vel = pl:CBaseEntity().AbsVelocity
301310
vel.x = vel.x + math.random(50, 230) * (math.random(0, 1) == 1 and -1 or 1)
302311
vel.y = vel.y + math.random(50, 230) * (math.random(0, 1) == 1 and -1 or 1)
@@ -305,6 +314,8 @@ commands:Register("addslapmenu_selecthealth", function (playerid, args, argc, si
305314
pl:CBaseEntity().AbsVelocity = vel
306315
pl:CBaseEntity().Health = pl:CBaseEntity().Health - AddSlapMenuSelectedHealth[playerid]
307316

317+
if not player:CBasePlayerController():IsValid() then return end
318+
if not pl:CBasePlayerController():IsValid() then return end
308319
ReplyToCommand(playerid, config:Fetch("admins.prefix"),
309320
FetchTranslation("admins.slap.message"):gsub("{ADMIN_NAME}",
310321
player and player:CBasePlayerController().PlayerName):gsub("{PLAYER_NAME}",
@@ -332,7 +343,9 @@ commands:Register("addslaymenu", function(playerid, args, argc, silent, prefix)
332343
local pl = GetPlayer(i)
333344
if pl then
334345
if not pl:IsFakeClient() then
335-
table.insert(players, { pl:CBasePlayerController().PlayerName, "sw_addslaymenu_selectplayer " .. i })
346+
if pl:CBasePlayerController():IsValid() then
347+
table.insert(players, { pl:CBasePlayerController().PlayerName, "sw_addslaymenu_selectplayer " .. i })
348+
end
336349
end
337350
end
338351
end
@@ -367,11 +380,14 @@ commands:Register("addslaymenu_selectplayer", function(playerid, args, argc, sil
367380

368381
AddSlayMenuSelectedPlayer[playerid] = pid
369382

383+
if not pl:CBaseEntity():IsValid() then return end
384+
if not pl:CBasePlayerController():IsValid() then return end
370385
if pl:CBaseEntity().Health <= 0 then
371386
return ReplyToCommand(playerid, config:Fetch("admins.prefix"), FetchTranslation("admins.slay.already_dead"):gsub("{PLAYER_NAME}", pl:CBasePlayerController().PlayerName))
372387
end
373388

374389
pl:Kill()
390+
if not player:CBasePlayerController():IsValid() then return end
375391
ReplyToCommand(playerid, config:Fetch("admins.prefix"),
376392
FetchTranslation("admins.slay.message"):gsub("{ADMIN_NAME}",
377393
player and player:CBasePlayerController().PlayerName):gsub("{PLAYER_NAME}",

0 commit comments

Comments
 (0)