• Attaching Entity that is a particle attached to an entity?
    9 replies, posted
code: function jobFx(ply)     if ply:Team() == TEAM_GUN then         local ent = ents.Create("mr_effect10")         ent:SetParent(ply, 3)         ent:Spawn()         end     end hook.Add("PlayerSpawn", "applyFx", jobFx ) Entity Code: AddCSLuaFile() ENT.Type             = "anim" ENT.Base             = "base_anim" ENT.PrintName        = "Steam 1" ENT.Author            = "Bombobux" ENT.Information        = "" ENT.Category        = "Placeable Effects" ENT.Spawnable        = true ENT.AdminOnly        = false if SERVER then function ENT:Initialize()          self:SetModel("models/Items/AR2_Grenade.mdl")     self:SetNoDraw(true)     self:DrawShadow(false)     self:PhysicsInit( SOLID_VPHYSICS )     self:SetMoveType( MOVETYPE_VPHYSICS )     self:SetSolid( SOLID_VPHYSICS )         ParticleEffectAttach( "mr_gas_leak_01", 1, self, 1 ) end end All I'm trying to do is attach the entity "mr_effect10" (class of the entity) to the player. This works if I do so with ParticleEffectAttach, however, because the particle system (library from gmod wiki) is so absolute regarding position of the particle, I find it difficult to position it correctly. Any advice would be appreciated.
I figured it out, mostly: function jobFx(ply) if ply:Team() != TEAM_GK then return end     if ply:Team() == TEAM_GK then         local ent = ents.Create("mr_effect13")         --local pos = ply:LocalToWorld(Vector(0,0,0), Angle(0,0,0))         local bpos = ply:GetBonePosition(10)         ent:FollowBone(ply,10)         ent:SetPos(bpos)         ent:Spawn()         end     end hook.Add("OnPlayerChangedTeam", "applyFx", jobFx ) I get an error that "Create" is null but it still does what it's supposed to (applies the entity to the player bone for that job).
ents.Create is serverside only.
I forgot I changed the name of the file to sh_ thank you!
function jobFx(ply) if ply:Team() != TEAM_GK then return end if ply:Team() == TEAM_GK then local ent = ents.Create("mr_effect13") --local pos = ply:LocalToWorld(Vector(0,0,0), Angle(0,0,0)) local bpos = ply:GetBonePosition(10) ent:FollowBone(ply,10) ent:SetPos(bpos) ent:Spawn() end end hook.Add("OnPlayerChangedTeam", "applyFx", jobFx ) Can anyone tell me why this code prevents the player from switching jobs? The notification that the job has been switched displays but the player doesn't respawn. I have to respawn as the job again for the code to work.
Can someone lend me their expertise? I have tried countless variations of this code and the behavior is all the same - either the entity spawns correctly the first time then gets removed (as it should) with the change of a job and then errors saying that the entity isn't null or The entity spawns as it should but isn't removed when I switch to the next job: function jobFx(ply) entfx_1 = ents.Create("mr_effect13")     bpos = ply:LocalToWorld(Vector(0,20,46))             entfx_1:FollowBone(ply,10)             entfx_1:SetPos(bpos) if ply:getDarkRPVar("job", "Gatekeeper") && entfx_1 != NULL then entfx_1:Spawn() elseif entfx_1 != NULL then entfx_1:Remove() end     end hook.Add("PlayerSpawn", "applyFx", jobFx ) I call the function on PlayerSpawn because the player has to respawn every time they switch jobs, I've also tried OnPlayerChangedTeam I've also tried various methods of "if ply:Team() != TEAM_GK" etc. The goal: to attach an entity to a player if they match a certain job, to remove it if they change to a different job, and not to call the remove function again if the entity has already been removed. I'll throw an extra 10 coins on if someone can help.
you can hook OnPlayerChangedTeam to figure out when a player is changing teams and what team hes changing to. make sure that when you create the effect entity you store it to some variable preferably stored on the player for future use such as removal. im not sure if the hook is always called when the players team changes though hook.Add( "OnPlayerChangedTeam", "blah", function( ply, old, new ) if new == TEAM_EFFECT and !IsValid( ply.EffectEnt ) then ply.EffectEnt = ents.Create( "effect_ent" ) else ply.EffectEnt:Remove( ) end end )
That seems to be working for now I had to add another validity check at the end and check the old team. Would you, or anyone know how to get a player's bone position localtoworld?
clientside or serverside? in general i know bones are really fucky to deal with, I try to stay away from them.
I was doing this to try and get the vector for the bone localtoworld but ply.Fx6:SetPos(ply:GetBonePosition(2)) ended up working just fine for what I was trying to do - which is odd because I could've swore I did this before for SetPos and Vector was nill, but now it's not. So :shrug:
Sorry, you need to Log In to post a reply to this thread.