DarkRP - Administrator - Godmode.

Hello, I’ve been trying to workout myself how to give godmode to Administrators but only when they are the current Administrator class. I just basically need some help with a little code as the code what i’ve come up with doesn’t work at all, no I don’t get any errors but it just doesn’t work.

Could I get a “help of a hand” ?


 
TEAM_ADMIN = DarkRP.createJob("Administrator", {
    color = Color(0, 0, 0, 255),
    model = {"models/Combine_Super_Soldier.mdl"},
    description = [[This is the job for the "GameMasters"!]],
    weapons = {"weapon_ak472"},
    command = "adminonduty",
    max = 0,
    salary = 60,
    admin = 1,
    vote = false,
    hasLicense = true,
    PlayerSpawn = function(ply) ply:GodEnable() end,     
   
})





local function godadmins(ply)
    if (ply:Team() == TEAM_ADMIN) then
        ply:GodEnable()
    end
end
hook.Add("PlayerSpawn", "enablegodadmin", godadmins)


This is serverside.

You can probably figure out how to make it so that when they change their job to and from Administrator it will give/revoke godmode.

PlayerSpawn = function(ply) ply:concommand(“ulx”, “god”) end,

Try this, I didnt test it!


local function AdminGod(p,from,to)
    if to == TEAM_ADMIN then
        p:GodEnable()
    elseif from == TEAM_ADMIN then
        p:GodDisable()
    end
end

hook.Add("OnPlayerChangedTeam", "admingod",AdminGod)

Or with ulx


local function AdminGod(p,from,to)
    if to == TEAM_ADMIN then
        ulx.god(p,p,false)
    elseif from == TEAM_ADMIN then
        ulx.god(p,p,false)
    end
end

hook.Add("OnPlayerChangedTeam", "admingod",AdminGod)

Both are untested but i am positive example #1 works.
I’ve never used ulx before so i just catched that function and arguments.

Good luck!

So could you give me an example of what file I can place this into? :L

Server side I believe.

Edit: AKA lua/autorun/server

Thanks, but it makes no difference, with no errors.

I’d say do something like this:


function GM:PlayerShouldTakeDamage( _victim, _attacker )
	// People connecting should not take damage
	if ( !_victim:IsFullyConnected( ) && _victim:IsPlayer( ) ) then return false; end

	// Admins in admin mode should not take damage
	if ( _victim:IsAdmin( ) ) then return false; end

	return true
end

My IsAdmin function only returns true when the player is spawned in as an admin character. You should adapt it to check the team; also the Fully Connected function is custom; yours should look like this:


//
// When making hooks; only return values in your SPECIFIC scenario otherwise it may break other functionality of a gamemode. - Josh 'Acecool' Moser
//
hook.Add( "PlayerShouldTakeDamage", "AdminGodMode", function( _victim, _attacker )
	if ( IsValid( _victim ) && _victim:IsPlayer( ) ) then
		// Admins in admin mode should not take damage
		if ( _victim:IsAdmin( ) && _victim:Team( ) == TEAM_ADMIN ) then return false; end
	end
end );


//
// No fall damage either...
//
hook.Add( "GetFallDamage", "AdminGodMode", function( _victim, _fallspeed )
	if ( IsValid( _victim ) && _victim:IsPlayer( ) ) then
		// Admins in admin mode should not take damage
		if ( _victim:IsAdmin( ) && _victim:Team( ) == TEAM_ADMIN ) then return 0; end
	end
end );

The reason you may have issues with GodEnable / Disable is because it is bugged… Sometimes damage is allowed, and if an admin dies with GodEnable, then God must be Disabled before re-enabling it to get it to work again. It is much easier to design a simple hook, or two, which handles the damage prevention for you without any issues.

So you actually think it will work?

[editline]20th September 2014[/editline]

I tried it, but when I’m administrator as soon as someone hits me a few times i’m godded but then server disconnects.

You tried my method yet?