I've just barely begun coding lua, and I have created an explosion/firework clientside script (from a tutorial of course). And then a entity that will explode using this clientside effect. How would I achieve this? It won't let me call it because ones global and the others clientside.
Here is the clientside explosion (placed in autorun/client):
[CODE]function firework(Pos)
local emi = ParticleEmitter(Pos)
for i=1, 300 do
local parti = emi:Add("Sprites/light_glow02_add", trace)
if parti then
parti:SetColor(math.random(30,255),math.random(30,255),math.random(30,255),math.random(30,255))
parti:SetVelocity(Vector(math.random(-1000,1000),math.random(-1000,1000),math.random(-1000,1000)):GetNormal() * 1000)
parti:SetDieTime(3)
parti:SetLifeTime(0)
parti:SetStartSize(200)
parti:SetEndSize(0)
end
end
emi:Finish()
end[/CODE]And heres the entitys init.lua:
[CODE]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
function ENT:SpawnFunction(ply, tr)
if (!tr.Hit) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 16
local ent = ents.Create("bomb")
ent:SetPos(SpawnPos)
ent:Spawn()
ent:Activate()
ent:SetName("Bomb")
return ent
end
function ENT:Use(activator, ply)
end
function ENT:Think()
end
function ENT:OnRemove()
end
function ENT:OnTakeDamage(dmg)
firework(self.Entity:GetPos())
util.BlastDamage(self.Entity, self.Entity, self.Entity:GetPos(), 100, 10)
local effectdata = EffectData()
effectdata:SetOrigin( self.Entity:GetPos() )
util.Effect( "Explosion", effectdata, true, true )
self.Entity:Remove()
end
function ENT:Initialize()
self.Entity:SetModel("models/Combine_Helicopter/helicopter_bomb01.mdl")
self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
self.Entity:SetSolid(SOLID_VPHYSICS)
local phys = self.Entity:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end
end[/CODE]Sorry if I'm vague or don't make sense i have to go to school so bye.
Any advice or help is appreciated.
When do you want it to explode?
Doesn't matter, I just want it to create the clientside effect when it does.
[CODE]function ENT:OnTakeDamage(dmg)
self:CallOnClient("firework", self.Entity:GetPos())
util.BlastDamage(self.Entity, self.Entity, self.Entity:GetPos(), 100, 10)
local effectdata = EffectData()
effectdata:SetOrigin( self.Entity:GetPos() )
util.Effect( "Explosion", effectdata, true, true )
self.Entity:Remove()
end
function ENT:firework(Pos)
local emi = ParticleEmitter(Pos)
for i=1, 300 do
local parti = emi:Add("Sprites/light_glow02_add", trace)
if parti then
parti:SetColor(math.random(30,255),math.random(30,255),math.random(30,255),math.random(30,255))
parti:SetVelocity(Vector(math.random(-1000,1000),math.random(-1000,1000),math.random(-1000,1000)):GetNormal() * 1000)
parti:SetDieTime(3)
parti:SetLifeTime(0)
parti:SetStartSize(200)
parti:SetEndSize(0)
end
end
emi:Finish()
end[/CODE]I put that in the entity's init.lua, just comes up with
entities/bomb/init.lua:28: attempt to call method 'CallOnClient' (a nil value)
I didn't experiment with it much but this looks like what i need.
Doesn't look like it's for entities though :x
Appart from a number of flaws in your implementation you are right, this seems to be only for sweps.
You could send an usermessahe to clients telling them to trigger it. Remember that all of your explosion code must be on a file the client will have.
Sorry, you need to Log In to post a reply to this thread.