Black Hole Type Entity

hello guys, i need some code help, this code makes a sphere and when it reaches max size it shrinks back down at a rapid rate then is supposed to delete itself, and damages any player within the sphere, and that’s off too

[lua]

function ENT:Draw()
self.Entity:DrawModel()

render.SetColorMaterial()
 render.SetMaterial(Material("models/effects/base"))
render.DrawSphere( self:GetPos(), self.size, 50, 50, Color( 0, 0, 0, 252 ) )

render.SetMaterial(Material(“models/effects/portalfunnel_sheet”))
render.DrawSphere( self:GetPos(), self.size*1.1, 50, 50, Color( 0, 150, 150, 100 ) )

end

function ENT:Initialize()
self.active=0
self.size=0
self.Delay=0

PrecacheParticleSystem(“flaregun_energyfield_red”)
PrecacheParticleSystem(“flaregun_energyfield_blue”)
ParticleEffectAttach(“flaregun_energyfield_red”,PATTACH_ABSORIGIN_FOLLOW,self,0)

self:SetModel( "models/weapons/w_models/w_stickybomb2.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )      -- Make us work with physics,
self:SetMoveType( MOVETYPE_VPHYSICS )   -- after all, gmod is a physics
self:SetSolid( SOLID_VPHYSICS )  


    local phys = self:GetPhysicsObject()
if (phys:IsValid()) then
	phys:Wake()
    
    phys:SetMass(1)
	

end

self.SoundName = Sound( “PS2/02345_car_loop.wav” )
self.Sound = CreateSound( self.Entity, self.SoundName )

self.Sound:PlayEx(400,200)

end

function ENT:Use( activator, caller )
return
end

function ENT:Think()

if (self.size<500 && self.active==0) then

self.size=self.size+1

end

if (self.size>=500 && self.active==0) then

self.active=self.active+1

end

if (self.Delay<=0 && self.active==1) then
self.size=self.size-5
end

if (self.size<=0) then
self.size=self.size*0
end

if (self.Delay==0 and self.active==1) then
self:Remove()
end

for k, v in pairs(ents.FindInSphere(self:GetPos(), self.size*4.5)) do

if( v:IsPlayer() or v:IsNPC()) then

local damage = 1
local attacker = self
local inflictor = self

v:TakeDamage( damage, attacker, inflictor )

end
end

end

[/lua]

Can you be more specific on what you need, or whats not working in this code?

I tried cleaning up the code and [del]I think I understand what the problem is, Delay currently does absolutely nothing, and this code doesn’t reduce the size, it only increases, for 500 ticks/Think calls (could be a different length of time depending on server tickrate).[/del] I have no idea what is going on.

This is what I formatted the above code to look like to help with readability (and also fix Material being called every frame):
[lua]local basemat = Material(“models/effects/base”)
local portalmat = Material(“models/effects/portalfunnel_sheet”)

function ENT:Draw()
self.Entity:DrawModel()
render.SetColorMaterial()
render.SetMaterial(basemat)
render.DrawSphere( self:GetPos(), self.size, 50, 50, Color( 0, 0, 0, 252 ) )
render.SetMaterial(portalmat)
render.DrawSphere( self:GetPos(), self.size*1.1, 50, 50, Color( 0, 150, 150, 100 ) )
end

function ENT:Initialize()

self.active=0
self.size=0
self.Delay=0

PrecacheParticleSystem("flaregun_energyfield_red")
PrecacheParticleSystem("flaregun_energyfield_blue")
ParticleEffectAttach("flaregun_energyfield_red",PATTACH_ABSORIGIN_FOLLOW,self,0)

self:SetModel( "models/weapons/w_models/w_stickybomb2.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )      -- Make us work with physics,
self:SetMoveType( MOVETYPE_VPHYSICS )   -- after all, gmod is a physics
self:SetSolid( SOLID_VPHYSICS )  

local phys = self:GetPhysicsObject()
if phys:IsValid() then
	phys:Wake()
	phys:SetMass(1)
end

self.SoundName = Sound( "PS2/02345_car_loop.wav" )
self.Sound = CreateSound( self.Entity, self.SoundName )
self.Sound:PlayEx(400,200)

end

function ENT:Use( activator, caller )
return
end

function ENT:Think()

if (self.size&lt;500 && self.active==0) then
	self.size=self.size+1
end
if (self.size&gt;=500 && self.active==0) then
	self.active=self.active+1
end
if (self.Delay&lt;=0 && self.active==1) then
	self.size=self.size-5
end
if (self.size&lt;=0) then
	self.size=self.size*0
end
if (self.Delay==0 and self.active==1) then
	self:Remove()
end

for k, v in pairs(ents.FindInSphere(self:GetPos(), self.size*4.5)) do
	if v:IsPlayer() or v:IsNPC() then
		local damage = 1
		local attacker = self
		local inflictor = self
		v:TakeDamage( damage, attacker, inflictor )
	end
end

end[/lua]

[editline]12th September 2016[/editline]

Dragula, what is Delay supposed to do? I am guessing this thing is supposed to grow to a set size, stay there a for a moment, then reduce size and remove?

I dont think delay does anything in this code, you should use timers to remove the entity and for loop like this for the size


for Size = 1, 34 do
	print( Size )
end

ok, currently delay was supposed to do just that, i had it set to 1 for debugging purposes, even then it did not work

[editline]11th September 2016[/editline]

basically, i’m needind it to expand to a large size, stay at that size for about a second then shrink down to nothing then disappear, and anything within it gets damaged

[editline]11th September 2016[/editline]

Ok i think i figured something out, i think i have both of the same code in both the init AND cl_init, can you help me parse which goes where, please?

I’ve figured a small thing out, i’ve removed the materials and i can see the sphere i’m drawing, it’s staying there even after the delay and size supposedly hit 0

Anything else you figured out? This is really cool btw!