General > Off-Topic

Please Help!

(1/2) > >>

BrightLiteFilms:
I am running ULX and Ulib. I just want to know if there is a way to make it so that deaths (who killed who) shows up in the chat bar for admins only. This will help me know if it was RDM, and it would be appreciated if someone would tell me how to do that, if there is even a way.

Megiddo:
Completely untested but try the following:


--- Code: ---local function death( victim_name, victim_team, inflicter_name, attacker_name, attacker_team )
local players = player.GetAll()
local str = ("%s was killed by %s"):format( victim_name, attacker_name )
for i=1, #players do
if players[ i ]:IsAdmin() then
players[ i ]:PrintMessage( HUD_PRINTTALK, str )
end
end
return true
end
hook.Add( "AddDeathNotice", "deathNotifyAdmins", death )
--- End code ---

BrightLiteFilms:
Thank you! It is much appretiated. But, I don't mean to sound stupid, but I am new to LUA coding. What .lua file does it go into? :/

MrPresident:
It's fine, everyone has to start somewhere.. But you would want to put this into its own file.

Create a file called deathnotifyadmin.lua and place it in your garrysmod/lua/autorun folder.

also... sorry to step on your toes Meg.. but this would be a more optimal way of doing it..


--- Code: ---function PlayerDeathAdminNotify( victim, weapon, killer )
if not victim:IsPlayer() or not killer:IsPlayer() then return end
local str = victim:GetName() .. " was killed by " .. killer:GetName() .. "."
for _, v in pairs( player.GetAll() ) do
if v:IsAdmin() then
v:PrintMessage( HUD_PRINTTALK, str )
end
end
end
hook.Add( "PlayerDeath", "PlayerDeathAdminNotify", PlayerDeathAdminNotify )
--- End code ---

Megiddo:

--- Quote from: MrPresident on July 12, 2010, 11:35:26 AM ---also... sorry to step on your toes Meg.. but this would be a more optimal way of doing it..


--- Code: ---function PlayerDeathAdminNotify( victim, weapon, killer )
if not victim:IsPlayer() or not killer:IsPlayer() then return end
local str = victim:GetName() .. " was killed by " .. killer:GetName() .. "."
for _, v in pairs( player.GetAll() ) do
if v:IsAdmin() then
v:PrintMessage( HUD_PRINTTALK, str )
end if
end
end
hook.Add( "PlayerDeath", "PlayerDeathAdminNotify", PlayerDeathAdminNotify )
--- End code ---

--- End quote ---

No problem, though you do have an 'end if' in there, and you should be returning to make it not show on the upper right. :)

I'd disagree on the use of pairs, but when we're talking about a difference of a few milliseconds every minute, it hardly matters.

Navigation

[0] Message Index

[#] Next page

Go to full version