Advertisement
Pipeline

init.lua

Jun 24th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. AddCSLuaFile( "cl_init.lua" )
  2. AddCSLuaFile( "shared.lua" )
  3. include('shared.lua')
  4.  
  5. Keypad = {}
  6. Keypad.Passwords = {}
  7. Keypad.CurrentNum = {}
  8.  
  9. util.PrecacheSound("buttons/button14.wav")
  10. util.PrecacheSound("buttons/button9.wav")
  11. util.PrecacheSound("buttons/button11.wav")
  12. util.PrecacheSound("buttons/button15.wav")
  13.  
  14.  
  15. function ENT:Initialize()
  16. self.Entity:SetModel( "models/props_lab/keypad.mdl" )
  17. self.Entity:PhysicsInit( SOLID_VPHYSICS )
  18. self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
  19. self.Entity:SetSolid( SOLID_VPHYSICS )
  20.  
  21. local phys = self.Entity:GetPhysicsObject()
  22. if (phys:IsValid()) then
  23. phys:Wake()
  24. end
  25. end
  26.  
  27. function ENT:OnRemove()
  28. local Index = self.Entity:EntIndex()
  29.  
  30. for k,v in pairs(Keypad.Passwords) do
  31. if (Index == v.Ent) then
  32. table.remove(Keypad.Passwords, k)
  33. end
  34. end
  35. end
  36.  
  37. function ENT:OnRestore()
  38. table.insert(Keypad.Passwords, {Ent = self.Entity:EntIndex(), Pass = self.Entity.Pass})
  39. end
  40.  
  41. function ENT:AddPassword(Pass)
  42. self:OnRemove()
  43.  
  44. Pass = util.CRC(Pass)
  45.  
  46. self.Entity.Pass = Pass
  47. table.insert(Keypad.Passwords, {Ent = self.Entity:EntIndex(), Pass = Pass})
  48. end
  49.  
  50. local function CorrectPassword(Ent, Pass)
  51. Ent = tonumber(Ent)
  52. Pass = util.CRC(tonumber(Pass) or 0)
  53.  
  54. for k,v in pairs(Keypad.Passwords) do
  55. if (Ent == v.Ent) then
  56. if (Pass == v.Pass) then
  57. return true
  58. end
  59. end
  60. end
  61.  
  62. return false
  63. end
  64.  
  65. local function RunKeypad(Repeats, Length, Delay, Key, Owner)
  66. for i = 0, Repeats do
  67. timer.Simple(Length*(i)+Delay*i, function () Owner:ConCommand("+gm_special "..Key.."\n") end)
  68. timer.Simple(Length*(i+1)+Delay*i, function () Owner:ConCommand("-gm_special "..Key.."\n") end)
  69. end
  70.  
  71. end
  72.  
  73. local function KeypadCommand(Ply, Command, Args)
  74. if (Args == nil) then return end
  75.  
  76. local Ent = ents.GetByIndex(Args[1])
  77. local Show = Ent:GetNetworkedBool("keypad_showaccess")
  78. local Secure = Ent:GetNetworkedBool("keypad_secure")
  79.  
  80. if (Show) then return end
  81. if ((Ply:GetShootPos() - Ent:GetPos()):Length() > 50) then return end
  82.  
  83. if (Args[2] == "reset") then
  84. Ent:SetNetworkedInt("keypad_num", 0)
  85. Ent:EmitSound("buttons/button14.wav")
  86. Keypad.CurrentNum[Args[1]] = nil
  87. elseif (Args[2] == "accept") then
  88. local Num = Ent:GetNetworkedInt("keypad_num")
  89. local Owner = Ent:GetNetworkedEntity("keypad_owner")
  90. local Simple = Ent:GetNetworkedBool("keypad_simple")
  91. local Key
  92. local Length
  93. local Delay
  94. local InitDelay
  95. local Repeats
  96.  
  97. if (CorrectPassword(Args[1], Keypad.CurrentNum[Args[1]])) then
  98. Key = Ent:GetNetworkedInt("keypad_keygroup1")
  99. Length = Ent:GetNetworkedInt("keypad_length1")
  100. Delay = Ent:GetNetworkedInt("keypad_delay1")
  101. InitDelay = Ent:GetNetworkedInt("keypad_initdelay1")
  102. Repeats = Ent:GetNetworkedInt("keypad_repeats1")
  103. Ent:SetNetworkedBool("keypad_access", true)
  104. Ent:EmitSound("buttons/button9.wav")
  105. else
  106. Key = Ent:GetNetworkedInt("keypad_keygroup2")
  107. Length = Ent:GetNetworkedInt("keypad_length2")
  108. Delay = Ent:GetNetworkedInt("keypad_delay2")
  109. InitDelay = Ent:GetNetworkedInt("keypad_initdelay2")
  110. Repeats = Ent:GetNetworkedInt("keypad_repeats2")
  111. Ent:SetNetworkedBool("keypad_access", false)
  112. Ent:EmitSound("buttons/button11.wav")
  113. end
  114.  
  115.  
  116. if (Key != nil) and (Key != -1) then
  117. if (Simple) then
  118. Owner:ConCommand("+gm_special "..Key.."\n")
  119. timer.Simple(Length, function() Owner:ConCommand("-gm_special "..Key.."\n") end)
  120. else
  121. if (InitDelay != 0) then
  122. timer.Simple(InitDelay, function() RunKeypad(Repeats, Length, Delay, Key, Owner) end)
  123. else
  124. RunKeypad(Repeats, Length, Delay, Key, Owner)
  125. end
  126. end
  127. end
  128.  
  129. Ent:SetNetworkedBool("keypad_showaccess", true)
  130. timer.Simple(2,
  131. function()
  132. if (ValidEntity(Ent)) then
  133. Ent:SetNetworkedInt("keypad_num", 0)
  134. Ent:SetNetworkedBool("keypad_showaccess", false)
  135. end
  136.  
  137. Keypad.CurrentNum[Args[1]] = nil
  138. end)
  139. else
  140. -- local Num = Ent:GetNetworkedInt("keypad_num")*10 + Args[2]
  141. Keypad.CurrentNum[Args[1]] = Keypad.CurrentNum[Args[1]] or 0
  142. local Num = Keypad.CurrentNum[Args[1]] *10 + Args[2]
  143.  
  144. if (Num < 10000) then
  145. Keypad.CurrentNum[Args[1]] = Num
  146. print(Secure)
  147. if (Secure) then
  148. Ent:SetNetworkedInt("keypad_num", 10 ^ (string.len(Num)-1))
  149. else
  150. Ent:SetNetworkedInt("keypad_num", Num)
  151. end
  152. Ent:EmitSound("buttons/button15.wav")
  153. end
  154. end
  155. end
  156. concommand.Add("gmod_keypad", KeypadCommand)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement