Ent . Create *Advice/help*

Hi guys I need some advice with the subject of end.Create.

So let me try to explain to what I want to do, and see if anyone has any idea’s on it.

I have a Swep which when you fire it create a smoke entity. I have given it a timer. So when you run and hold it down the entity will only be there for 1 second. So we are creating a smoke screen gun I guess. But the issue is that when clients look at it they get lower or bad fps. So obviously this method works but it isn’t a very good way of doing it.

Does anyone know how you could make or do something like this but in an efficient way.

If you have any idea’s please post them and or give me links which may help.

Thanks.

-Duby

That’s because you are constantly spawning smoke, more than once.
If you are spawning it within’ SWEP:PrimaryAttack() then set SWEP.Primary.Automatic to false…

Also, post the code someday, we aren’t miracle workers and we won’t be able to tell what’s wrong unless you provide the freakin’ code…

[sp]damn it’s so warm in here, 29’C, my brain is boiling[/sp]

That still wouldn’t help as it needs to be a wall of smoke. Thats what I want to create but in an efficient way regarding to fps.

Less particles but with higher scale.

Also, are you even creating the effect using util.Effect() or just spawning smoke via ents.Create( ‘env_smoke’ )

via ents.Create( ‘env_smoke’ )

As I don’t know any other method.

That solves all the mystery…
And I bet you create more than 1 of it right?

Why don’t just create a custom effect? It’s really easy, fun and can be adjusted to your own needs.

Right yes that is what I am doing. So how do you do it? Can you give me an example some tips and links maybe?

Well, you can base off my smoke effect that I used for my sweps.


/*---------------------------------------------------------
Init
---------------------------------------------------------*/
function EFFECT:Init( data )
	local emitter = ParticleEmitter( data:GetOrigin() )
	self.weapon = data:GetEntity()
	self.attachment = data:GetAttachment()
	self.pos = self:GetTracerShootPos( data:GetOrigin(), self.weapon, self.attachment )

	local heat = emitter:Add( "sprites/heatwave", self.pos )
	if ( heat ) then
		heat:SetVelocity( VectorRand() )
		heat:SetLifeTime( 0 )
		heat:SetDieTime( 0.25 )
		heat:SetStartAlpha( 255 )
		heat:SetAirResistance( 160 )
		heat:SetEndAlpha( 0 )
		heat:SetStartSize( 25 )
		heat:SetEndSize( 10 )
		heat:SetGravity( Vector( 0, 0, 100 ) )
	end
	for i = 1, 2 do
		local smoke = emitter:Add( "particle/particle_smokegrenade", self.pos )
		if ( smoke ) then
			smoke:SetVelocity( Vector( math.Rand( -20, 20 ), math.Rand( -20, 20 ), 22 ) )
			smoke:SetLifeTime( 0 )
			smoke:SetDieTime( 2 )
			smoke:SetColor( 75, 75, 75 )
			smoke:SetStartAlpha( 255 )
			smoke:SetEndAlpha( 0 )
			smoke:SetStartSize( 2 )
			smoke:SetEndSize( 55 )
			smoke:SetRoll( math.Rand( 180, 480 ) )
			smoke:SetGravity( Vector( 0, 0, 55 ) )
			smoke:SetCollide( false )
			smoke:SetBounce( 0.45 )
		end
	end
	local muzzleflash = emitter:Add( "effects/muzzleflash" .. math.random( 1, 4 ), self.pos )
	muzzleflash:SetVelocity( Vector( 0, 0, 0 ) )
	muzzleflash:SetGravity( Vector( 0, 0, 0 ) )
	muzzleflash:SetDieTime( 0.1 )
	muzzleflash:SetStartAlpha( 150 )
	muzzleflash:SetStartSize( 15 )
	muzzleflash:SetEndSize( 0 )
	muzzleflash:SetRoll( math.Rand( 180, 480 ) )
	muzzleflash:SetRollDelta( math.Rand( -1, 1 ) )
	muzzleflash:SetColor( 255, 255, 255 )

	emitter:Finish()
end

function EFFECT:Think( )
	return false
end

/*---------------------------------------------------------
Render
---------------------------------------------------------*/
function EFFECT:Render()
end

Hmm right this works form a ini.t file. SO I’d just include this in the shared file? ‘Shared file contains all of the other things in the SWEP.’ Also in the primary attack function how would I go about calling this? Would it be the same as the end.Create but slightly modified?

First of all, its ents.Create(), not end.Create.
And effects go to lua/entities/effects or lua/effects and can be called via:



	local e = EffectData()
	e:SetOrigin( self.Owner:GetShootPos() )
	util.Effect( "grp_weaponeffect", e )

Ofcourse the above thing is just an example

Hmm right I will have a fiddle with this. Thanks for the help!

[editline]21st May 2014[/editline]

Hmmm I am using this code to produce this particle entity. But I don’t what to call upon when you create the actual entity. here is what I have got.




for i=1, 8 do
	--	local ent = ents.Create("env_smoketrail")
		local ent = ents.Create("")
	--	local ent = ents.Create("particle/particle_smokegrenade")
		
		
		if ent:IsValid() then
			local heading = (aimvec + VectorRand() * 0.2):GetNormal()
			local heading = (aimvec + VectorRand() * 1.2):GetNormal()
			ent:SetPos(startpos + heading * 8)
			ent:SetOwner(pl)
			ent:Spawn()
			ent.TeamID = pl:Team()	
			
			local phys = ent:GetPhysicsObject()
			ent:SetPhysicsAttacker(pl)
	end
	
	--timer.Simple(0.01, function()
	--ent:Remove()
--	end)
		
	end



Oh, man.
Why are you creating non existant entity 8 times?
It’s like you completely ignored what I said.

Here is what you do:
-First you create a folder in lua/effects named my_sexy_effect.
-Inside this folder make an init.lua file
-Inside that file TRY to make an effect following the thing I posted above, it’s a nice smoke use it to see if it works and modify it later
-Inside SWEPs functions (SWEP:PrimaryAttack) put this part of code:


local e = EffectData()
e:SetPos( self.Owner:GetShootPos() )
e:SetOrigin( self.Owner:GetShootPos() )
util.Effect( "my_sexy_effect", e )

-Remember to have SWEP.Primary.Automatic set to false otherwise you’ll spam a lot.

I am having an issue with this code. It says that the SetPos is a nil value. I don’t quite understand why. Please forgive my noobyness I am new to this effect concept.

Then get rid of SetPos(), I think SetOrigin() will be enough.

Ah perfect! Thankyou very much!! I have learnt a lot today! :slight_smile: