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" ?
[CODE]
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,
})
[/CODE]
[code]
local function godadmins(ply)
if (ply:Team() == TEAM_ADMIN) then
ply:GodEnable()
end
end
hook.Add("PlayerSpawn", "enablegodadmin", godadmins)
[/code]
This is serverside.
You can probably figure out how to make it so that when [URL="http://wiki.darkrp.com/index.php/Hooks/shared/onplayerchangedteam"]they change their job[/URL] to and from Administrator it will give/revoke godmode.
PlayerSpawn = function(ply) ply:concommand("ulx", "god") end,
Try this, I didnt test it!
[CODE]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)[/CODE]
Or with ulx
[CODE]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)[/CODE]
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
[QUOTE=Chickengbs;46026482]So could you give me an example of what file I can place this into? :L[/QUOTE]
Server side I believe.
Edit: AKA lua/autorun/server
[QUOTE=Lolcats;46019978][code]
local function godadmins(ply)
if (ply:Team() == TEAM_ADMIN) then
ply:GodEnable()
end
end
hook.Add("PlayerSpawn", "enablegodadmin", godadmins)
[/code]
This is serverside.
You can probably figure out how to make it so that when [URL="http://wiki.darkrp.com/index.php/Hooks/shared/onplayerchangedteam"]they change their job[/URL] to and from Administrator it will give/revoke godmode.[/QUOTE]
Thanks, but it makes no difference, with no errors.
I'd say do something like this:[code]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[/code]
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:
[code]//
// 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 );[/code]
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]
[QUOTE=Acecool;46033614]I'd say do something like this:[code]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[/code]
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:
[code]//
// 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 );[/code]
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.[/QUOTE]
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?
Sorry, you need to Log In to post a reply to this thread.