Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.24 KB | None | 0 0
  1.  
  2.  
  3.  
  4. AddCSLuaFile()
  5.  
  6.  
  7.  
  8.  
  9.  
  10. SWEP.ViewModel = Model( "models/weapons/c_arms_animations.mdl" )
  11.  
  12.  
  13. SWEP.WorldModel = Model( "models/MaxOfS2D/camera.mdl" )
  14.  
  15.  
  16.  
  17.  
  18.  
  19. SWEP.Primary.ClipSize       = -1
  20.  
  21.  
  22. SWEP.Primary.DefaultClip    = -1
  23.  
  24.  
  25. SWEP.Primary.Automatic      = false
  26.  
  27.  
  28. SWEP.Primary.Ammo           = "none"
  29.  
  30.  
  31.  
  32.  
  33.  
  34. SWEP.Secondary.ClipSize     = -1
  35.  
  36.  
  37. SWEP.Secondary.DefaultClip  = -1
  38.  
  39.  
  40. SWEP.Secondary.Automatic    = true
  41.  
  42.  
  43. SWEP.Secondary.Ammo         = "none"
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. SWEP.PrintName  = "Kamera"
  53.  
  54.  
  55.  
  56.  
  57.  
  58. SWEP.Slot       = 5
  59.  
  60.  
  61. SWEP.SlotPos    = 1
  62.  
  63.  
  64.  
  65.  
  66.  
  67. SWEP.DrawAmmo       = false
  68.  
  69.  
  70. SWEP.DrawCrosshair  = false
  71.  
  72.  
  73. SWEP.Spawnable      = true
  74.  
  75.  
  76.  
  77.  
  78.  
  79. SWEP.ShootSound = Sound( "NPC_CScanner.TakePhoto" )
  80.  
  81.  
  82.  
  83.  
  84.  
  85. if ( SERVER ) then
  86.  
  87.  
  88.  
  89.  
  90.  
  91.     SWEP.AutoSwitchTo       = false
  92.  
  93.  
  94.     SWEP.AutoSwitchFrom     = false
  95.  
  96.  
  97.  
  98.  
  99.  
  100.     --
  101.  
  102.  
  103.     -- A concommand to quickly switch to the camera
  104.  
  105.  
  106.     --
  107.  
  108.  
  109.     concommand.Add( "gmod_camera", function( player, command, arguments )
  110.  
  111.  
  112.  
  113.  
  114.  
  115.         player:SelectWeapon( "gmod_camera" )
  116.  
  117.  
  118.  
  119.  
  120.  
  121.     end )
  122.  
  123.  
  124.  
  125.  
  126.  
  127. end
  128.  
  129.  
  130.  
  131.  
  132.  
  133. --
  134.  
  135.  
  136. -- Network/Data Tables
  137.  
  138.  
  139. --
  140.  
  141.  
  142. function SWEP:SetupDataTables()
  143.  
  144.  
  145.  
  146.  
  147.  
  148.     self:NetworkVar( "Float", 0, "Zoom" )
  149.  
  150.  
  151.     self:NetworkVar( "Float", 1, "Roll" )
  152.  
  153.  
  154.  
  155.  
  156.  
  157.     if ( SERVER ) then
  158.  
  159.  
  160.         self:SetZoom( 70 )
  161.  
  162.  
  163.         self:SetRoll( 0 )
  164.  
  165.  
  166.     end
  167.  
  168.  
  169.  
  170.  
  171.  
  172. end
  173.  
  174.  
  175.  
  176.  
  177.  
  178. --
  179.  
  180.  
  181. -- Initialize Stuff
  182.  
  183.  
  184. --
  185.  
  186.  
  187. function SWEP:Initialize()
  188.  
  189.  
  190.  
  191.  
  192.  
  193.     self:SetHoldType( "camera" )
  194.  
  195.  
  196.  
  197.  
  198.  
  199. end
  200.  
  201.  
  202.  
  203.  
  204.  
  205. --
  206.  
  207.  
  208. -- Reload resets the FOV and Roll
  209.  
  210.  
  211. --
  212.  
  213.  
  214. function SWEP:Reload()
  215.  
  216.  
  217.  
  218.  
  219.  
  220.     if ( !self.Owner:KeyDown( IN_ATTACK2 ) ) then self:SetZoom( self.Owner:IsBot() && 75 || self.Owner:GetInfoNum( "fov_desired", 75 ) ) end
  221.  
  222.  
  223.     self:SetRoll( 0 )
  224.  
  225.  
  226.  
  227.  
  228.  
  229. end
  230.  
  231.  
  232.  
  233.  
  234.  
  235. --
  236.  
  237.  
  238. -- PrimaryAttack - make a screenshot
  239.  
  240.  
  241. --
  242.  
  243.  
  244. function SWEP:PrimaryAttack()
  245.  
  246.  
  247.  
  248.  
  249.  
  250.     self:DoShootEffect()
  251.  
  252.  
  253.  
  254.  
  255.  
  256.     -- If we're multiplayer this can be done totally clientside
  257.  
  258.  
  259.     if ( !game.SinglePlayer() && SERVER ) then return end
  260.  
  261.  
  262.     if ( CLIENT && !IsFirstTimePredicted() ) then return end
  263.  
  264.  
  265.  
  266.  
  267.  
  268.     self.Owner:ConCommand( "jpeg" )
  269.  
  270.  
  271.  
  272.  
  273.  
  274. end
  275.  
  276.  
  277.  
  278.  
  279.  
  280. --
  281.  
  282.  
  283. -- SecondaryAttack - Nothing. See Tick for zooming.
  284.  
  285.  
  286. --
  287.  
  288.  
  289. function SWEP:SecondaryAttack()
  290.  
  291.  
  292. end
  293.  
  294.  
  295.  
  296.  
  297.  
  298. --
  299.  
  300.  
  301. -- Mouse 2 action
  302.  
  303.  
  304. --
  305.  
  306.  
  307. function SWEP:Tick()
  308.  
  309.  
  310.  
  311.  
  312.  
  313.     if ( CLIENT && self.Owner != LocalPlayer() ) then return end -- If someone is spectating a player holding this weapon, bail
  314.  
  315.  
  316.  
  317.  
  318.  
  319.     local cmd = self.Owner:GetCurrentCommand()
  320.  
  321.  
  322.  
  323.  
  324.  
  325.     if ( !cmd:KeyDown( IN_ATTACK2 ) ) then return end -- Not holding Mouse 2, bail
  326.  
  327.  
  328.  
  329.  
  330.  
  331.     self:SetZoom( math.Clamp( self:GetZoom() + cmd:GetMouseY() * 0.1, 0.1, 175 ) ) -- Handles zooming
  332.  
  333.  
  334.     self:SetRoll( self:GetRoll() + cmd:GetMouseX() * 0.025 ) -- Handles rotation
  335.  
  336.  
  337.  
  338.  
  339.  
  340. end
  341.  
  342.  
  343.  
  344.  
  345.  
  346. --
  347.  
  348.  
  349. -- Override players Field Of View
  350.  
  351.  
  352. --
  353.  
  354.  
  355. function SWEP:TranslateFOV( current_fov )
  356.  
  357.  
  358.  
  359.  
  360.  
  361.     return self:GetZoom()
  362.  
  363.  
  364.  
  365.  
  366.  
  367. end
  368.  
  369.  
  370.  
  371.  
  372.  
  373. --
  374.  
  375.  
  376. -- Deploy - Allow lastinv
  377.  
  378.  
  379. --
  380.  
  381.  
  382. function SWEP:Deploy()
  383.  
  384.  
  385.  
  386.  
  387.  
  388.     return true
  389.  
  390.  
  391.  
  392.  
  393.  
  394. end
  395.  
  396.  
  397.  
  398.  
  399.  
  400. --
  401.  
  402.  
  403. -- Set FOV to players desired FOV
  404.  
  405.  
  406. --
  407.  
  408.  
  409. function SWEP:Equip()
  410.  
  411.  
  412.  
  413.  
  414.  
  415.     if ( self:GetZoom() == 70 && self.Owner:IsPlayer() && !self.Owner:IsBot() ) then
  416.  
  417.  
  418.         self:SetZoom( self.Owner:GetInfoNum( "fov_desired", 75 ) )
  419.  
  420.  
  421.     end
  422.  
  423.  
  424.  
  425.  
  426.  
  427. end
  428.  
  429.  
  430.  
  431.  
  432.  
  433. function SWEP:ShouldDropOnDie() return false end
  434.  
  435.  
  436.  
  437.  
  438.  
  439. --
  440.  
  441.  
  442. -- The effect when a weapon is fired successfully
  443.  
  444.  
  445. --
  446.  
  447.  
  448. function SWEP:DoShootEffect()
  449.  
  450.  
  451.  
  452.  
  453.  
  454.     self:EmitSound( self.ShootSound )
  455.  
  456.  
  457.     self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  458.  
  459.  
  460.     self.Owner:SetAnimation( PLAYER_ATTACK1 )
  461.  
  462.  
  463.  
  464.  
  465.  
  466.     if ( SERVER && !game.SinglePlayer() ) then
  467.  
  468.  
  469.  
  470.  
  471.  
  472.         --
  473.  
  474.  
  475.         -- Note that the flash effect is only
  476.  
  477.  
  478.         -- shown to other players!
  479.  
  480.  
  481.         --
  482.  
  483.  
  484.  
  485.  
  486.  
  487.         local vPos = self.Owner:GetShootPos()
  488.  
  489.  
  490.         local vForward = self.Owner:GetAimVector()
  491.  
  492.  
  493.  
  494.  
  495.  
  496.         local trace = {}
  497.  
  498.  
  499.         trace.start = vPos
  500.  
  501.  
  502.         trace.endpos = vPos + vForward * 256
  503.  
  504.  
  505.         trace.filter = self.Owner
  506.  
  507.  
  508.  
  509.  
  510.  
  511.         local tr = util.TraceLine( trace )
  512.  
  513.  
  514.  
  515.  
  516.  
  517.         local effectdata = EffectData()
  518.  
  519.  
  520.         effectdata:SetOrigin( tr.HitPos )
  521.  
  522.  
  523.         util.Effect( "camera_flash", effectdata, true )
  524.  
  525.  
  526.  
  527.  
  528.  
  529.     end
  530.  
  531.  
  532.  
  533.  
  534.  
  535. end
  536.  
  537.  
  538.  
  539.  
  540.  
  541. if ( SERVER ) then return end -- Only clientside lua after this line
  542.  
  543.  
  544.  
  545.  
  546.  
  547. SWEP.WepSelectIcon = surface.GetTextureID( "vgui/gmod_camera" )
  548.  
  549.  
  550.  
  551.  
  552.  
  553. -- Don't draw the weapon info on the weapon selection thing
  554.  
  555.  
  556. function SWEP:DrawHUD() end
  557.  
  558.  
  559. function SWEP:PrintWeaponInfo( x, y, alpha ) end
  560.  
  561.  
  562.  
  563.  
  564.  
  565. function SWEP:HUDShouldDraw( name )
  566.  
  567.  
  568.  
  569.  
  570.  
  571.     -- So we can change weapons
  572.  
  573.  
  574.     if ( name == "CHudWeaponSelection" ) then return true end
  575.  
  576.  
  577.     if ( name == "CHudChat" ) then return true end
  578.  
  579.  
  580.  
  581.  
  582.  
  583.     return false
  584.  
  585.  
  586.  
  587.  
  588.  
  589. end
  590.  
  591.  
  592.  
  593.  
  594.  
  595. function SWEP:FreezeMovement()
  596.  
  597.  
  598.  
  599.  
  600.  
  601.     -- Don't aim if we're holding the right mouse button
  602.  
  603.  
  604.     if ( self.Owner:KeyDown( IN_ATTACK2 ) || self.Owner:KeyReleased( IN_ATTACK2 ) ) then
  605.  
  606.  
  607.         return true
  608.  
  609.  
  610.     end
  611.  
  612.  
  613.  
  614.  
  615.  
  616.     return false
  617.  
  618.  
  619.  
  620.  
  621.  
  622. end
  623.  
  624.  
  625.  
  626.  
  627.  
  628. function SWEP:CalcView( ply, origin, angles, fov )
  629.  
  630.  
  631.  
  632.  
  633.  
  634.     if ( self:GetRoll() != 0 ) then
  635.  
  636.  
  637.         angles.Roll = self:GetRoll()
  638.  
  639.  
  640.     end
  641.  
  642.  
  643.  
  644.  
  645.  
  646.     return origin, angles, fov
  647.  
  648.  
  649.  
  650.  
  651.  
  652. end
  653.  
  654.  
  655.  
  656.  
  657.  
  658. function SWEP:AdjustMouseSensitivity()
  659.  
  660.  
  661.  
  662.  
  663.  
  664.     if ( self.Owner:KeyDown( IN_ATTACK2 ) ) then return 1 end
  665.  
  666.  
  667.  
  668.  
  669.  
  670.     return self:GetZoom() / 80
  671.  
  672.  
  673.  
  674.  
  675.  
  676. end
  677.  
  678.  
  679.  
  680.  
  681.  
  682. local themat = Material("hgg/hgg.png")
  683.  
  684.  
  685. local waterMark
  686.  
  687.  
  688.  
  689.  
  690.  
  691. hook.Add("PlayerSwitchWeapon", "HGGWatermark", function(ply, oldWeapon, newWeapon)
  692.  
  693.  
  694.     if ply ~= LocalPlayer() then return end
  695.  
  696.  
  697.     if newWeapon:GetClass() == "gmod_camera" then
  698.  
  699.  
  700.         if not waterMark then
  701.  
  702.  
  703.             waterMark = vgui.Create("DPanel")
  704.  
  705.  
  706.             waterMark:SetSize(255, 255)
  707.  
  708.  
  709.             waterMark:SetPos(0, ScrH() - 255, 255, 255)
  710.  
  711.  
  712.             function waterMark:Paint(w, h)
  713.  
  714.  
  715.                 surface.SetMaterial( themat )
  716.  
  717.  
  718.                 surface.SetDrawColor(255, 255, 255, 175)
  719.  
  720.  
  721.                 surface.DrawTexturedRect(0, 0, w, h)
  722.  
  723.  
  724.             end
  725.  
  726.  
  727.         end
  728.  
  729.  
  730.         waterMark:SetVisible(true)
  731.  
  732.  
  733.     elseif oldWeapon:GetClass() == "gmod_camera" then
  734.  
  735.  
  736.         waterMark:SetVisible(false)
  737.  
  738.  
  739.     end
  740.  
  741.  
  742. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement