Page 1 of 1

delay in events

Posted: Sat Jan 07, 2017 1:35 pm
by TAW_legitscoper
Hello, I have a problem in creating my map. I want to make gun burst for let's say, 20 bullets and wait some time. Here is script:

Code: Select all

public void Timer(TriggerArgs args)
{

}

public void turret(TriggerArgs args){
	for(int i = 0; i < 20;i++)
	{
	IObject obj = Game.GetSingleObjectByCustomId("start");
	IObject objDir = Game.GetSingleObjectByCustomId("end");
	Vector2 pos = obj.GetWorldPosition();
	Vector2 dir = objDir.GetWorldPosition();
	Game.SpawnProjectile(ProjectileItem.M60, pos, dir - pos);

	}
	
}
public void turret2(TriggerArgs args){
	IObject obj = Game.GetSingleObjectByCustomId("start");
	IObject objDir = Game.GetSingleObjectByCustomId("end");
	Vector2 pos = obj.GetWorldPosition();
	Vector2 dir = objDir.GetWorldPosition();
	Game.SpawnProjectile(ProjectileItem.BAZOOKA, pos, dir - pos);
	
}
problem is that the gun is firing continous. turret and turrer2 are timers.

Re: delay in events

Posted: Sat Jan 07, 2017 3:06 pm
by Voven
TAW_legitscoper wrote:Hello, I have a problem in creating my map. I want to make gun burst for let's say, 20 bullets and wait some time. Here is script:

Code: Select all

public void Timer(TriggerArgs args)
{

}

public void turret(TriggerArgs args){
	for(int i = 0; i < 20;i++)
	{
	IObject obj = Game.GetSingleObjectByCustomId("start");
	IObject objDir = Game.GetSingleObjectByCustomId("end");
	Vector2 pos = obj.GetWorldPosition();
	Vector2 dir = objDir.GetWorldPosition();
	Game.SpawnProjectile(ProjectileItem.M60, pos, dir - pos);

	}
	
}
public void turret2(TriggerArgs args){
	IObject obj = Game.GetSingleObjectByCustomId("start");
	IObject objDir = Game.GetSingleObjectByCustomId("end");
	Vector2 pos = obj.GetWorldPosition();
	Vector2 dir = objDir.GetWorldPosition();
	Game.SpawnProjectile(ProjectileItem.BAZOOKA, pos, dir - pos);
	
}
problem is that the gun is firing continous. turret and turrer2 are timers.
I guess your timer's interval time is really low. Try to set it with more time, like 5.000-10.000ms.
Hope it works.

Re: delay in events

Posted: Sat Jan 07, 2017 5:03 pm
by TAW_legitscoper
OK, but now it fires one bullet and waits that 5 seconds. Or for loop isn't working. Is there any way to delay that loop, like Delay(10); or something that exist

Added in 55 minutes 5 seconds:
I figured it out. It was simpler than I thought. I just placed second timer, gave it 5000ms delay, activate on startup and activate turret timer. For turret timer I set repeat to 20, don't activate on startup and interval to 30ms

Re: delay in events

Posted: Sat Jan 07, 2017 6:52 pm
by gwendalaze
remove the loop, just make sure the timer trigger repeat every ~200