| 
		
	
		| ooadrianoo   Member
 
 Posts: 82
 Threads: 29
 Joined: Apr 2012
 Reputation: 
0
 | 
			| Need help with hazards 
 
				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:
 void OnStart(){
 int iBarrel = RandFloat(1, 6);
 
 
 
 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_" +iBarrel, false);
 AddTimer("remove_barrel", 5, "Remove_Barrel_Timer");
 }
 }
 
Can anyone tell me, that I have done false?
			 |  |  
	| 09-22-2012, 01:55 AM |  |  
	
		| Adny   Posting Freak
 
 Posts: 1,766
 Threads: 6
 Joined: Mar 2012
 Reputation: 
173
 | 
			| RE: Need help with hazards 
 
				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!
 
 I rate it 3 memes. |  |  
	| 09-22-2012, 02:02 AM |  |  
	
		| Your Computer   SCAN ME!
 
 Posts: 3,456
 Threads: 32
 Joined: Jul 2011
 Reputation: 
235
 | 
			| RE: Need help with hazards 
 
				You declared iBarrel locally, but tried to access it as if it were declared in the global scope.
			 
 |  |  
	| 09-22-2012, 02:03 AM |  |  
	
		| ooadrianoo   Member
 
 Posts: 82
 Threads: 29
 Joined: Apr 2012
 Reputation: 
0
 | 
			| RE: Need help with hazards 
 
				Please can you post a right script?
 I come from Germany so I can't understand everything you write.
 |  |  
	| 09-22-2012, 02:05 AM |  |  
	
		| Your Computer   SCAN ME!
 
 Posts: 3,456
 Threads: 32
 Joined: Jul 2011
 Reputation: 
235
 | 
			| RE: Need help with hazards 
 
				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: void OnStart(){
 AddTimer("barrel_"+RandInt(1, 6), 1, "ActivateBarrel");
 }
 
 void ActivateBarrel(string &in barrel)
 {
 SetEntityActive(barrel, true);
 AddTimer(barrel, 2, "RemoveBarrel");
 }
 
 void RemoveBarrel(string &in barrel)
 {
 SetEntityActive(barrel, false);
 }
 
 
				
(This post was last modified: 09-22-2012, 02:17 AM by Your Computer.)
 |  |  
	| 09-22-2012, 02:16 AM |  |  
	
		| ooadrianoo   Member
 
 Posts: 82
 Threads: 29
 Joined: Apr 2012
 Reputation: 
0
 | 
			| RE: Need help with hazards 
 
				 (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:
 
 void OnStart(){
 AddTimer("barrel_"+RandInt(1, 6), 1, "ActivateBarrel");
 }
 
 void ActivateBarrel(string &in barrel)
 {
 SetEntityActive(barrel, true);
 AddTimer(barrel, 2, "RemoveBarrel");
 }
 
 void RemoveBarrel(string &in barrel)
 {
 SetEntityActive(barrel, false);
 }
 
 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.
 |  |  
	| 09-22-2012, 09:44 AM |  |  
	
		| WALP   Posting Freak
 
 Posts: 1,221
 Threads: 34
 Joined: Aug 2012
 Reputation: 
45
 | 
			| RE: Need help with hazards 
 
				barrels?, I sense a pewdiepie themed custom story here.just saying
 |  |  
	| 09-22-2012, 10:24 AM |  |  |