Frictional Games Forum (read-only)

Full Version: Need help with hazards
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is my first contacts with hazards.
There are 5 barrels. The barrels should be spawn randomly, and should removed randomly.
Here is my script:
PHP Code:
void OnStart()
{
int iBarrel RandFloat(16);



AddTimer("remove_barrel"2"Remove_Barrel_Timer");

AddTimer("barrel"1"BarrelTimer");
}

void BarrelTimer(string &in asTimer)
{
SetEntityActive("barrel_" +iBarrel true);
AddTimer("barrel"3"BarrelTimer");
}



void Remove_Barrel_Timer(string &in asTimer)
{
if (
GetEntityExists("barrel_" +iBarrel) == true)
{
SetEntityActive("barrel_" +iBarrelfalse);
AddTimer("remove_barrel"5"Remove_Barrel_Timer");
}


Can anyone tell me, that I have done false?
Try RandInt instead of RandFloat; The game is generating a random decimal between 1 & 6, but I'm assuming the names of the barrels in the level editor (that you're trying to set active) are just integers (i.e. "barrel_1", not "barrel_1.241")

Scripting isn't my cup of tea, but I hope that helped!
You declared iBarrel locally, but tried to access it as if it were declared in the global scope.
Please can you post a right script?

I come from Germany so I can't understand everything you write.
You don't explain much in what exactly you're trying to achieve, nor does your code allow me to make safe assumptions. Nevertheless, i'd rewrite your code like so:

PHP Code:
void OnStart()
{
    
AddTimer("barrel_"+RandInt(16), 1"ActivateBarrel");
}

void ActivateBarrel(string &in barrel)
{
    
SetEntityActive(barreltrue);
    
AddTimer(barrel2"RemoveBarrel");
}

void RemoveBarrel(string &in barrel)
{
    
SetEntityActive(barrelfalse);

(09-22-2012, 02:16 AM)Your Computer Wrote: [ -> ]You don't explain much in what exactly you're trying to achieve, nor does your code allow me to make safe assumptions. Nevertheless, i'd rewrite your code like so:

PHP Code:
void OnStart()
{
    
AddTimer("barrel_"+RandInt(16), 1"ActivateBarrel");
}

void ActivateBarrel(string &in barrel)
{
    
SetEntityActive(barreltrue);
    
AddTimer(barrel2"RemoveBarrel");
}

void RemoveBarrel(string &in barrel)
{
    
SetEntityActive(barrelfalse);



I just wanted to set random barrels active. So if they is a barrel active (checked by GetEntityExists), then this barrel should be deactivated in a few seconds.

This process should not stop.
barrels?, I sense a pewdiepie themed custom story here.
just saying