Hello everyone
So this is a little thing I have wanted to do for a while and now I finally got it everything I need and got it working so I want to share it with the forum.
So this is an Emergency flare that spawns on a script area that will light up areas for you but will burn out after a certain amount of time which makes it an alternate portable light source that has some dynamics in it
Picture of it in action
This package comes with a Flare model, Flare sound and some burning flare particles. And if you want to use it you need to place each folder in it's certain category. Flare goes in to Entities, Flare_sound to sound folder and flare_particles goes into the particle folder (remember to add these components to your CS folder if you are going to use it
Here's the code to make it work
Put this code inside void OnStart()
SpawnFlareAtArea("EmergencyFlare", "SpawnFlare", 0.79f);
So I'm going to break down this code so you can change it yourself.
EmergencyFlare: is the name of the Flare (it's not that relevant so just keep it.)
SpawnFlare: is the name of the Script Area you want to spawn the flare.
0.79f: is the Burn Time for the Flare, you can change it to what ever you want (Remember that the higher the number is the longer it will burn and right now it burns for around 1 minute)
Here's the rest of the code that you just have to copy and paste in to your .hps
//////////////////////////
//Emergency Flare Script//
const string _FlareOBJ = "Flare.ent";
void SpawnFlareAtArea(string &in flareName, string &in areaTarget, float burnTime)
{
CreateEntityAtArea(flareName, _FlareOBJ, areaTarget, true);
SetLocalVarFloat(flareName+"_time", burnTime >= 1.0f ? 0.999f : burnTime);
SetEntityPlayerInteractCallback(flareName, "InteractFlare", true);
AddDebugMessage("Flare Spawned", true);
}
void InteractFlare(string &in entity)
{
CreateParticleSystemAtEntity("PFlare", "ps_flare_sparkles", entity, false);
FadeLightTo(entity+"_FlareLight", 1.0f, 0.1f, 0.0f, 0.7f, -1, 1.5f);
PlaySoundAtEntity("SFlare", "flare_loop.snt", entity, 1, false);
BurnLoop(entity);
AddDebugMessage("Picked :" +entity, true);
}
void BurnLoop(string &in timer)
{
if(GetLocalVarFloat(timer+"_time") <= 0.0f)
{
StopFlareParticles("PFlare", "SFlare");
return;
}
AddLocalVarFloat(timer+"_time", -0.00035f);
AddTimer(timer, 0.0166f, "BurnLoop");
AddDebugMessage("Time: "+GetLocalVarFloat(timer+"_time"), false);
}
void StopFlareParticles(string &in ParticleName, string &in SoundName)
{
DestroyParticleSystem(ParticleName);
StopSound(SoundName, 1.5f);
FadeLightTo("EmergencyFlare"+"_FlareLight", 0, 0, 0, 0, -1, 1);
}
//End Flare Script//
/////////////////////
If you have any questions feel free to ask them and I will be glad to answer
CREDIT
Traggey for making me the Flare model (since my own sucked x))
DarkAdders for making the particles system for the flare (also since my own sucked)
Palistov for the source and gave me the inspiration and knowledge to do this
Frictional Games for making the Flare sound (it's from penumbra)
DOWNLOAD V1.1
Updated it by changing side of the flare so it don't collide with the lantern