Python1320

asdf

Mar 27th, 2011
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. --[[
  2. ~ BLACK HOLE OF DOOOM ~
  3. ~ Lexi ~
  4. --]]
  5. local ENT={}
  6. ENT.Type = "anim"
  7. ENT.Base = "base_gmodentity"--"base_anim"
  8.  
  9. ENT.PrintName = "Black Hole Of Doom"
  10. ENT.Author = "Lexi"
  11. ENT.Contact = ""
  12. ENT.Purpose = "To suck all matter into itself"
  13. ENT.Instructions = "Do not use under pain of being sucked into a black hole"
  14.  
  15. ENT.Spawnable = true
  16. ENT.AdminSpawnable = true
  17. ENT.RenderGroup = RENDERGROUP_TRANSLUCENT;
  18. ENT.Category = "Lexi's Dev Stuff"
  19.  
  20. function ENT:SetupDataTables()
  21. self:DTVar("Int", 0, "mass");
  22. end
  23.  
  24. local model, modelradius = "models/combine_helicopter/helicopter_bomb01.mdl", 28
  25. local scale = modelradius * 100
  26.  
  27. if (CLIENT) then
  28. --[[
  29. ENT.lastmass = 0;
  30. function ENT:Think()
  31. local m1, m2 = self.dt.mass, self.lastmass
  32. if (m1 ~= m2) then
  33. self.lastmass = m1;
  34. local num = m1 / scale;
  35. self:SetModelScale(Vector(num, num, num));
  36. end
  37. end
  38. --]]
  39. return;
  40. end
  41.  
  42. local G = 4.67428e-5
  43. local function gravity(mass1,mass2,dist)
  44. return G * mass1 * mass2 / dist * dist;
  45. end
  46. function ENT:Initialize()
  47. self:SetModel(model)
  48. self.dt.mass = modelradius;
  49. self:PhysicsInitSphere(self.dt.mass)
  50. -- self:PhysicsInit(SOLID_VPHYSICS)
  51. self:SetMoveType(MOVETYPE_VPHYSICS)
  52. self:SetSolid(SOLID_VPHYSICS)
  53. self:SetMaterial("models/debug/debugwhite")
  54. local ent = self;
  55. self:SetOverlayText("- Black Hole -\nInternal Mass: " .. self.dt.mass);
  56. -- hook.Add("Tick", "Black Hole Sucking: " .. self:EntIndex(), function() ent:Suck(); end);
  57. end
  58. --[[
  59. function ENT:OnRemove()
  60. hook.Remove("Tick", "Black Hole Sucking: " .. self:EntIndex());
  61. end
  62. --]]
  63. function ENT:Think()
  64. self:Suck();
  65. -- self:NextThink(CurTime() + 0.1);
  66. -- return true;
  67. end
  68.  
  69. function ENT:Suck()
  70. local phys, mass, dir, pos, entpos, grav;
  71. pos = self:GetPos();
  72. mass = self.dt.mass;
  73. for _,ent in ipairs(ents.GetAll()) do
  74. phys = ent:GetPhysicsObject();
  75. if (phys:IsValid() and ent ~= self and not ent:IsWorld()) then
  76. entpos = ent:GetPos();
  77. grav = gravity(mass, phys:GetMass(), entpos:Distance(pos));
  78. dir = (entpos - pos):Normalize() * -grav;
  79. if (ent:IsPlayer()) then
  80. ent:SetVelocity(dir);
  81. else
  82. phys:AddVelocity(dir);
  83. end
  84. if (not phys:IsMoveable() and dir:LengthSqr() > 100000000) then
  85. phys:EnableMotion(true);
  86. end
  87. -- debugoverlay.Line(entpos, entpos + dir, 0.5);
  88. -- debugoverlay.Text(entpos, grav, 0.5);
  89. end
  90. end
  91. end
  92. function ENT:SpawnFunction( ply, tr )
  93. local ClassName = ClassName or "sent_blackhole"
  94. if not tr.Hit then return end
  95. local ent = ents.Create(ClassName)
  96. ent:SetPos( tr.HitPos + tr.HitNormal * 52)
  97. ent:Spawn()
  98. ent:Activate()
  99. return ent
  100. end
  101. function ENT:PhysicsCollide(data)
  102. local ent = data.HitEntity;
  103. -- print(ent);
  104. if (not(ent:IsValid() and ent ~= self and not ent:IsWorld())) then return; end
  105. local physobj = ent:GetPhysicsObject();
  106. if (not(physobj:IsValid())) then return end
  107. self.dt.mass = self.dt.mass + physobj:GetMass();
  108. --self:PhysicsInitSphere(self.dt.mass)
  109. if (ent:IsPlayer()) then
  110. ent:TakeDamage(200, self, self);
  111. else
  112. ent:Remove();
  113. end
  114. self:SetOverlayText("- Black Hole -\nInternal Mass: " .. self.dt.mass);
  115. end
  116.  
  117. scripted_ents.Register(ENT,"sent_blackhole",true)
Advertisement
Add Comment
Please, Sign In to add comment