Advertisement
Guest User

Untitled

a guest
May 28th, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.75 KB | None | 0 0
  1.  
  2. AddCSLuaFile( "cl_init.lua" )
  3. AddCSLuaFile( "shared.lua" )
  4. include('shared.lua')
  5.  
  6.  
  7. function ENT:Initialize()
  8.     self:SetModel(self.WorldModel)
  9.  
  10.     self:PhysicsInit( SOLID_VPHYSICS )
  11.     -- self:PhysicsInitSphere(50)
  12.     self:SetMoveType( MOVETYPE_VPHYSICS )
  13.     self:SetSolid( SOLID_VPHYSICS )
  14.     self:DrawShadow(false)
  15.  
  16.     // don't do impact damage
  17.     -- self:SetTrigger(true)
  18.     -- self:SetCollisionGroup(COLLISION_GROUP_WEAPON)
  19.  
  20.     local phys = self:GetPhysicsObject()
  21.     if IsValid(phys) then
  22.         phys:Wake()
  23.     end
  24.  
  25.     self:Fire("kill", "", 30)
  26.  
  27.     self.HitSomething = false
  28. end
  29.  
  30. function ENT:Use(ply)
  31.     self.RemoveNext = true
  32. end
  33.  
  34. function ENT:Think()
  35.     if self.RemoveNext && IsValid(self) then
  36.         self.RemoveNext = false
  37.         self:Remove()
  38.     end
  39.     if self.HitSomething && self:GetVelocity():Length2D() < 1.5 then
  40.         self.HitSomething = false
  41.         local knife = ents.Create(self.WeaponClass)
  42.         knife:SetPos(self:GetPos())
  43.         knife:SetAngles(self:GetAngles())
  44.         knife:Spawn()
  45.         self:Remove()
  46.         local phys = knife:GetPhysicsObject()
  47.         if IsValid(phys) then
  48.             phys:SetVelocity(self:GetVelocity())
  49.         end
  50.     end
  51.  
  52.     self:NextThink(CurTime())
  53.     return true
  54. end
  55.  
  56. local function addangle(ang,ang2)
  57.     ang:RotateAroundAxis(ang:Up(),ang2.y) -- yaw
  58.     ang:RotateAroundAxis(ang:Forward(),ang2.r) -- roll
  59.     ang:RotateAroundAxis(ang:Right(),ang2.p) -- pitch
  60. end
  61.  
  62. function ENT:PhysicsCollide( data, physobj )
  63.     -- print(data.OurOldVelocity:Length())
  64.  
  65.     if self.HitSomething then return end
  66.     if self.RemoveNext then return end
  67.    
  68.     local ply = data.HitEntity
  69.     if IsValid(ply) && ply:IsPlayer() then
  70.  
  71.         -- self.RemoveNext = true
  72.         -- self:SetColor(Color(0,0,0,0))
  73.  
  74.         local dmg = DamageInfo()
  75.         dmg:SetDamage(120)
  76.         dmg:SetAttacker(self:GetOwner())
  77.         ply:TakeDamageInfo(dmg)
  78.         self:EmitSound("physics/flesh/flesh_squishy_impact_hard" .. math.random(1, 4) .. ".wav")
  79.  
  80.         local pos = ply:GetPos() + Vector(00,0,40)
  81.         local ang = ply:GetAngles() * 1
  82.         addangle(ang, Angle(-60,0,0))
  83.  
  84.         timer.Simple(0, function ()
  85.             local rag = ply:GetRagdollEntity()
  86.  
  87.             if IsValid(rag) then
  88.                 local pos, ang = rag:GetBonePosition(0)
  89.                 local vec = Vector(0, 16, -14)
  90.                 vec:Rotate(ang)
  91.                 pos = pos + vec
  92.                 addangle(ang, Angle(30, -90, 0))
  93.  
  94.                 -- local knife = ents.Create("prop_physics")
  95.                 -- knife:SetModel("models/weapons/w_knife_t.mdl")
  96.                 -- knife:SetCollisionGroup(COLLISION_GROUP_DEBRIS)
  97.                 -- knife:SetPos(pos)
  98.                 -- knife:SetAngles(ang)
  99.                 -- knife:Spawn()
  100.  
  101.                 -- local phys = knife:GetPhysicsObject()
  102.                 -- if IsValid(phys) then
  103.                 --  phys:EnableCollisions(false)
  104.                 -- end
  105.  
  106.  
  107.                 -- constraint.Weld(rag, knife, 0, 0, 0, true)
  108.  
  109.                 -- rag:CallOnRemove("knife_cleanup", function() SafeRemoveEntity(knife) end)
  110.  
  111.             end
  112.  
  113.         end)
  114.     end
  115.  
  116.     self.HitSomething = true
  117. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement