BananeMan

sv_init

Jul 7th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.13 KB | None | 0 0
  1. function omgcleanupomg()
  2.     cleanup.CC_AdminCleanup()
  3.     LoadMapKCS()
  4. end
  5.  
  6. function LoadMapKCS()
  7.    
  8.     MsgN( "Chargement de la configuration de la map..." )
  9.  
  10.     local read = file.Read( string.lower( KCS.SavePath ) .. "/" .. string.lower( game.GetMap() ) .. "_json.txt", "DATA" )
  11.    
  12.     if not read then
  13.    
  14.         MsgN( "Aucune configuration de map trouver" .. game.GetMap() .. "." )
  15.        
  16.         return
  17.    
  18.     end
  19.    
  20.     local config = util.JSONToTable( read )
  21.    
  22.     MsgN( "Chargement de la configuration de la map avec succés" )
  23.    
  24.     for k,v in pairs( config ) do
  25.    
  26.         if v[1] then
  27.            
  28.                 for c,d in pairs( ents.FindByClass( k ) ) do
  29.                    
  30.                     d:Remove()
  31.                    
  32.                 end
  33.  
  34.                 for c,d in pairs( v ) do
  35.                
  36.                     if k == "keycard_register" then
  37.                         local id = d[1]
  38.                         local level = d[2]
  39.                         for _, ent in pairs( ents.GetAll() ) do
  40.                             if ent:EntIndex() == id then
  41.                                 ent.Restricted = true
  42.                                 ent.Level = level
  43.                             end
  44.                         end
  45.                     end
  46.                 end
  47.         end
  48.        
  49.     end
  50.  
  51. end
  52.  
  53. hook.Add( "InitPostEntity", "LoadTheStops", LoadMapKCS )
  54.  
  55. function SaveMapKCS()
  56.  
  57.     if not file.Exists( KCS.SavePath, "DATA" ) then file.CreateDir( KCS.SavePath ) end
  58.     MsgN( "Sauvegarde de la configuration DATA de vos cartes" )
  59.  
  60.     local enttbl = {
  61.         keycard_register = {}
  62.     }
  63.    
  64.     for k,v in pairs( enttbl ) do
  65.         for c,d in pairs( ents.GetAll() ) do
  66.             if d.Restricted then
  67.                 table.insert( enttbl[k], { d:EntIndex(), d.Level } )
  68.             end
  69.         end    
  70.     end
  71.        
  72.    
  73.     file.Write( string.lower( KCS.SavePath ) .. "/" .. string.lower( game.GetMap() ) .. "_json.txt", util.TableToJSON( enttbl ) )
  74.  
  75. end
  76.  
  77. function SaveKCS( ply, cmd, args )
  78.  
  79.     if ( !ply:IsAdmin() or !ply:IsSuperAdmin() ) then return end
  80.    
  81.     ply:StripWeapon( "admin_multitool" )
  82.     SaveMapKCS()
  83.    
  84. end
  85.  
  86. concommand.Add( "kcs_end", SaveKCS )
  87.  
  88. function KCSSetupMode( ply, cmd, args )
  89.  
  90.     if not IsValid( ply ) then
  91.    
  92.         for k, ply in pairs( player.GetAll() ) do
  93.        
  94.             if ply:IsAdmin() or ply:IsSuperAdmin() then
  95.    
  96.                 ply:Give( "admin_multitool" )
  97.            
  98.             end
  99.        
  100.         end
  101.        
  102.         return
  103.        
  104.     end
  105.  
  106.     if ply:IsAdmin() or ply:IsSuperAdmin() then
  107.    
  108.         ply:Give( "admin_multitool" )
  109.    
  110.     end
  111.  
  112. end
  113.  
  114. concommand.Add( "kcs_start", KCSSetupMode )
  115.  
  116. hook.Add( "InitPostEntity", "jesusfuckingchrist", function()
  117.     timer.Simple( 10, function()
  118.         hook.Add( "PlayerUse", "CheckThePrivlege", function( ply, ent )
  119.             if not ent.Restricted then return end
  120.             local weapon = ply:GetActiveWeapon()
  121.             if not IsValid( weapon ) then return false end
  122.  
  123.             if not weapon:GetClass():find( "keycard" ) then return false end
  124.  
  125.             local level = ent.Level
  126.             local access = weapon.Level
  127.  
  128.             if level <= access then return true end
  129.  
  130.             ent:EmitSound( "buttons/combine_button_locked.wav", 100, math.random(90,100) )
  131.             return false
  132.         end )
  133.     end )
  134. end )
  135.  
  136. hook.Add( "PlayerInitialSpawn", "NetworkTheButtons", function( ply )
  137.     timer.Simple( 5, function()
  138.         local butts = {}
  139.         for _,butt in pairs( ents.GetAll() ) do
  140.             if butt.Restricted then
  141.                 butts[ butt:EntIndex() ] = butt.Level
  142.             end
  143.         end
  144.         net.Start( "SyncButtons" )
  145.             net.WriteTable( butts )
  146.         net.Send( ply )
  147.     end )
  148. end )
  149.    
  150. concommand.Add( "reset", omgcleanupomg )
Advertisement
Add Comment
Please, Sign In to add comment