Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

delay in events

Here you can find answered ScriptAPI topics.
Forum rules
By using the forum you agree to the following rules.
Post Reply
TAW_legitscoper
Meatbag
Posts: 2
Joined: Sat Jan 07, 2017 1:32 pm
SFD Account: TAW_legitscoper

delay in events

Post by TAW_legitscoper » Sat Jan 07, 2017 1:35 pm

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.
0 x

Voven
Meatbag
Posts: 3
Joined: Thu Jan 05, 2017 8:30 pm
SFD Account: Voven
Started SFD: Alpha 1.0.0
Location: Iceland
Gender:

Post by Voven » Sat Jan 07, 2017 3:06 pm

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.
0 x
- Voven

TAW_legitscoper
Meatbag
Posts: 2
Joined: Sat Jan 07, 2017 1:32 pm
SFD Account: TAW_legitscoper

Post by TAW_legitscoper » Sat Jan 07, 2017 5:03 pm

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
0 x

User avatar
gwendalaze
Superfighter
Superfighter
Posts: 84
Joined: Sat Mar 19, 2016 12:55 pm
Title: Jarate Yellow Belt
Started SFD: PreAlpha 1.1.4
Location: France

Post by gwendalaze » Sat Jan 07, 2017 6:52 pm

remove the loop, just make sure the timer trigger repeat every ~200
0 x
- Gwendalaze, failing at being fun, just like this signature

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests