Advertisement
Guest User

init.lua

a guest
Aug 27th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. AddCSLuaFile "cl_init.lua"
  2. AddCSLuaFile "shared.lua"
  3. include "shared.lua"
  4.  
  5. util.AddNetworkString( "netKCSMenu" )
  6. util.AddNetworkString( "netKCSpawn" )
  7. util.AddNetworkString( "netKeycardHackSpawn" )
  8.  
  9. net.Receive( "netKCSpawn", function( len, ply )
  10. local ent = net.ReadEntity()
  11. if not IsValid( ply ) or not IsValid( ent ) then return end
  12. if ent:GetStatus() ~= ent.Status_None then return end
  13.  
  14. timer.Simple( 2, function()
  15. if not IsValid( ent ) or not IsValid( keycard ) then return end
  16. keycard:Remove()
  17. end )
  18.  
  19. ScanCard( ply, ent )
  20. end )
  21.  
  22. net.Receive( "netKeycardHackSpawn", function( len, ply )
  23. local ent = net.ReadEntity()
  24. if not IsValid( ply ) or not IsValid( ent ) then return end
  25. if ent:GetStatus() ~= ent.Status_None then return end
  26.  
  27. local keycard = ents.Create( "ent_keycardh" )
  28. keycard:SetPos( ent:LocalToWorld( Vector(-7.5, 0, -0.1) ) )
  29. keycard:SetAngles( ent:LocalToWorldAngles( Angle(0, 0, 0) ) )
  30. keycard:SetParent( ent )
  31. keycard:Spawn()
  32.  
  33. ply:StripWeapon( "weapon_keycardh" )
  34. ent:EmitSound( "buttons/button18.wav" )
  35. ent:SetStatus( ent.Status_Hacking )
  36.  
  37. timer.Create( "KS_Beep", 1, 0, function()
  38. if not IsValid( ent ) or not IsValid( keycard ) then
  39. if IsValid( ent ) then ent:SetStatus( ent.Status_None ) end
  40.  
  41. if IsValid( ply ) then
  42. ply:Give( "weapon_keycardh" )
  43. end
  44.  
  45. return
  46. end
  47.  
  48. ent:EmitSound( "buttons/button17.wav" )
  49. end )
  50.  
  51. timer.Create( "KS_Beep2", 1.5, 0, function()
  52. if not IsValid( ent ) or not IsValid( keycard ) then return end
  53.  
  54. ent:EmitSound( "buttons/button17.wav" )
  55. end )
  56.  
  57. timer.Simple( 60, function()
  58. if not IsValid( ent ) or not IsValid( keycard ) then return end
  59. ply:Give( "weapon_keycardh" )
  60.  
  61. timer.Destroy( "KS_Beep" )
  62. timer.Destroy( "KS_Beep2" )
  63.  
  64. ent:SetStatus( ent.Status_None )
  65. keycard:Remove()
  66.  
  67. ent:Access( true )
  68. end )
  69. end )
  70.  
  71. function ScanCard( ply, ent )
  72.  
  73. if not IsValid( ply ) or not IsValid( ent ) then return end
  74. if ent:GetStatus() ~= ent.Status_None then return end
  75. if ply:EyePos():Distance( ent:GetPos() ) >= 120 then return end
  76.  
  77. ply:StripWeapon( "weapon_keycard" )
  78. ent:EmitSound( "buttons/button14.wav" )
  79. ent:SetStatus( ent.Status_Scanning )
  80.  
  81. timer.Simple( 2, function()
  82. if not IsValid( ent ) then return end
  83. local AllowedUsers = ent.KCSData.AllowedUsers or {}
  84. if ply == ent.KCSData.Owner or table.HasValue( AllowedUsers, ply ) then ent:Access( true ) else ent:Access( false ) end
  85. end )
  86.  
  87. timer.Simple( 2, function() ply:Give( "weapon_keycard" ) end )
  88.  
  89. end
  90.  
  91. function ENT:Initialize()
  92.  
  93. self.Outputs = WireLib.CreateOutputs(self, {"Access Granted", "Access Denied"})
  94. self:SetModel( "models/card/keycard_scanner.mdl" )
  95. self:PhysicsInit( SOLID_VPHYSICS )
  96. self:SetMoveType( MOVETYPE_VPHYSICS )
  97. self:SetSolid( SOLID_VPHYSICS )
  98. self:SetUseType( SIMPLE_USE )
  99.  
  100. local phys = self:GetPhysicsObject()
  101. if phys:IsValid() then phys:Wake() end
  102. end
  103.  
  104. function ENT:Access( granted )
  105.  
  106.  
  107. local length, initdelay, delay, owner, key
  108.  
  109. if granted then
  110. self:SetStatus( self.Status_Granted )
  111.  
  112. length = self.KCSData.LengthGranted
  113. initdelay = self.KCSData.InitDelayGranted
  114. delay = self.KCSData.DelayGranted
  115. owner = self.KCSData.Owner
  116. key = tonumber( self.KCSData.KeyGranted ) or 0
  117. else
  118. self:SetStatus( self.Status_Denied )
  119.  
  120. length = self.KCSData.LengthDenied
  121. initdelay = self.KCSData.InitDelayDenied
  122. delay = self.KCSData.DelayDenied
  123. owner = self.KCSData.Owner
  124. key = tonumber( self.KCSData.KeyDenied ) or 0
  125. end
  126.  
  127. timer.Simple( math.max(initdelay + length + delay * 0.25, 2), function()
  128. if IsValid( self ) then
  129. self:Reset()
  130. end
  131. end )
  132.  
  133. timer.Simple(initdelay, function()
  134. if(IsValid(self)) then
  135. for i = 0, repeats do
  136. timer.Simple(length * i + delay * i, function()
  137. if(IsValid(self) and IsValid(owner)) then
  138. numpad.Activate(owner, key, true)
  139. end
  140. end)
  141.  
  142. timer.Simple(length * (i + 1) + delay * i, function()
  143. if(IsValid(self) and IsValid(owner)) then
  144. numpad.Deactivate(owner, key, true)
  145. end
  146. end)
  147. end
  148. end
  149. end)
  150.  
  151. if granted then
  152. self:EmitSound( "buttons/button9.wav" )
  153. WireLib.TriggerOutput(self,"Access Granted",accessGrantedValue)
  154. else
  155. self:EmitSound( "buttons/button11.wav" )
  156. WireLib.TriggerOutput(self,"Access Denied",accessDeniedValue)
  157. end
  158. end
  159.  
  160. function ENT:SetData( data )
  161. self.KCSData = data
  162.  
  163. self:Reset()
  164. end
  165.  
  166. function ENT:GetData()
  167. return self.KCSData
  168. end
  169.  
  170. function ENT:Reset()
  171. self:SetStatus( self.Status_None )
  172. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement