I'm currently using the below code, yet I don't know what type of godmode this provides. I can still die by cars and barrel myself.
[lua]local function ccGodModeOn( ply )
if not ply:HasPriv(ADMIN) then ply:PrintMessage(2, string.format(LANGUAGE.need_admin, "rp_godmodeon"))
return
end
if ply:HasPriv(ADMIN) then
ply:GodEnable()
end
end
concommand.Add("rp_godmodeon", ccGodModeOn)
local function ccGodModeOff( ply )
if not ply:HasPriv(ADMIN) then ply:PrintMessage(2, string.format(LANGUAGE.need_admin, "rp_godmodeoff"))
return
end
if ply:HasPriv(ADMIN) then
ply:GodDisable()
end
end
concommand.Add("rp_godmodeon", ccGodModeOff)[/lua]
[lua]function GM:EntityTakeDamage( t_Entity, t_Inflictor, t_Attacker, t_DamageAmount )
if ( t_Ent:IsPlayer() && t_Ent:GetNetworkedBool( "IsGod" ) ) then
return;
end
end[/lua]
Now just make something to toggle "IsGod".
I toggled IsGod however:
[lua]
[gamemode\server\gamemode_functions.lua:871] attempt to index global 't_Ent' (a nil value)(Hook: EntityTakeDamage)
[gamemode\server\gamemode_functions.lua:871] attempt to index global 't_Ent' (a nil value)(Hook: EntityTakeDamage)
[/lua]
Change t_Entity to t_Ent (line 1), or t_Ent to t_Entity (line 3). Either will work.
Now, I just need to figure out the toggle. My attempt of ply:IsGod() did not go so well. ^_^
[QUOTE=Bubka3;37702243]I can still die by cars and barrel myself.[/QUOTE]
Be best to use PlayerShouldTakeDamage.
[QUOTE=Bubka3;37705824]I toggled IsGod however:
[lua]
[gamemode\server\gamemode_functions.lua:871] attempt to index global 't_Ent' (a nil value)(Hook: EntityTakeDamage)
[gamemode\server\gamemode_functions.lua:871] attempt to index global 't_Ent' (a nil value)(Hook: EntityTakeDamage)
[/lua][/QUOTE]
Oh wow I'm sorry, my bad. I didn't realize I did that.
[lua]function GM:EntityTakeDamage( t_Entity, t_Inflictor, t_Attacker, t_DamageAmount )
if ( t_Entity:IsPlayer() && t_Entity:GetNetworkedBool( "IsGod" ) ) then
return;
end
end[/lua]
There are multiple ways you could toggle it, although I recommend using the new net library that's in Garry's Mod 13 (Beta).
If you were to do so, then please examine and process the following:
[b]Serverside:[/b]
[lua]util.AddNetworkString( "ToggleGodmode" );
net.Receive( "ToggleGodmode", function( )
local t_Player = net.ReadEntity();
-- Is the requesting entity valid, and a player?
if ( IsValid( t_Player ) && t_Player:IsPlayer() ) then
-- If it is a valid player, then we make sure they're at least an administrator.
-- You can put any type of check in here, you could even add another variable
-- to the networked message like "t_Password", so the player could either be
-- an admin, or provide a correct password.
if ( t_Player:IsAdmin() ) then
-- Basically what this does is, it sets the networked boolean "IsGod" to
-- opposite of what it currently is.
-- If it doesn't exist, that just means it'll return true and enable it
-- on the first request.
t_Player:SetNWBool( "IsGod", !t_Player:GetNWBool( "IsGod" ) );
-- Not something you really need, but an example of how you could display
-- to the server's console that somebody toggled godmode on themself.
MsgN( "Player " .. t_Player:Nick() .. " toggled godmode on themself. (Active = " .. t_Player:GetNWBool( "IsGod" ) .. ")" );
end
end
end );[/lua]
[b]Clientside:[/b]
[lua]concommand.Add( "rp_godmode", function( )
net.Start( "ToggleGodmode" );
net.WriteEntity( LocalPlayer() );
net.SendToServer();
end );[/lua]
Excuse my broad usage of spaces, I find it much easier to read it when there are larger spaces.
Also I usually start non-global variables with 't_' defining that they're temporary, because I can't stand capitalized variables.
[QUOTE=TylerB;37707485][lua]
concommand.Add("rp_godmodeon", ccGodModeOn)
concommand.Add("rp_godmodeon", ccGodModeOff)
[/lua]
:v:[/QUOTE]
The sad part is, even with you posting this, it took me 5x times reading it over to understand. :P
@DaneSomdahl, I will use the network method when GMOD 13 is out from beta, thanks! :D
Possibly because said killers use :Kill and do not apply damage.
[QUOTE=Wizard of Ass;37716562]Possibly because said killers use :Kill and do not apply damage.[/QUOTE]
Even so, you could still use the same networked boolean to make the player unable to die that way as well.
No lol.
[editline]18th September 2012[/editline]
Kill() simply kills a player, there is no damage applies thus this hook is pointless.
Sorry, you need to Log In to post a reply to this thread.