Gmod automatic AOD god (and message)

Hello there, I was wondering if you guys have an idea on how to make it say “player has gone AOD!”

Here’s my system for the godmode
Code: [Select]

if (SERVER) then

local adminondutyteams = { TEAM_ADMIN }

hook.Add(“PlayerShouldTakeDamage”, “godmodeAdminsss”, function(ply)
if ( ply:IsPlayer() ) then
for i, v in ipairs(adminondutyteams) do
if ply:Team() == v then
return false
end
end
end
end

But does anyone have a clue how to make it so it says playername has gone aod!?
Would I have to make a PlayerSay hook that gets called when they go admin on duty? I am not sure how though.
Maybe
if Player:Team == TEAM_ADMIN then
AddChat( “v:Nick has gone AOD!” )
??? Thank you.

You need not create a hook for manually creating a god mode when you can use the natively supplied functions,

Player:GodEnable and

Player:GodDisable.

You can then do something like this:

[lua]
local _AOD_NETMSG = “aod_message_broadcast”
local _AOD_MESSAGE_ENABLE = “%s has gone AOD!”
local _AOD_MESSAGE_DISABLE = “%s is no longer AOD!”

if SERVER then

local PLAYER = FindMetaTable( "Player" )
if ( not PLAYER ) then return end -- You have a serious problem if this happens

util.AddNetworkString( _AOD_NETMSG )

function PLAYER:AdminOnDuty( bOnDuty )

	if ( bOnDuty ) then self:GodEnable() else self:GodDisable() end
	
	net.Start( _AOD_NETMSG )
		net.WriteEntity( self )
		net.WriteBool( bOnDuty )
	net.Broadcast( )
	
end

else

net.Receive( _AOD_NETMSG, function(len)

	local ePlayer = net.ReadEntity( )
	local bOnDuty = net.ReadBool( )
	
	chat.AddText( string.format( bOnDuty and _AOD_MESSAGE_ENABLE or _AOD_MESSAGE_DISABLE, ePlayer:Nick() ) )

end)

end
[/lua]

Be warned that I haven’t tested the code, it was simply to give you an indication of how it could be accomplished. I chose to network it and have the message print from the client realm because you may choose to call a hook from there to indicate to other parts of your code that this event has occurred.

Thank you very much! It will probably work better than what I had in mind. You see what I was planning on doing is scrapping my old one and making the following lua files in autorun client + server…

server:



util.AddNetworkString( "sf_name" )


concommand.Add( "Shadowfunc",
function shadowfunction()
	local ply = LocalPlayer()
	if ply:Team() == "TEAM_ADMIN" then
		ply:GodEnable
	else
		print "You're not admin! You can NOT have godmode! HAHAHAH"
	end
	net.Start( "sf_name" )
		net.WriteString( ply:Name )
	net.Send( ply )
end )



Client:



function HasGoneAod()
	local name = net.ReadString()
	
	chat.AddText( color( 0, 255, 255 ), name, "Has gone AOD! And have granted godmode upon themself.")
end


Can I know though, how will it know that my team is TEAM_ADMIN? On your one?
Or do I need to keep most of the old one, and then just write what you put down?

this wont work, at all.

True… but instead of just saying it won’t work… maybe say how I can improve it? Your comment is really useless.

concommand.Add takes 2 base arguments, commands and function
you can’t do

concommand.Add(“test”,function test() <body> end)

You have to do, since you’re defining a function as second parameter

concommand.Add(“test”,function <body> end)

Or

function test() <body> end
concommand.Add(“test”,test)


concommand.Add("test", function() <body> end)

FTFY