• Why my sent doesn't spawn and have valid physobj?
    3 replies, posted
Hey, I'm trying to make my sent work but it doesn't have valid physobj when I'm trying to spawn it in my swep. However it has valid physobj on it's ENT:Initialize function. Also, the whole sent doesn't even appear. I'm not getting any errors in console. Part of my swep where I'm trying to create the sent: [lua] function ENT:SpawnCluster() local beep = Sound ("weapons/grenade/tick1.wav") if (self.Entity and self.Entity:IsValid()) then self.Entity:EmitSound(beep) end timer.Simple(0.2, function() if (self.Entity and self.Entity:IsValid()) then self.Entity:EmitSound(beep) end end) timer.Simple(0.4, function() if (self.Entity and self.Entity:IsValid()) then self.Entity:EmitSound(beep) end end) timer.Simple(0.6, function() if (self.Entity and self.Entity:IsValid()) then if (!SERVER) then return end local speedtable={} --I have no clue if these work like I want... speedtable[1] = Angle(285, 72, 0) speedtable[2] = Angle(285, 144, 0) speedtable[3] = Angle(285, 216, 0) speedtable[4] = Angle(285, 288, 0) speedtable[5] = Angle(285, 0, 0) for i=1, 5 do local cluster = ents.Create("sent_cluster") if (cluster:IsValid()) then --cluster:SetPos(self.Entity:GetPos():GetNormal() * -16) cluster:SetPos(self.Entity:GetOwner():GetPos()) --debug cluster:SetAngles(speedtable[i]) print(tostring(speedtable[i])) --debug print("cluster tehty") --debug local phys = cluster:GetPhysicsObject() print(tostring(phys)) --debug if (phys:IsValid()) then -- PHYS IS NOT VALID HERE! WHY? phys:ApplyForceCenter(speedtable[i]:Forward() * 2000) print("clusterin speed laitettu") --debug else print("phys is not valid") --debug end local clusterit = ents.FindInSphere( cluster:GetPos(), 10 ) for key, sent in pairs(clusterit) do constraint.NoCollide(cluster, sent, 0, 0) end end end end end) end [/lua] sent_cluster whole init.lua: (cl_init.lua and shared.lua are completely fine) [lua] AddCSLuaFile( "cl_init.lua" ) -- Make sure clientside AddCSLuaFile( "shared.lua" ) -- and shared scripts are sent. include('shared.lua') function ENT:Initialize() self.Entity:SetModel( "models/props_lab/jar01b.mdl" ) self.Entity:SetMaterial("models/debug/debugwhite") self.Entity:SetColor(0,0,0,255) self.Entity:PhysicsInit( SOLID_VPHYSICS ) -- Make us work with physics, self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) -- after all, gmod is a physics self.Entity:SetSolid( SOLID_VPHYSICS ) self.Entity:Spawn() self.Entity:Activate() self.Entity:SpawnTrail() local phys = self.Entity:GetPhysicsObject() if (phys:IsValid()) then -- PHYS IS ACTUALLY VALID HERE! phys:Wake() else print("PHYS IS NOT VALIIIIIID") end local beep = Sound ("weapons/grenade/tick1.wav") self.Entity:SpawnTrail() end function ENT:PhysicsCollide( data, physobj ) self.Entity:Explode() end function ENT:Explode() if (ValidEntity(self.Entity)) then util.BlastDamage(self.Entity, self.Entity, self.Entity:GetPos(), 100, 100) end end function ENT:SpawnTrail() if (ValidEntity(self.Entity)) then util.SpriteTrail(self.Entity, 0, Color(187,0,255,255), false, 20, 0, 10, 1/(20+0)*0.5, "trails/laser") end end function ENT:Use( activator, caller ) return end function ENT:Think() return --self.Entity:NextThink( CurTime() + 0.1) --return true end [/lua]
Because you did not spawn and activate the cluster before getting the PhysObj? I don't think it'll work if you put it in the ENT:Initialize(), but I might be mistaken. Just try putting in cluster:Spawn() cluster:Activate().
[QUOTE=Entoros;19515515]Because you did not spawn and activate the cluster before getting the PhysObj? I don't think it'll work if you put it in the ENT:Initialize(), but I might be mistaken. Just try putting in cluster:Spawn() cluster:Activate().[/QUOTE] You never need activate on lua sents, unless you actually define the function yourself with ENT:Ativate() It is only used by some HL2 entities. But he is right I don't see where you call cluster:Spawn() Also putting self:Spawn() in initialize is likely to cause an infinite loop. Seeing as that is the function Spawn() calls.
Thank you both! That worked.
Sorry, you need to Log In to post a reply to this thread.