Have damagelogs working, wondering how to make all logs display in admins console

Me and a friend are trying to get damagelogs working for a jailbreak server.

This is our damagelog code to display a damagelog to the user that was damaged



 function GM:PlayerHurt( victim, attacker, healthleft, healthtaken, ply )
  if ( attacker:IsPlayer() ) then
 victim:PrintMessage( HUD_PRINTCONSOLE, "You were attacked by " .. attacker:GetName() .. " for " .. tostring(healthtaken) .. " damage.
")
 end
 end


That works fine but once we try to get all damagelogs to display in console for admins, it stops working



function GM:PlayerHurt( victim, attacker, healthleft, healthtaken, ply )
   if (ply:IsSuperAdmin() ) then
 PrintMessage( HUD_PRINTCONSOLE, victim:GetName() .. "was attacked by " .. attacker:GetName() .. " for " .. tostring(healthtaken) .. " damage.
")
 else
  if ( attacker:IsPlayer() ) then
 victim:PrintMessage( HUD_PRINTCONSOLE, "You were attacked by " .. attacker:GetName() .. " for " .. tostring(healthtaken) .. " damage.
")
 end
 end
 end


I am completely new to coding so any help would be appreciated. We are trying to learn

The error we are getting is "attempt to index local ‘ply’ (a nil value)

There is not 5th argument, so ply will never be anything other than nil.

So how would we go around adding it so all damage logs are shown to superadmins and admins?

Thanks for the fast reply!

You have to cycle through all players and look if they are an admin.
Would be more efficient if you would make a table with all admins in it.



function GM:PlayerHurt( victim, attacker, healthleft, healthtaken)
	if ( attacker:IsPlayer() ) then
		victim:PrintMessage(HUD_PRINTCONSOLE, "You were attacked by "..attacker:GetName().." for "..tostring(healthtaken).." damage.
")
		for k, v in pairs(player.GetAll()) do
			if v:IsSuperAdmin() or v:IsAdmin() then
				v:PrintMessage(HUD_PRINTCONSOLE, victim:GetName().." was attacked by "..attacker:GetName().." for "..tostring(healthtaken).." damage.
")
			end
		end
	end
end


If we made the table with all admins in that, that mean we could chose select people aswell?

So we could have all Trialmods, all mods, all admins, all superadmins and then select users if we felt like it, right?

Great reply thank you! We do have ULX on the server which has the user group options. If we could incorporate that into the code would that be better? Also how would I go about doing that?

Sorry about these newbie questions

I have no idea about ULX but you could just do smth like this:



local players = {
	"STEAMID",
	"STEAMID",
	"STEAMID"
}

local playerson = {}

local function addtotable(ply)
	for k, v in pairs(players) do
		if ply:SteamID() == v then
			table.insert(playerson, ply)
		end
	end
end


local function removefromtable(ply)
	for k, v in pairs(playerson) do
		if ply == v then
			table.remove(playerson, k)
		end
	end
end

hook.Add("PlayerAuthed", "addtotable", addtotable)
hook.Add("PlayerDisconnected", "removefromtable", removefromtable)


Just put the steamids in the first table.

Untested though.
Enough code feeding for now. :slight_smile:

Thanks for the help, will update you if it works after we have put it in.

Just so you know you should not reply with an [del]image[/del] meme, you might get banned :\

also the ULX question:



ply:IsUserGroup("SuperDuper-Admin")


would return true if the player’s rank is “SuperDuper-Admin”