Advertisement
mj2009

hands_telekinez

Oct 7th, 2022
797
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.75 KB | None | 0 0
  1. AddCSLuaFile()
  2.  
  3.  
  4. SWEP.Author = "night"
  5. SWEP.SwayScale=3
  6. SWEP.BobScale=3
  7.  
  8. SWEP.Instructions   = ""
  9.  
  10. SWEP.Spawnable          = true
  11. SWEP.AdminOnly      = true
  12.  
  13. SWEP.HoldType = "normal"
  14.  
  15. SWEP.ViewModel = Model("models/weapons/c_arms_cstrike.mdl")
  16. SWEP.WorldModel = ""
  17. SWEP.IsAlwaysRaised = true
  18.  
  19. SWEP.AttackSlowDown=.5
  20.  
  21. SWEP.Primary.ClipSize       = -1
  22. SWEP.Primary.DefaultClip    = -1
  23. SWEP.Primary.Automatic      = false
  24. SWEP.Primary.Ammo           = "none"
  25. SWEP.FireWhenLowered = true
  26.  
  27. SWEP.Secondary.ClipSize     = -1
  28. SWEP.Secondary.DefaultClip  = -1
  29. SWEP.Secondary.Automatic    = false
  30. SWEP.Secondary.Ammo         = "none"
  31.  
  32. SWEP.ReachDistance=75
  33.  
  34.  
  35.     SWEP.PrintName = "Hands"
  36.     SWEP.Slot = 1
  37.     SWEP.SlotPos = 1
  38.     SWEP.DrawAmmo = false
  39.     SWEP.DrawCrosshair = false
  40.  
  41.  
  42.  
  43. function SWEP:SetupDataTables()
  44.     self:NetworkVar("Float",0,"NextIdle")
  45.     self:NetworkVar("Bool",2,"Fists")
  46.     self:NetworkVar("Float",1,"NextDown")
  47.     self:NetworkVar("Bool",3,"Blocking")
  48. end
  49.  
  50. function SWEP:PreDrawViewModel(vm,wep,ply)
  51.     --vm:SetMaterial("engine/occlusionproxy") -- Hide that view model with hacky material
  52. end
  53. function SWEP:Initialize()
  54.     self:SetNextIdle(CurTime()+5)
  55.     self:SetNextDown(CurTime()+5)
  56.     self:SetHoldType(self.HoldType)
  57. end
  58.  
  59. function SWEP:Deploy()
  60.     if not(IsFirstTimePredicted())then
  61.         --self:DoBFSAnimation("fists_draw")
  62.         self.Owner:GetViewModel():SetPlaybackRate(.1)
  63.         return
  64.     end
  65.     self:SetNextSecondaryFire(CurTime()+.1)
  66.  
  67.     self:SetNextDown(CurTime())
  68.     --self:DoBFSAnimation("fists_draw")
  69.     return true
  70. end
  71.  
  72. function SWEP:Holster()
  73.     self:OnRemove()
  74.     return true
  75. end
  76.  
  77. function SWEP:CanSecondaryAttack()
  78.     return false
  79. end
  80.  
  81. local pickupWhiteList = {
  82.     ["prop_ragdoll"] = true,
  83.     ["prop_physics"] = true,
  84.     ["prop_physics_multiplayer"] = true
  85. }
  86. function SWEP:CanPickup(ent)
  87.     if ent:IsNPC() then return false end
  88.     if(ent.IsLoot)then return true end
  89.     local class=ent:GetClass()
  90.     if pickupWhiteList[class] then return true end
  91.     return true
  92. end
  93.  
  94. function SWEP:PrimaryAttack()
  95.     if not(IsFirstTimePredicted())then return end
  96.     local tr = self.Owner:GetEyeTraceNoCursor()
  97.  
  98.  
  99.    
  100.     if SERVER then
  101.         self:SetCarrying()
  102.                      
  103.  
  104.        
  105.         if((IsValid(tr.Entity))and(self:CanPickup(tr.Entity))and not(tr.Entity:IsPlayer()))then
  106.             local Dist=(self.Owner:GetShootPos()-tr.HitPos):Length()
  107.             if(Dist<self.ReachDistance)then
  108.                 if(tr.Entity.ContactPoisoned)then
  109.                     if(self.Owner.Murderer)then
  110.                         self.Owner:PrintMessage(HUD_PRINTTALK,"This is poisoned!")
  111.                         return
  112.                     else
  113.                         tr.Entity.ContactPoisoned=false
  114.                         HMCD_Poison(self.Owner,tr.Entity.Poisoner)
  115.                     end
  116.                 end
  117.                 self:SetCarrying(tr.Entity,tr.PhysicsBone,tr.HitPos,Dist)
  118.                 tr.Entity.Touched=true
  119.                 self:ApplyForce()
  120.             end
  121.         elseif((IsValid(tr.Entity))and(tr.Entity:IsPlayer()))then
  122.             local Dist=(self.Owner:GetShootPos()-tr.HitPos):Length()
  123.             if(Dist<self.ReachDistance)then
  124.                 self.Owner:SetVelocity(self.Owner:GetAimVector()*20)
  125.                 tr.Entity:SetVelocity(-self.Owner:GetAimVector()*50)
  126.                 HMCD_StaminaPenalize(self.Owner,2)
  127.                 self:SetNextPrimaryFire(CurTime()+.25)
  128.             end
  129.         end
  130.  
  131.     end
  132. end
  133.  
  134.  
  135. function SWEP:ApplyForce()
  136.     local target = self.Owner:GetAimVector() * self.CarryDist + self.Owner:GetShootPos()
  137.     local phys = self.CarryEnt:GetPhysicsObjectNum(self.CarryBone)
  138.     if IsValid(phys) and not (self.CarryEnt:GetClass()=="prop_ragdoll") then
  139.         local TargetPos=phys:GetPos()
  140.         if(self.CarryPos)then TargetPos=self.CarryEnt:LocalToWorld(self.CarryPos) end
  141.         local vec = target - TargetPos
  142.         local len,mul = vec:Length(),self.CarryEnt:GetPhysicsObject():GetMass()
  143.         if((len>self.ReachDistance)or(mul>500))then
  144.             self:SetCarrying()
  145.  
  146.             return
  147.         end
  148.         --if(self.CarryEnt:GetClass()=="prop_ragdoll")then mul=mul*2 end
  149.         vec:Normalize()
  150.         local avec,velo=vec*len,phys:GetVelocity()-self.Owner:GetVelocity()
  151.         local CounterDir,CounterAmt=velo:GetNormalized(),velo:Length()
  152.         if(self.CarryPos)then
  153.             phys:ApplyForceOffset((avec-velo/2)*mul,self.CarryEnt:LocalToWorld(self.CarryPos))
  154.         else
  155.             phys:ApplyForceCenter((avec-velo/2)*mul)
  156.         end
  157.         phys:ApplyForceCenter(Vector(0,0,mul))
  158.         phys:AddAngleVelocity(-phys:GetAngleVelocity()/10)
  159.     end
  160.  
  161.  
  162. --Ragdoll force
  163.     local ragtarget = self.Owner:GetAimVector() * 30 + self.Owner:GetShootPos()
  164.     local ragphys = self.CarryEnt:GetPhysicsObjectNum(self.CarryBone)
  165.    
  166.     if IsValid(ragphys) and (self.CarryEnt:GetClass()=="prop_ragdoll") then
  167.         local ragvec = ragtarget - ragphys:GetPos()
  168.         local raglen = ragvec:Length()
  169.         if raglen > 40 then
  170.             self:SetCarrying()
  171.             return
  172.         end
  173.  
  174.         ragvec:Normalize()
  175.        
  176.         local ragtvec = ragvec * raglen * 15
  177.         local ragavec = ragtvec - ragphys:GetVelocity()
  178.         ragavec = ragavec:GetNormal() * math.min(45, ragavec:Length())
  179.         ragavec = ragavec / ragphys:GetMass() * 16
  180.        
  181.         ragphys:AddVelocity(ragavec)
  182.     end
  183. end
  184.  
  185. function SWEP:OnRemove()
  186.     if(IsValid(self.Owner) && CLIENT && self.Owner:IsPlayer())then
  187.         local vm=self.Owner:GetViewModel()
  188.         if(IsValid(vm)) then vm:SetMaterial("") end
  189.     end
  190. end
  191.  
  192. function SWEP:GetCarrying()
  193.     return self.CarryEnt
  194. end
  195.  
  196. function SWEP:SetCarrying(ent,bone,pos,dist)
  197.     if IsValid(ent) then
  198.  
  199.         self.CarryEnt = ent
  200.         self.CarryBone = bone
  201.         self.CarryDist=dist
  202.         if not (ent:GetClass()=="prop_ragdoll") then
  203.             self.CarryPos=ent:WorldToLocal(pos)
  204.         else
  205.             self.CarryPos=nil
  206.         end
  207.     else
  208.         self.CarryEnt = nil
  209.         self.CarryBone = nil
  210.         self.CarryPos = nil
  211.         self.CarryDist=nil
  212.     end
  213.     self.Owner:CalculateSpeed()
  214.  
  215. end
  216.  
  217.  
  218. --[[function SWEP:SetCarrying(ent, bone)
  219.     if IsValid(ent) then
  220.         self.CarryEnt = ent
  221.         self.CarryBone = bone
  222.  
  223.     else
  224.         self.CarryEnt = nil
  225.         self.CarryBone = nil
  226.     end
  227.    
  228.     self.Owner:CalculateSpeed()
  229. end]]--
  230.  
  231. local function lookingAtLockable(ply, ent, hitpos)
  232.     local eyepos = ply:EyePos()
  233.     return IsValid(ent)
  234.         and ent:isKeysOwnable()
  235.         and (
  236.             ent:isDoor() and eyepos:DistToSqr(hitpos) < 2000
  237.             or
  238.             ent:IsVehicle() and eyepos:DistToSqr(hitpos) < 4000
  239.         )
  240. end
  241.  
  242. function SWEP:Think()
  243.     local tr = self.Owner:GetEyeTraceNoCursor()
  244.     local Dist=(self.Owner:GetShootPos()-tr.HitPos):Length()
  245.     if((IsValid(self.Owner))and(self.Owner:KeyDown(IN_ATTACK)))then
  246.         if IsValid(self.CarryEnt) then
  247.             self:ApplyForce()
  248.         end
  249.     elseif self.CarryEnt then
  250.         self:SetCarrying()
  251.     end
  252.     if((self.Owner:KeyDown(IN_ATTACK)))then
  253.         self:SetNextSecondaryFire(CurTime()+.5)
  254.     end
  255.     local Owner = self:GetOwner()
  256.     if((IsValid(tr.Entity))and(self:CanPickup(tr.Entity))and not(tr.Entity:IsPlayer()) and (Dist<self.ReachDistance)) and self.Owner:KeyPressed(IN_ATTACK) or self.Owner:KeyReleased(IN_ATTACK) then
  257.     self:SetHoldType(self.Owner:KeyDown(IN_ATTACK) and "magic" or "normal")
  258.     elseif self.Owner:KeyPressed(IN_ATTACK) or self.Owner:KeyReleased(IN_ATTACK) then self:SetHoldType(self.Owner:KeyDown(IN_ATTACK) and "pistol" or "normal")
  259.     end
  260. end
  261.  
  262.  
  263.  
  264.  
  265.  
  266. function SWEP:Reload()
  267.     if not(IsFirstTimePredicted())then return end
  268.  
  269.     return end
  270.  
  271.     --self:SetCarrying()
  272. --end
  273.  
  274. function SWEP:DrawWorldModel()
  275.     -- no, do nothing
  276. end
  277.  
  278. --[[function SWEP:DoBFSAnimation(anim)
  279.     local vm=self.Owner:GetViewModel()
  280.     vm:SendViewModelMatchingSequence(vm:LookupSequence(anim))
  281. end]]--
  282.  
  283. function SWEP:UpdateNextIdle()
  284.     local vm=self.Owner:GetViewModel()
  285.     self:SetNextIdle(CurTime()+vm:SequenceDuration())
  286. end
  287.  
  288. function SWEP:IsEntSoft(ent)
  289.     return ((ent:IsNPC())or(ent:IsPlayer()))
  290. end
  291.  
  292.  
  293.  
  294. local playerMeta = FindMetaTable( "Player" )
  295.  
  296. function playerMeta:CalculateSpeed()
  297.     // set the defaults
  298.     local walk = 75-- nut.config.get("walkSpeed", default)
  299.     local run = 115
  300.  
  301.  
  302.  
  303.     local wep = self:GetActiveWeapon()
  304.     if IsValid(wep) then
  305.         if wep.GetCarrying && wep:GetCarrying() then
  306.             walk = walk * 0.5
  307.             run = run * 0.4
  308.  
  309.         end
  310.     end
  311.  
  312.     // set out new speeds
  313.  
  314.     self:SetWalkSpeed(walk)
  315.     self:SetRunSpeed(run)
  316.  
  317.  
  318. end
  319.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement