Advertisement
Guest User

Untitled

a guest
Oct 18th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.96 KB | None | 0 0
  1. /*-------------------------------------------------------------------------------------------------------------------------
  2.     Restriction
  3. -------------------------------------------------------------------------------------------------------------------------*/
  4.  
  5. local PLUGIN = {}
  6. PLUGIN.Title = "Restriction"
  7. PLUGIN.Description = "Restricts weapons."
  8. PLUGIN.Author = "Overv"
  9.  
  10. function PLUGIN:PlayerSpawnSWEP( ply, name, tbl )
  11.     if ( GAMEMODE.Name == "Sandbox" and table.HasValue( evolve.privileges, "@" .. name ) and !ply:EV_HasPrivilege( "@" .. name ) ) then
  12.         evolve:Notify( ply, evolve.colors.red, "You are not allowed to spawn this weapon!" )
  13.         return false
  14.     end
  15. end
  16. function PLUGIN:PlayerGiveSWEP( ply, name, tbl )
  17.     if ( self:PlayerSpawnSWEP( ply, name, tbl ) == false ) then
  18.         return false
  19.     end
  20. end
  21.  
  22. function PLUGIN:PlayerSpawnSENT( ply, class )
  23.     if ( GAMEMODE.Name == "Sandbox" and table.HasValue( evolve.privileges, ":" .. class ) and !ply:EV_HasPrivilege( ":" .. class ) ) then
  24.         evolve:Notify( ply, evolve.colors.red, "You are not allowed to spawn this entity!" )
  25.         return false
  26.     end
  27. end
  28.  
  29. function PLUGIN:CanTool( ply, tr, class )
  30.     if ( GAMEMODE.Name == "Sandbox" and table.HasValue( evolve.privileges, "#" .. class ) and !ply:EV_HasPrivilege( "#" .. class ) ) then
  31.         evolve:Notify( ply, evolve.colors.red, "You are not allowed to use this tool!" )
  32.         return false
  33.     end
  34. end
  35.  
  36. function PLUGIN:PlayerSpawn( ply )
  37.     // Only block picking up when a player spawns, because we still want to make it possible to use !give and allow admins to drop weapons for players!
  38.     ply.EV_PickupTimeout = CurTime() + 0.5
  39. end
  40.  
  41. function PLUGIN:PlayerCanPickupWeapon( ply, wep )
  42.     if ( GAMEMODE.Name == "Sandbox" and table.HasValue( evolve.privileges, "@" .. wep:GetClass() ) and !ply:EV_HasPrivilege( "@" .. wep:GetClass() ) and ( !ply.EV_PickupTimeout or CurTime() < ply.EV_PickupTimeout ) ) then
  43.         return false
  44.     end
  45. end
  46.  
  47. function PLUGIN:Initialize()   
  48.     // Weapons
  49.     local weps = {}
  50.    
  51.     for _, wep in pairs( weapons.GetList() ) do
  52.         table.insert( weps, "@" .. wep.ClassName )
  53.     end
  54.    
  55.     table.Add( weps, {
  56.         "@weapon_crowbar",
  57.         "@weapon_pistol",
  58.         "@weapon_smg1",
  59.         "@weapon_frag",
  60.         "@weapon_physcannon",
  61.         "@weapon_crossbow",
  62.         "@weapon_shotgun",
  63.         "@weapon_357",
  64.         "@weapon_rpg",
  65.         "@weapon_ar2",
  66.         "@weapon_physgun",
  67.     } )
  68.    
  69.     table.Add( evolve.privileges, weps )
  70.    
  71.     // Entities
  72.     local entities = {}
  73.    
  74.     for class, ent in pairs( scripted_ents.GetList() ) do
  75.         if ( ent.t.Spawnable or ent.t.AdminSpawnable ) then
  76.             table.insert( entities, ":" .. ( ent.ClassName or class ) )
  77.         end
  78.     end
  79.    
  80.     table.Add( evolve.privileges, entities )
  81.    
  82.     // Tools
  83.     local tools = {}
  84.    
  85.     if ( GAMEMODE.Name == "Sandbox" ) then
  86.         for _, val in ipairs( file.FindInLua( "weapons/gmod_tool/stools/*.lua" )  ) do
  87.             local _, __, class = string.find( val, "([%w_]*)\.lua" )
  88.             table.insert( tools, "#" .. class )
  89.         end
  90.     end
  91.    
  92.     table.Add( evolve.privileges, tools )
  93.    
  94.     // If this is the first time the restriction plugin runs, add all weapon and entity privileges to all ranks so it doesn't break anything
  95.     if ( !evolve:GetGlobalVar( "RestrictionSetUp", false ) ) then      
  96.         for id, rank in pairs( evolve.ranks ) do
  97.             if ( id != "owner" ) then
  98.                 table.Add( rank.Privileges, weps )
  99.             end
  100.         end
  101.        
  102.         evolve:SetGlobalVar( "RestrictionSetUp", true )
  103.         evolve:SaveRanks()
  104.     end
  105.    
  106.     if ( !evolve:GetGlobalVar( "RestrictionSetUpEnts", false ) ) then      
  107.         for id, rank in pairs( evolve.ranks ) do
  108.             if ( id != "owner" ) then
  109.                 table.Add( rank.Privileges, entities )
  110.             end
  111.         end
  112.        
  113.         evolve:SetGlobalVar( "RestrictionSetUpEnts", true )
  114.         evolve:SaveRanks()
  115.     end
  116.    
  117.     if ( !evolve:GetGlobalVar( "RestrictionSetUpTools2", false ) ) then    
  118.         for id, rank in pairs( evolve.ranks ) do
  119.             if ( id != "owner" ) then
  120.                 table.Add( rank.Privileges, tools )
  121.             end
  122.         end
  123.        
  124.         evolve:SetGlobalVar( "RestrictionSetUpTools2", true )
  125.         evolve:SaveRanks()
  126.     end
  127. end
  128.  
  129. evolve:RegisterPlugin( PLUGIN )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement