Advertisement
Guest User

Untitled

a guest
May 30th, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.62 KB | None | 0 0
  1. if (SERVER) then
  2.     AddCSLuaFile("shared.lua")
  3. end
  4.  
  5. if (CLIENT) then
  6.     SWEP.PrintName = "ATM Cracker"
  7.     SWEP.Slot = 4
  8.     SWEP.SlotPos = 1
  9.     SWEP.DrawAmmo = false
  10.     SWEP.DrawCrosshair = true
  11. end
  12.  
  13. -- Variables that are used on both client and server
  14.  
  15. SWEP.Author = "DoritosMan"
  16. SWEP.Instructions = "Left click to break into an ATM"
  17. SWEP.Contact = ""
  18. SWEP.Purpose = ""
  19.  
  20. SWEP.ViewModelFOV = 62
  21. SWEP.ViewModelFlip = false
  22. SWEP.ViewModel = Model("models/weapons/v_c4.mdl")
  23. SWEP.WorldModel = Model("models/weapons/w_c4.mdl")
  24.  
  25. SWEP.Spawnable = false
  26. SWEP.AdminSpawnable = true
  27.  
  28. SWEP.Sound = Sound("weapons/deagle/deagle-1.wav")
  29.  
  30. SWEP.Primary.ClipSize = -1      -- Size of a clip
  31. SWEP.Primary.DefaultClip = 0        -- Default number of bullets in a clip
  32. SWEP.Primary.Automatic = false      -- Automatic/Semi Auto
  33. SWEP.Primary.Ammo = ""
  34.  
  35. SWEP.Secondary.ClipSize = -1        -- Size of a clip
  36. SWEP.Secondary.DefaultClip = -1     -- Default number of bullets in a clip
  37. SWEP.Secondary.Automatic = false        -- Automatic/Semi Auto
  38. SWEP.Secondary.Ammo = ""
  39. SWEP.KeyCrackTime = 45
  40.  
  41.  
  42. /*---------------------------------------------------------
  43. Name: SWEP:Initialize()
  44. Desc: Called when the weapon is first loaded
  45. ---------------------------------------------------------*/
  46. function SWEP:Initialize()
  47.     if (SERVER) then
  48.         self:SetWeaponHoldType("normal")
  49.         self.CanCrack = true
  50.     end
  51. end
  52.  
  53.  
  54. /*---------------------------------------------------------
  55. Name: SWEP:PrimaryAttack()
  56. Desc: +attack1 has been pressed
  57. ---------------------------------------------------------*/
  58.  
  59. function SWEP:PrimaryAttack()
  60.     self.Weapon:SetNextPrimaryFire(CurTime() + .4)
  61.     if self.Weapon.IsCracking then return end
  62.     local trace = self.Owner:GetEyeTrace()
  63.     local e = trace.Entity
  64.     if ValidEntity(e) and trace.HitPos:Distance(self.Owner:GetShootPos()) <= 300 and (e:GetClass() == "prop_atm") then
  65.         if not self.CanCrack then
  66.             self.Owner:ChatPrint( "You must wait 3 minutes inbetween cracking ATM's!")
  67.             return
  68.         end
  69.         self.Weapon.IsCracking = true
  70.         self.StartCrack = CurTime()
  71.         self.EndCrack   = CurTime() + self.KeyCrackTime
  72.         if SERVER then
  73.             self:SetWeaponHoldType("pistol")
  74.             timer.Create("KeyCrackSounds", 1, self.KeyCrackTime, function(wep)
  75.                 wep:EmitSound("buttons/blip2.wav", 100, 100)
  76.             end, self)
  77.         end
  78.         if CLIENT then
  79.             self.Dots = self.Dots or ""
  80.             timer.Create("KeyCrackDots", 0.5, 0, function(wep)
  81.                 if not wep:IsValid() then timer.Destroy("KeyCrackDots") return end
  82.                 local len = string.len(wep.Dots)
  83.                 local dots = {[0]=".", [1]="..", [2]="...", [3]=""}
  84.                 wep.Dots = dots[len]
  85.             end, self)
  86.         end
  87.     end
  88. end
  89.  
  90. function SWEP:Holster()
  91.     self.Weapon.IsCracking = false
  92.     if SERVER then timer.Destroy("KeyCrackSounds") end
  93.     if CLIENT then timer.Destroy("KeyCrackDots") end
  94.     return true
  95. end
  96.  
  97. function SWEP:Succeed()
  98.     self.Weapon.IsCracking = false
  99.     local trace = self.Owner:GetEyeTrace()
  100.     if ValidEntity(trace.Entity) and trace.Entity:GetClass() == "prop_atm" then
  101.         local amountStolen = math.random(250, 2500)
  102.             if SERVER then
  103.                 self.Owner:AddMoney( amountStolen )
  104.                 self.Owner:ChatPrint( "You stole a total of $" .. amountStolen .. ".")
  105.                 self.CanCrack = false
  106.                 timer.Simple(180, function()
  107.                     self.CanCrack = true
  108.                 end)
  109.             end
  110.     end
  111.     if SERVER then timer.Destroy("KeyCrackSounds") end
  112.     if CLIENT then timer.Destroy("KeyCrackDots") end
  113. end
  114.  
  115. function SWEP:Fail()
  116.     self.Weapon.IsCracking  = false
  117.     if SERVER then self:SetWeaponHoldType("normal")
  118.     timer.Destroy("KeyCrackSounds") end
  119.     if CLIENT then timer.Destroy("KeyCrackDots") end
  120. end
  121.  
  122. function SWEP:Think()
  123.     if self.Weapon.IsCracking then
  124.         local trace = self.Owner:GetEyeTrace()
  125.         if not ValidEntity(trace.Entity) then
  126.             self:Fail()
  127.         end
  128.         if trace.HitPos:Distance(self.Owner:GetShootPos()) > 300 or (trace.Entity:GetClass() != "prop_atm") then
  129.             self:Fail()
  130.         end
  131.         if self.EndCrack <= CurTime() then
  132.             self:Succeed()
  133.         end
  134.     end
  135. end
  136.  
  137. function SWEP:DrawHUD()
  138.     if self.Weapon.IsCracking then
  139.         self.Dots = self.Dots or ""
  140.         local w = ScrW()
  141.         local h = ScrH()
  142.         local x,y,width,height = w/2-w/10, h/ 2, w/5, h/15
  143.         draw.RoundedBox(8, x, y, width, height, Color(10,10,10,120))
  144.        
  145.         local time = self.EndCrack - self.StartCrack
  146.         local curtime = CurTime() - self.StartCrack
  147.         local status = curtime/time
  148.         local BarWidth = status * (width - 16) + 8
  149.         draw.RoundedBox(8, x+8, y+8, BarWidth, height - 16, Color(255-(status*255), 0+(status*255), 0, 255))
  150.        
  151.         draw.SimpleText("Cracking"..self.Dots, "Trebuchet24", w/2, h/2 + height/2, Color(255,255,255,255), 1, 1)
  152.     end
  153. end
  154.  
  155. function SWEP:SecondaryAttack()
  156.     self:PrimaryAttack()
  157. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement