I need help on a class ;-;

So, I have stared at the almost infinite lines of coding for wiremod, and have watched countless videos, seen endless threads, I just can’t find an answer. So in wire mod, I would like to restrict all tools EXCEPT the “text screen” tool to one class, my Engineer class. I would also like to completely restrict the “sound emitters” tool from every class. I just can’t find any help anywhere, so i’m hoping you can help me. The top code for my class (So you can see the names) is:



TEAM_ENGINEER = DarkRP.createJob("Engineer", {


Forgive me if I put this in the wrong section

Why do you want to use Wiremod for this??

DarkRP’s admin system (FAdmin) has a build in tool restriction system. I use that for restricting certain wiremod tools for different usergroups. You could probably re-work this system easily to work with jobs instead of usergroups.

  • if that’s your kind of thing…


hook.Add( "CanTool", "somehookname", function( _p, tr, tool )

    if( _p:Team() == TEAM_ENGINEER && tool != "textscreen" ) then
        return false;
    end

end );


So I took into consideration about you saying there was an Fadmin tool already. I used it to restrict everything but the textscreen, and create a new group in the tool called “engineer”. The tool i used was under Utilities/Falco’s Prop Protection/Admin Settings/Tool Restrictions… it is by SteamID for the groups, but is there any way to make it so if you are the engineer class, you are put in the group until you leave that class. Like “if (ply:team() == TEAM_ENGINEER) then group “engineer” return true” I’m not goof at creating functions or tables, or how to call that group to that command in general.

¨

If you take the code in the comment above yours, and put in a file, for example:
garrysmod/lua/autorun/server/blabla.lua
it should work as you want: only textscreen tool for TEAM_ENGINEER.

I don’t want the text screen only for the engineer I want the text screen to be the only thing that anyone can use. The engineer however has access to all of the wiremod tools.

Use FPP? Group tool restriction or team restrictions…

Then



local BannedTools = { -- You might find that you need to ban other tools, eg Grabber etc.
	"soundemitter",
}

local AllowedTeams = { -- You might add more classes, or allow the Admin On Duty ( if you have one ) class to use the tools
	TEAM_ENGINEER,
}
local AllTools = { -- You will probably want to add the tool names of the Gmod Tools, eg Colour etc.
       "textscreen",
}
hook.Add( "CanTool", "wiredeny", function( p, tr, tool )
	if( table.HasValue(AllTools, tool) ) then -- If the tool's name is in the AllTools table
		return true -- Then allow it
	elseif( table.HasValue(BannedTools, tool) )then -- If the tool's name is in the BannedTools table
		return false -- Then deny it.
	elseif( table.HasValue(AllowedTeams, p:Team()) )then
		return true -- If the player's team is in the AllowedTeams table, and the two if statements above have not returned, allow it.
	end
end)


More configurable version, adapted from Busan1’s version.

I’d recommend putting this in a directory as such, so you can find it easily, and do not loose it if you move servers:

“addons/darkrpmodification/lua/darkrp_modules/wiredeny/sh_wiredeny.lua”

Why not take it one step further and optimize it?.. I went a little bit further:

https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/simple_banned_tool_system/sv_simple_banned_tool_system.lua.html - remove .html to view .lua

Thanks Acecool! It worked and its great for further configuration! I need to learn from you cause wow.

So, it was working, but now after a server restart all the tools are unable to be used

Your script is probably loaded after TEAM_ has been set up

how do I make it load before?

try with:



hook.Add( "loadCustomDarkRPItems", "blablaname", BuildCanToolData );


Updated the code so it uses OnReloaded instead of using concommand… I also added a few checks ( such as checking that EACH team is valid that is added, with the builder function able to set a var to bypass the hook if there is an issue ) so if there is an issue it’ll try rebuilding the list if CanTool is called prior to TEAM_ creation… I also added a console output so if the server logs output something, you may want to double-check the tables… I left the console command for users that don’t have Auto-Refresh or for those that prefer a custom, faster, implementation…

As long as everything is defined in that local function, it should build that list after the teams are initialized ( you don’t want to do it before, otherwise the list will be full of [ nil ] = { }; )…

I do tutor and I’ve written over 500 tutorials and ready-to-use snippets / systems; Feel free to add me on Steam.

Also, you will want this script to load AFTER TEAM_ is created otherwise TEAM_* will be nil and the table will have 1 entry ( if nil can be used as a valid index )… So you won’t want it to load before TEAM_* is created… You will, however, want it to work properly so try adding print statements to see where it is hanging up… Also, all group-names should be lower-case. Any groups with a space should be added using [ “xxx xxx” ] = …; in the table… otherwise a simple-string can be used without using [ “” ]s…

I could add a simple snippet of code that would verify that the entire script loads and if it doesn’t it could output an error message( a simple timer.Create at the top and timer.Remove at the bottom so on error the timer.Remove is never called ) but it’d be easier to simply check for error messages in your console.log.

So, the thing is it isn’t saying there are any errors. See if you can find out if I did something wrong.




//
// - Josh 'Acecool' Moser
// http://forum.facepunch.com/showthread.php?t=1462025
//


//
//
//
banned_tool_system = banned_tool_system || { };


//
//
//
local function BuildCanToolData( )
    // These are the tools which are banned...
    banned_tool_system.tools = {
        soundemitter = true;
		addressbud = true;
		adv_emarker = true;
		adv_input = true;
		button = true;
		cameracontroller = true;
		cd_disk = true;
		cd_lock = true;
		cd_ray = true;
		clutch = true;
		colorer = true;
		cpu = true;
		data_satellitedish = true;
		data_store = true;
		data_transfer = true;
		dataplug = true;
		dataport = true;
		datarate = true;
		datasocket = true;
		detonator = true;
		dhdd = true;
		dual_input = true;
		dynamic_button = true;
		egp_emitter = true;
		emarker = true;
		exit_point = true;
		explosive = true;
		extbus = true;
		eyepod = true;
		forcer = true;
		freezer = true;
		fx_emitter = true;
		gate = true;
		gimbal = true;
		gps = true;
		gpulib = true;
		grabber = true;
		graphics_tablet = true;
		gyroscopes = true;
		hdd = true;
		holoemitter = true;
		hologram = true;
		hologrid = true;
		hoverball = true;
		hydraulic = true;
		igniter = true;
		indicator = true;
		input = true;
		keypad = false;
		lamp = true;
		las_receiver = true;
		latch = true;
		lever = true;
		light = true;
		locator = true;
		motor = true;
		nailer = true;
		numpad = true;
		oscilloscope = true;
		output = true;
		pixel = true;
		plug = true;
		pod = true;
		radio = true;
		ranger = true;
		relay = true;
		screen = true;
		sensor = true;
		simple_explosives = true;
		socket = true;
		spawner = true;
		speedometer = true;
		target_finder = true;
		teleporter = true;
		textentry = true;
		textreciever = true;
		textscreen = false;
		thruster = true;
		trail = true;
		trigger = true;
		trigger_entity = true;
		turret = true;
		twoway_radio = true;
		user = true;
		value = true;
		vectorthruster = true;
		vehicle = true;
		watersensor = true;
		waypoint = true;
		weight = true;
		wheel = true;
		-- main tools--
		ballsocket = true;
		editentity = true;
		elastic = true;
		muscle = true;
		pulley = true;
		rope = true;
		slider = true;
		winch = true;
		duplicator = true;
		dynamite = true;
		emitter = true;
		physprop = true;
		eyeposer = true;
		faceposer = true;
		finger = true;
		inflator = true;
		wheel = true;
		thruster = true;
		hoverball = true;
		paint = true;
		trails = true;
		
		
		
    };

    // Global bypass
    banned_tool_system.group_overrides = {
        superadmin  = true;

        // Not needed, but....
        user        = false;
    };

    // Team bypass - each team needs to specify the allowed tools...
    banned_tool_system.team_overrides = {
        // Let engineers use sound-emitters... NOTE: If used in ADDON this script must be encased in
        // a hook -- we use brackets here because we want the text to be processed as a variable...
        [ TEAM_ENGINEER ] = {
				addressbud = true;
				adv_emarker = true;
				adv_input = true;
				button = true;
				cameracontroller = true;
				cpu = true;
				data_satellitedish = true;
				data_store = true;
				data_transfer = true;
				dataplug = true;
				dataport = true;
				datarate = true;
				datasocket = true;
				dhdd = true;
				dual_input = true;
				egp_emitter = true;
				exit_point = true;
				extbus = true;
				gate = true;
				gimbal = true;
				gps = true;
				gpulib = true;
				graphics_tablet = true;
				hdd = true;
				hoverball = true;
				hydraulic = true;
				indicator = true;
				input = true;
				keypad = true;
				lever = true;				
				locator = true;
				numpad = true;
				output = true;
				pod = true;
				ranger = true;
				relay = true;
				screen = true;
				sensor = true;
				target_finder = true;
				textentry = true;
				textreciever = true;
				textscreen = true;
				thruster = true;
				value = true;
				vehicle = true;


        };

        // If you want to allow all tools based on team, simply set the value to true instead of as a table...
        [ TEAM_ADMIN ] = false;
    };

    // Helper var...
    banned_tool_system.__initialized = true;
end


//
// Our hook...
//
hook.Add( "CanTool", "OptimizedBannedTools", function( _p, _trace, _tool )
    // No sense in protecting against RCON so let another hook deal with it...
    if ( !IsValid( _p ) ) then return; end

    // First time someone executes this command, we call our local builder func ( so teams can initialize before building )
    if ( !banned_tool_system.__initialized ) then
        BuildCanToolData( );
    end

    // Reconfigure vars...
    local _tool = string.lower( _tool );

    // If a banned tool is selected
    if ( banned_tool_system.tools[ _tool ] ) then
        // Check to see if the user has bypass permissions
        local _group = string.lower( _p:GetNWString( "UserGroup" ) || "guest" );
        if ( banned_tool_system.group_overrides[ _group ] ) then return true; end

        // Now, check to see if the user is on a team which can use the tool... Allow a table of tools or a simple true...
        local _team = _p:Team( ) || TEAM_UNASSIGNED;
        local _team_data = banned_tool_system.team_overrides[ _team ];
        if ( ( isbool( _team_data ) && _team_data == true ) || ( istable( _team_data ) && _team_data[ _tool ] ) ) then return true; end

        // In hooks, we avoid targeting generic behavior; here we are returning false if the user doesn't
        // have over-ride permissions to a banned tool...
        return false;
    end

    // And no return is used here...
end );


//
// So auto-refresh can be used... a console command to update the list...
//
concommand.Add( "dev_banned_tools", function( _p, _cmd, _args )
    if ( !IsValid( _p ) || _p:IsAdmin( ) || _p:IsSuperAdmin( ) ) then
        print( "Rebuilding banned tools list..." );
        BuildCanToolData( );
    end
end );


I updated your version to the latest version and tabbed the data in-line to look nicer ( tab set to “use” 4 spaces as width so it may not look right in your browser )… I too didn’t see any errors after running it except TEAM_ENGINEER is nil index but no errors after changing it to a valid team…

https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/simple_banned_tool_system/sv_simple_banned_tool_system_withdata.lua

There should be no reason for it to not be working unless something else is using the hook and returning true or false before this hook gets the chance to run…

Use: lua_run PrintTable( hook.GetTable( ).CanTool ); in your server console…

If some output then run: lua_run PrintTable( debug.getinfo( hook.GetTable( ).CanToo.OptimizedBannedTools ) ); for each name, replacing OptimizedBannedTools with the name that shows up ( or removing . and using [ “OptimizedBannedTools” ] if there is a space / non-simple string…

By not working do you mean all tools are banned? If so, true means the tool will be banned… With how it is set up, Engineer gets to use a few tools while superadmin group’d users get to use any banned tool…

I added a new CVar: sv_devmode… set it to 1 for it to print data to console each time CanTool is executed… I added a lot of print statements ( under debug.print so they can be easily disabled by the convar ) so I wouldn’t recommend keeping it set to 1 once we find and resolve the issue… But, hopefully this version has all necessary checks in place…