Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.99 KB | None | 0 0
  1. -- variables
  2. placed = false
  3. position = 0
  4. angleb = 0
  5.  
  6. if SERVER then
  7.    AddCSLuaFile( "shared.lua" )
  8. end
  9.  
  10. SWEP.HoldType = "normal"
  11.  
  12. if CLIENT then
  13.    SWEP.PrintName           = "Spy Camera"
  14.    SWEP.Slot                = 7
  15.  
  16.    SWEP.ViewModelFOV = 10
  17.  
  18.    SWEP.EquipMenuData = {
  19.       type="Weapon + Active use item",
  20.       model="models/dav0r/camera.mdl",
  21.       desc=""
  22.    };
  23.  
  24.    SWEP.Icon = "VGUI/ttt/icon_radio"
  25. end
  26.  
  27. SWEP.Base = "weapon_tttbase"
  28.  
  29. SWEP.ViewModel          = "models/weapons/v_crowbar.mdl"
  30. SWEP.WorldModel         = "models/dav0r/camera.mdl"
  31. SWEP.DrawCrosshair      = true
  32. SWEP.ViewModelFlip      = false
  33. SWEP.Primary.ClipSize       = -1
  34. SWEP.Primary.DefaultClip    = -1
  35. SWEP.Primary.Automatic      = true
  36. SWEP.Primary.Ammo       = "none"
  37. SWEP.Primary.Delay = 1.0
  38.  
  39. SWEP.Secondary.ClipSize     = -1
  40. SWEP.Secondary.DefaultClip  = -1
  41. SWEP.Secondary.Automatic    = true
  42. SWEP.Secondary.Ammo     = "none"
  43. SWEP.Secondary.Delay = 1.0
  44.  
  45. SWEP.Kind = WEAPON_EQUIP2
  46. SWEP.CanBuy = {ROLE_TRAITOR}
  47. SWEP.LimitedStock = true
  48. SWEP.WeaponID = AMMO_CAMERA
  49.  
  50.  
  51. SWEP.AllowDrop = false
  52.  
  53. SWEP.NoSights = true
  54.  
  55. function SWEP:OnDrop()
  56.    self:Remove()
  57. end
  58.  
  59. function SWEP:PrimaryAttack()
  60.    self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  61.    self:CameraStick()
  62. end
  63. function SWEP:SecondaryAttack()
  64.    self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay )
  65.    self:CameraStick()
  66. end
  67.  
  68. local throwsound = Sound( "Weapon_SLAM.SatchelThrow" )
  69.  
  70. function SWEP:CameraStick()
  71.    if SERVER then
  72.       local ply = self.Owner
  73.       if not ValidEntity(ply) then return end
  74.  
  75.       if self.Planted then return end
  76.  
  77.       local ignore = {ply, self.Weapon}
  78.       local spos = ply:GetShootPos()
  79.       local epos = spos + ply:GetAimVector() * 80
  80.       local tr = util.TraceLine({start=spos, endpos=epos, filter=ignore, mask=MASK_SOLID})
  81.  
  82.       if tr.HitWorld then
  83.          local camera = ents.Create("gmod_cameraprop")
  84.          if ValidEntity(camera) then
  85.             camera:PointAtEntity(ply)
  86.  
  87.             local tr_ent = util.TraceEntity({start=spos, endpos=epos, filter=ignore, mask=MASK_SOLID}, camera)
  88.  
  89.             if tr_ent.HitWorld then
  90.  
  91.                local ang = tr_ent.HitNormal:Angle()
  92.                        
  93.                camera:SetPos(tr_ent.HitPos) -- + ang:Forward()
  94.                camera:SetAngles(ang)
  95.                camera:SetOwner(ply)
  96.                camera:Spawn()
  97.  
  98.                local phys = camera:GetPhysicsObject()
  99.                if ValidEntity(phys) then
  100.                   phys:EnableMotion(false)
  101.                end
  102.  
  103.                camera.IsOnWall = true
  104.  
  105.                self:Remove()
  106.  
  107.                self.Planted = true
  108.                
  109.                position = camera:GetPos()
  110.                angleb = camera:GetAngles()
  111.                placed = true
  112.             end
  113.          end
  114.       end
  115.    end
  116. end
  117.  
  118. function SWEP:Reload()
  119.    return false
  120. end
  121.  
  122. function SWEP:OnRemove()
  123.    if CLIENT and ValidEntity(self.Owner) and self.Owner == LocalPlayer() and self.Owner:Alive() then
  124.       RunConsoleCommand("lastinv")
  125.    end
  126. end
  127.  
  128. if CLIENT then
  129.    local hudtxt = {text="Click to place the radio", font="TabLarge", xalign=TEXT_ALIGN_RIGHT, pos={}}
  130.    function SWEP:DrawHUD()
  131.       hudtxt.pos[1] = ScrW() - 80
  132.       hudtxt.pos[2] = ScrH() - 80
  133.       draw.TextShadow(hudtxt, 2)
  134.    end
  135. end
  136. -- Invisible, same hacks as holstered weapon
  137.  
  138.  
  139. function SWEP:Deploy()
  140.    if SERVER and IsValid(self.Owner) then
  141.       self.Owner:DrawViewModel(false)
  142.    end
  143.    return true
  144. end
  145.  
  146. function SWEP:DrawWorldModel()
  147. end
  148.  
  149. function SWEP:DrawWorldModelTranslucent()
  150. end
  151.  
  152. local function OriginCam()
  153.                  local camera = ents.FindByName("camera")
  154.                  local CamData = {}
  155.                  CamData.angles = angleb
  156.                  CamData.origin = position
  157.                  CamData.x = 0
  158.                  CamData.y = 0
  159.                  CamData.w = ScrW() / 3
  160.                  CamData.h = ScrH() / 3
  161.                  if placed then
  162.                  render.RenderView( CamData )
  163.                  end
  164. end        
  165.  
  166. hook.Add("HUDPaint", "OriginCam", OriginCam)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement