General > Developers Corner

stool and weapon restriction

<< < (3/4) > >>

MrPresident:
Nice! This is good to know actually, i was always wondering if when I reloaded a script without restarting my server if the function was hooking more than once. I guess now I know! =)

saintmark:
Great info and help guys THANKS!!! ;D

I have good news too.... my server was empty so I had a chance to test it out -IT WORKED!!!!!!
I am soooooo very happy. I am proud of my little code. The only thing I cant figure out is why it double prints the HUD_PRINTTALK

my code ver1.2


--- Code: ---function UseTool_admin( ply, tr, toolmode )
if toolmode == "rt_antinoclip" or toolmode == "light" or toolmode == "lamp" or toolmode == "ignite"  // put the FILE NAME of the tool
or toolmode == "rtcamera" or toolmode == "trails" or toolmode == "wire_light" or toolmode == "wire_lamp" then 
if ( ply:IsAdmin() or ply:IsSuperAdmin()  ) then
return
else
ply:PrintMessage( HUD_PRINTTALK, "This tool is restricted to Admins" )
return false
end
end
end
hook.Add( "CanTool", "UseTool_admin_Hook", UseTool_admin )

function UseTool_vip( ply, tr, toolmode )
if toolmode == "balloon" or toolmode == "smartwelder" or toolmode == "wire_igniter" or toolmode == "emitter" then // put the FILE NAME of the tool
if ( ply:IsAdmin() or ply:IsSuperAdmin() or ply:IsUserGroup("moderator") or ply:IsUserGroup("vip") ) then
return
else
ply:PrintMessage( HUD_PRINTTALK, "This tool is restricted to Admins, Moderators, and VIPs." )
return false
end
end
end
hook.Add( "CanTool", "UseTool_vip_Hook", UseTool_vip )

function UseTool_respected( ply, tr, toolmode )
if toolmode == "ol_stacker" or toolmode == "turret" or toolmode == "dynamite" or toolmode == "wire_turret" or toolmode == "wire_explosive" then // put the FILE NAME of the tool
if ( ply:IsAdmin() or ply:IsSuperAdmin() or ply:IsUserGroup("moderator") or ply:IsUserGroup("vip") or ply:IsUserGroup("respected") ) then
return
else
ply:PrintMessage( HUD_PRINTTALK, "This tool is restricted to Respected Players and above." )
return false
end
end
end
hook.Add( "CanTool", "UseTool_respected_Hook", UseTool_respected )

--- End code ---

Also nobody posted if I could write my codes like in ex A. I think it looks cleaner and it would be easy for someone to modify.

jay209015:
Since you wanted an easier configuration of the tools, I put them into three tables. Not test, but I think it should work.


--- Code: ---// List of admin only tools
Admin_Tools = { "rt_antinoclip", "light", "lamp", "ignite", "rtcamera", "trails", "wire_light", "wire_lamp" }
// List of V.I.P. tools
VIP_Tools = { "balloon", "smartwelder", "wire_igniter", "emitter" }
// List of Respected tools
Respected_Tools = { "ol_stacker", "turret", "dynamite", "wire_turret", "wire_explosive" }

//========================================END OF CONFIGURATION===========================================//



function UseTool_admin( ply, tr, toolmode )
for _, toolA in pairs(Admin_Tools) do // Loops through the Admin_Tools table
if toolmode == toolA then // Checks to see if the toolmode equals any of the tools in that table
if ply:IsAdmin() or ply:IsSuperAdmin() then // checks to see if they are in the selected groups or not
return // If they are then allow the use of the tool
else
ply:PrintMessage( HUD_PRINTTALK, "This tool is restricted to Admins" ) // If not admin then prints the message "This tool is restricted to Admins"
return false // And disallows the use of the tool for that player
end
end
end
end
hook.Add( "CanTool", "UseTool_admin_Hook", UseTool_admin )

function UseTool_vip( ply, tr, toolmode )
for _, toolV in pairs(VIP_Tools) do // Loops through the VIP_Tools table
if toolmode == toolV then // Checks to see if the toolmode equals any of the tools in that table
if ply:IsAdmin() or ply:IsSuperAdmin() or ply:IsUserGroup("moderator") or ply:IsUserGroup("vip") then // checks to see if they are in the selected groups or not
return // If they are then allow the use of the tool
else
ply:PrintMessage( HUD_PRINTTALK, "This tool is restricted to Admins" ) // If not then prints the message "This tool is restricted to Admins, Moderators, and VIPs."
return false // And disallows the use of the tool for that player
end
end
end
end
hook.Add( "CanTool", "UseTool_vip_Hook", UseTool_vip )

function UseTool_respected( ply, tr, toolmode )
for _, toolR in pairs(Respected_Tools) do // Loops through the VIP_Tools table
if toolmode == toolR then // Checks to see if the toolmode equals any of the tools in that table
if ply:IsAdmin() or ply:IsSuperAdmin() or ply:IsUserGroup("moderator") or ply:IsUserGroup("vip") or ply:IsUserGroup("respected") then // checks to see if they are in the selected groups or not
return // If they are then allow the use of the tool
else
ply:PrintMessage( HUD_PRINTTALK, "This tool is restricted to Respected Players and above" ) // If not then prints the message "This tool is restricted to Respected Players and above"
return false // And disallows the use of the tool for that player
end
end
end
end
hook.Add( "CanTool", "UseTool_vip_Hook", UseTool_vip )
--- End code ---

saintmark:
Wow Jay That looks great and easy to mod... You went above the call of duty!

Your code looks better than mine.

my code ver 1.3


--- Code: ---   // This code was written by Saint Mark - with the assistance from the lua kings of www.ulyssesmod.net
  // You can have as many UseTool_group's as you want (Copy and Paste down below)--
 // --Just make sure you change the function UseTool_groupA to another letter -
//-Also make sure you change it in the -hook.Add( "CanTool", "UseTool_groupA_Hook", UseTool_groupA ) -


function UseTool_groupA( ply, tr, toolmode )    //This is the first line of groupA 
if toolmode == "rt_antinoclip"           //place the FILE NAME of the tool inside the quotes
or toolmode == "light"                  // You may add or delete these too
or toolmode == "lamp"
or toolmode == "ignite"       
or toolmode == "rtcamera"
or toolmode == "trails"
or toolmode == "wire_light"
or toolmode == "wire_lamp"
then 
if ( ply:IsAdmin()
or ply:IsSuperAdmin() 
) then
return
else
ply:PrintMessage( HUD_PRINTTALK, "This tool is restricted to Admins" ) //you can change the text that will be printed on the screen
return false
end
end
end
hook.Add( "CanTool", "UseTool_groupA_Hook", UseTool_groupA ) //This is the last line of GroupA

function UseTool_groupB( ply, tr, toolmode )
if toolmode == "balloon"
or toolmode == "smartwelder"
or toolmode == "wire_igniter"
or toolmode == "emitter"
then
if ( ply:IsAdmin()
or ply:IsSuperAdmin()
or ply:IsUserGroup("moderator")
or ply:IsUserGroup("vip")
) then
return
else
ply:PrintMessage( HUD_PRINTTALK, "This tool is restricted to Admins, Moderators, and VIPs." )
return false
end
end
end
hook.Add( "CanTool", "UseTool_groupB_Hook", UseTool_groupB )

function UseTool_groupC( ply, tr, toolmode )
if toolmode == "ol_stacker"
or toolmode == "turret"
or toolmode == "dynamite"
or toolmode == "wire_turret"
or toolmode == "wire_explosive"
then
if ( ply:IsAdmin()
or ply:IsSuperAdmin()
or ply:IsUserGroup("moderator")
or ply:IsUserGroup("vip")
or ply:IsUserGroup("respected")
) then
return
else
ply:PrintMessage( HUD_PRINTTALK, "This tool is restricted to Respected Players and above." )
return false
end
end
end
hook.Add( "CanTool", "UseTool_groupC_Hook", UseTool_groupC )

--- End code ---

jay209015:
Thanks, either way you want to run this script works :D

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version