/* * Author: Needles * https://steamcommunity.com/profiles/76561198026257137/ */ ::Debug.Print("*** PARTICLE"); ::Particle <- {}; ::Particle.SCOPE_KEY <- UniqueString(); ::Particle.ParticleAttachment <- class { self = null; effectList = null; constructor(_self) { self = _self; effectList = []; } function AddEffect(name) { if (self == null || self.IsValid() == false) return; if (effectList.find(name) != null) return; ::Particle.AttachEffect(self, name); effectList.append(name); } function RemoveEffect(name) { if (self == null || self.IsValid() == false) return; local index = effectList.find(name); if (index == null) return; EntFireByHandle(self, "DispatchEffect", "ParticleEffectStop", -1.0, null, null); effectList.remove(index); foreach (name in effectList) { ::Particle.AttachEffect(self, name); } } function RemoveAll() { if (self == null || self.IsValid() == false) return; EntFireByHandle(self, "DispatchEffect", "ParticleEffectStop", -1.0, null, null); effectList.clear(); } } function Particle::Validate(entity) { if (entity == null || entity.IsValid() == false || entity.ValidateScriptScope() == false) return null; if (::Particle.SCOPE_KEY in entity.GetScriptScope()) return entity.GetScriptScope()[::Particle.SCOPE_KEY]; local particleAttachment = ::Particle.ParticleAttachment(entity); entity.GetScriptScope()[::Particle.SCOPE_KEY] <- particleAttachment; return particleAttachment; } function Particle::PrecacheEffect(name) { PrecacheEntityFromTable({ classname = "info_particle_system", effect_name = name }) } function Particle::AttachEffect(entity, name) { if (entity == null || entity.IsValid() == false) return; local ent_particle = SpawnEntityFromTable("trigger_particle", { particle_name = name, attachment_type = 1, // PATTACH_ABSORIGIN_FOLLOW, spawnflags = 64, // allow everything }); EntFireByHandle(ent_particle, "starttouch", "!activator", -1.0, entity, entity); EntFireByHandle(ent_particle, "Kill", "", -1.0, null, null); }