Hey, Im having a bit of trouble getting colored kill logs in the chat for the admin and above rank, and for the admin job. I messed about and got this, (in sv autorun)
[lua]function GM:PlayerDeath(ply, weapon, killer)
if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].PlayerDeath then
RPExtraTeams[ply:Team()].PlayerDeath(ply, weapon, killer)
end
if weapon:IsVehicle() and weapon:GetDriver():IsPlayer() then killer = weapon:GetDriver() end
local KillerName = (killer:IsPlayer() and killer:Nick()) or tostring(killer)
local WeaponName = IsValid(weapon) and ((weapon:IsPlayer() and IsValid(weapon:GetActiveWeapon()) and weapon:GetActiveWeapon():GetClass()) or weapon:GetClass()) or "unknown"
if IsValid(weapon) and weapon:GetClass() == "prop_physics" then
WeaponName = weapon:GetClass() .. " (" .. (weapon:GetModel() or "unknown") .. ")"
end
if killer == ply then
KillerName = "Himself"
WeaponName = "suicide trick"
end
chat.AddText( Color( 100, 100, 255 ), ply:Nick(), " was killed by ", Color( 100, 255, 100 ) .. KillerName .. "with a" .. WeaponName .. )
end[/lua]
Thanks for the help
chat.addtext is client sided and playerdeath is server sided. to do it server sided you would have to do ply:chatprint() or network the players name and send it to the client and use chat.addtext. If you do use the chatprint method the best way would be to run it through a for loop, and check if the players are an admin or whatever group and then print it to them.
?If you want to make it 100% clientside, look at this:
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/game_event_listeners.lua[/url]
The last one:
gameevent.Listen("entity_killed")
hook.Add( "entity_killed", "entity_killed:Example", function( _data )
Is shared. To access the actual Entity for each of the data points, use Entity( _data.attacker ); etc...
I just filled the entity conversions in for you. Additionally, I added if CLIENT then hook.Call player death. This turns the PlayerDeath hook into a shared hook meaning, just by dropping the last game-event into a shared or client file, your code in the original post should work ( as long as it doesn't need to use server calls ).
Sorry, you need to Log In to post a reply to this thread.