Skip to content

Commit ada67cf

Browse files
Fix triggerClientEvent nil argument in admin chat handler (#713)
triggerClientEvent failed due to a nil sender Added a fallback for the sender element using local sender = client or source. Added a safety check to ensure aPlayers[player] exists before accessing its indices. Fixed potential script breaks when the admin chat is triggered via certain console commands.
1 parent 578598a commit ada67cf

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

[admin]/admin2/server/admin_server.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,13 @@ addEventHandler(
407407
"aAdminChat",
408408
root,
409409
function(chat)
410-
if #chat > ADMIN_CHAT_MAXLENGTH then
410+
local sender = client or source
411+
if not chat or #chat > (ADMIN_CHAT_MAXLENGTH or 255) then
411412
return
412413
end
413-
for id, player in ipairs(getElementsByType("player")) do
414-
if (aPlayers[player]["chat"]) then
415-
triggerClientEvent(player, "aClientAdminChat", client, chat)
414+
for _, player in ipairs(getElementsByType("player")) do
415+
if aPlayers[player] and aPlayers[player]["chat"] then
416+
triggerClientEvent(player, "aClientAdminChat", sender, chat)
416417
end
417418
end
418419
end

0 commit comments

Comments
 (0)