Limiting tools based on DarkRP job AND ULX rank.

I tried looking all over the internet, found nothing.
I need something like this.
[lua] if ply.GetTeam() == “jobname” AND ply:IsUserGroup(“highrank”) then
– allow a tool to be used on EVERYONES props. Not just self.
end
[/lua]
Something like superadmin but based on job too.
Any idea?

I imagine you have to use this hook, Gamemode.CanTool.

Inside there you check the players job, the players rank, and depending on that return true or false.

If you only want to either allow everyone with a job and rank to toolgun all props then you just need to make table with the job name and rank name, are they connected?
Connected like
job1 and rank1
job2 and rank2
or
job1 and rank1 or rank2?

You can write everything like
[LUA]if ( ply:Team() == “” && ply:IsUserGroup( “admin” ) ) then[/LUA]
but if there’s more than one job or rank then you should use tables.

job1 and rank1 or rank2 or rank3
etc.
I can’t figure how to allow usage of the tool for players not in the job (on their own props) but allow usage of the tool on everyones prop if the job.
I got stuck here:
[lua]
hook.Add(“CanTool”, “JobCanTool”, function()
if ply:GetTeam() == “team_name” and ply:IsUserGroup(“rank1”) or ply:IsUserGroup(“rank2”) then
–what do I put here? I return false, it disables the tool I suppose?
end
end)
[/lua]

I think this will work but this hook will override other hooks, are you using darkrp?
[LUA]
allowed = { }
allowed [ “rank1” ] = { “job1”, “job2”, “job3” };
allowed [ “rank2” ] = { “job1” };

function useToolGun( ply, trace, tool )
local ent = trace.Entity;

if ( table.HasValue( allowed, ply:GetUserGroup() ) ) then
	if ( table.HasValue( allowed[ ply:GetUserGroup() ], team.GetName( ply:GetTeam() ) ) ) then
		return true;
	else
		return false;
	end
end

end

hook.Add( “CanTool”, “JobCanTool”, UseToolGun );
[/LUA]

this code will only allow toolgun to be used on anything IF the player is of a certain job and rank, this means they cant use it on their own stuff so are you using DarkRP?

Yeah I’m use it, sadly. Not able to write my own gamemode with my current lua capabilities/knowledge.

[LUA]
allowed = { }
allowed [ “rank1” ] = { “job1”, “job2”, “job3” };
allowed [ “rank2” ] = { “job1” };

function GM:CanTool( ply, trace, tool )

local ent = trace.Entity;

if ( !self.BaseClass:CanTool(ply, trace, mode) ) then 
	return false;
end

if ( IsValid( ent ) ) then
	if ( ent.onlyremover ) then
		if ( tool == "remover" ) then
			return ( ply:IsAdmin() or ply:IsSuperAdmin() );
		else
			return false;
		end
	end

	if ( ent.nodupe && ( tool == "weld" ||
				tool == "weld_ez" ||
				tool == "spawner" ||
				tool == "duplicator" ||
				tool == "adv_duplicator" ) ) 
	then
		return false;
	end

	if ( ent:IsVehicle() && tool == "nocollide" && !GAMEMODE.Config.allowvnocollide ) then
		return false;
	end

end

    if ( ply == ent:CPPIGetOwner() ) then
        return true;
    end

if ( table.HasValue( allowed, ply:GetUserGroup() ) ) then
	if ( table.HasValue( allowed[ ply:GetUserGroup() ], team.GetName( ply:GetTeam() ) ) ) then
		return true;
	else
		return false;
	end
end

end
[/LUA]

This allows players to use toolgun on their own entities even if they aren’t of the right job and rank.
I put the old DarkRP code there too, go into line 287 and replace everything between line 287 - 312 with that.

Thank you very much, I’ll try it out once I wake up. ( 4:23 AM )