TheDenVxUA

re_hands.lua

May 3rd, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.51 KB | None | 0 0
  1. if SERVER then
  2.     AddCSLuaFile()
  3. end
  4.  
  5. SWEP.PrintName          = "Руки"
  6. SWEP.Author             = "SunRise Games"
  7. SWEP.Purpose                = "Удерживайте левую клавишу чтоб поднять предмет."
  8. SWEP.Spawnable              = true
  9. SWEP.Category               = "Other"
  10.  
  11. SWEP.ViewModel          = "models/weapons/c_medkit.mdl"
  12. SWEP.WorldModel         = ""
  13.  
  14. SWEP.AnimPrefix         = "rpg"
  15.  
  16. SWEP.Primary.ClipSize       = -1
  17. SWEP.Primary.DefaultClip    = -1
  18. SWEP.Primary.Automatic      = true
  19. SWEP.Primary.Ammo           = "none"
  20.  
  21. SWEP.Secondary.ClipSize     = -1
  22. SWEP.Secondary.DefaultClip  = -1
  23. SWEP.Secondary.Automatic    = false
  24. SWEP.Secondary.Ammo         = "none"
  25.  
  26. SWEP.DrawCrosshair = false
  27.  
  28. function SWEP:Initialize()
  29.     self:SetHoldType( "normal" )
  30.  
  31.     self.Time = 0
  32.     self.Range = 150
  33. end
  34.  
  35. function SWEP:Think()
  36.     if self.Drag and (not self.Owner:KeyDown(IN_ATTACK) or not IsValid(self.Drag.Entity)) then
  37.         self.Drag = nil
  38.     end
  39. end
  40.  
  41. function SWEP:PrimaryAttack()
  42.     local Pos = self.Owner:GetShootPos()
  43.     local Aim = self.Owner:GetAimVector()
  44.  
  45.     local Tr = util.TraceLine{
  46.         start = Pos,
  47.         endpos = Pos +Aim *self.Range,
  48.         filter = player.GetAll(),
  49.     }
  50.  
  51.     local HitEnt = Tr.Entity
  52.     if self.Drag then
  53.         HitEnt = self.Drag.Entity
  54.     else
  55.         if not IsValid( HitEnt ) or HitEnt:GetMoveType() ~= MOVETYPE_VPHYSICS or
  56.             HitEnt:IsVehicle() or HitEnt:GetNWBool( "NoDrag", false ) or
  57.             HitEnt.BlockDrag or
  58.             IsValid( HitEnt:GetParent() ) then
  59.             return
  60.         end
  61.  
  62.         if not self.Drag then
  63.             self.Drag = {
  64.                 OffPos = HitEnt:WorldToLocal(Tr.HitPos),
  65.                 Entity = HitEnt,
  66.                 Fraction = Tr.Fraction,
  67.             }
  68.         end
  69.     end
  70.  
  71.     if CLIENT or not IsValid( HitEnt ) then return end
  72.  
  73.     local Phys = HitEnt:GetPhysicsObject()
  74.  
  75.     if IsValid( Phys ) then
  76.         local Pos2 = Pos +Aim *self.Range *self.Drag.Fraction
  77.         local OffPos = HitEnt:LocalToWorld( self.Drag.OffPos )
  78.         local Dif = Pos2 -OffPos
  79.         local Nom = (Dif:GetNormal() *math.min(1, Dif:Length() /100) *500 -Phys:GetVelocity()) *Phys:GetMass()
  80.  
  81.         Phys:ApplyForceOffset( Nom, OffPos )
  82.         Phys:AddAngleVelocity( -Phys:GetAngleVelocity() /4 )
  83.     end
  84. end
  85.  
  86. if CLIENT then
  87.     local x, y = ScrW() /2, ScrH() /2
  88.     local MainCol = Color( 255, 255, 255, 255 )
  89.     local Col = Color( 255, 255, 255, 255 )
  90.  
  91.     function SWEP:DrawHUD()
  92.         if IsValid( self.Owner:GetVehicle() ) then return end
  93.         local Pos = self.Owner:GetShootPos()
  94.         local Aim = self.Owner:GetAimVector()
  95.  
  96.         local Tr = util.TraceLine{
  97.             start = Pos,
  98.             endpos = Pos +Aim *self.Range,
  99.             filter = player.GetAll(),
  100.         }
  101.  
  102.         local HitEnt = Tr.Entity
  103.         if IsValid( HitEnt ) and HitEnt:GetMoveType() == MOVETYPE_VPHYSICS and
  104.             not self.rDag and
  105.             not HitEnt:IsVehicle() and
  106.             not IsValid( HitEnt:GetParent() ) and
  107.             not HitEnt:GetNWBool( "NoDrag", false ) then
  108.  
  109.             self.Time = math.min( 1, self.Time +2 *FrameTime() )
  110.         else
  111.             self.Time = math.max( 0, self.Time -2 *FrameTime() )
  112.         end
  113.  
  114.         if self.Time > 0 then
  115.             Col.a = MainCol.a *self.Time
  116.  
  117.             draw.SimpleText(
  118.                 "Тащить",
  119.                 "DermaLarge",
  120.                 x,
  121.                 y,
  122.                 Col,
  123.                 TEXT_ALIGN_CENTER
  124.             )
  125.         end
  126.  
  127.         if self.Drag and IsValid( self.Drag.Entity ) then
  128.             local Pos2 = Pos +Aim *100 *self.Drag.Fraction
  129.             local OffPos = self.Drag.Entity:LocalToWorld( self.Drag.OffPos )
  130.             local Dif = Pos2 -OffPos
  131.  
  132.             local A = OffPos:ToScreen()
  133.             local B = Pos2:ToScreen()
  134.  
  135.             surface.DrawRect( A.x -2, A.y -2, 4, 4, MainCol )
  136.             surface.DrawRect( B.x -2, B.y -2, 4, 4, MainCol )
  137.             surface.DrawLine( A.x, A.y, B.x, B.y, MainCol )
  138.         end
  139.     end
  140. end
  141.  
  142. function SWEP:PreDrawViewModel( vm, pl, wep )
  143.     return true
  144. end
Add Comment
Please, Sign In to add comment