Guest User

Entity - Init.lua

a guest
Oct 18th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. AddCSLuaFile("cl_init.lua")
  2. AddCSLuaFile("shared.lua")
  3. include("shared.lua")
  4.  
  5. AccessorFunc(ENT, "HasCollided", "HasCollided")
  6. AccessorFunc(ENT, "CollisionPosition", "CollisionPosition")
  7. AccessorFunc(ENT, "CollisionNormal", "CollisionNormal")
  8.  
  9. hook.Add("TTTPrepareRound", "ValkyrieCameraCleanUp", function()
  10. for _, camera in pairs(ents.FindByClass("valkyrie_camera")) do
  11. camera:Remove()
  12. end
  13. end)
  14.  
  15. function ENT:PhysicsCollide(colData, collider)
  16. local ent = colData.HitEntity
  17.  
  18. if !ent:IsWorld() then self:DropToFloor() return end
  19.  
  20. self:SetHasCollided(true)
  21. self:SetCollisionPosition(colData.HitPos)
  22. self:SetCollisionNormal(colData.HitNormal)
  23.  
  24. local phys = self:GetPhysicsObject()
  25. if IsValid(phys) then
  26. phys:EnableMotion(false)
  27. end
  28. end
  29.  
  30. function ENT:OnTakeDamage(damage)
  31. print("ENT:OnTakeDamage")
  32. print(damage)
  33. if (IsValid(self)) then
  34. self:SetHealth(self:Health() - damage:GetDamage())
  35. if (self:Health() <= 0) then
  36. local attacker = damage:GetAttacker()
  37. if (IsValid(attacker)) then
  38. self:SetPlacer(attacker)
  39. end
  40. self:Remove()
  41. end
  42. end
  43. end
  44.  
  45. function ENT:Think()
  46. if IsValid(self) and self:GetHasCollided() then
  47. local phys = self:GetPhysicsObject()
  48. if IsValid(phys) then
  49. phys:EnableMotion(false)
  50. end
  51.  
  52. local pos = self:GetCollisionPosition()
  53. local norm = self:GetCollisionNormal()
  54. local ang = norm:Angle()
  55. ang.p = ang.p - 90
  56.  
  57. self:SetPos(pos)
  58. self:SetAngles(ang)
  59.  
  60. self:SetHasCollided(false)
  61. self:SetCollisionPosition(nil)
  62. self:SetCollisionNormal(nil)
  63. end
  64. end
Advertisement
Add Comment
Please, Sign In to add comment