Jump to content
Joe98

How to make a command fire over and over again

Recommended Posts

I place myself on the map. I place one enemy on the map and I name him  enemy

I place a command in a trigger: 

enemy move getPos player; enemy setCombatMode "RED"

 

The enemy comes looking for me. This works for enemy men, vehicles and aircraft. They always finds me!

Except when I run away. Then they never find me.

I start at location A and move to location B and they never find me, because they think I am at the same location as I was when the trigger fired.

The solution is to have the trigger fire over and over and over again.

 

To do this, I place a man on a road in an out of the way place.  I use a cycle waypoint and he runs through the trigger, then turns and runs through the trigger over and over again!  Every time the trigger activates the command fires, every time the trigger deactivates the command fires. It works just great!

 

However I suspect it is inefficaint.

 

Is there another  way to get a command to fire over and over again?

.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

to get a trigger fire every half second you just have to set all options to none and the condition to true.

 

Other way would be to spawn a script with a loop...

  • Like 2

Share this post


Link to post
Share on other sites

 

 

11 hours ago, sarogahtyp said:

 

 

Other way would be to spawn a script with a loop...

 

 

Ok, how do I create a script with a loop. It should probably loop once per second.

 

Thank you

 

 

Share this post


Link to post
Share on other sites
11 hours ago, sarogahtyp said:

to get a trigger fire every half second you just have to set all options to none and the condition to true.

 

Other way would be to spawn a script with a loop...

I believe you also have to set the trigger to "Repeatable" for this to be the case.

Share this post


Link to post
Share on other sites
2 hours ago, itisnotlogical said:

I believe you also have to set the trigger to "Repeatable" for this to be the case.

 

Of course, but that can't work if you don't deactivate the trigger.

cond:          isNil "blabla"  (and certainly not just: true)

on act:       what you want ; blabla = true;

on deact:   0 = [] spawn {sleep 1; blabla = nil}

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, Joe98 said:

 

 

 

 

Ok, how do I create a script with a loop. It should probably loop once per second.

 

Thank you

 

 

 

_handle = [] spawn {
	while {true} do {
		//code
		sleep 1;
	};
};

https://community.bistudio.com/wiki/spawn and https://community.bistudio.com/wiki/while are what you need. But you'd be better off giving the AI a waypoint (one of the types that never completes) and moving the waypoint's position every 30 seconds or so.

Share this post


Link to post
Share on other sites
1 hour ago, beno_83au said:

 


_handle = [] spawn {
	while {true} do {
		//code
		sleep 1;
	};
};

 

 

OK but somewhere in there I have to place the two commands

 

enemy move getPos player; enemy setCombatMode "RED"

 

Where do I place the commands?    

.

 

 

 

 

 

Share this post


Link to post
Share on other sites

@Joe98,
Generally speaking this is my favorite type of loop,

Spoiler

waitUntil {sleep 1;
	if (_condition) then {};
	_condition
}

Which acts like a trigger.

Here is an outline for a loop which can do just about anything,


this spawn {
	private _doStuff = {systemChat format ["%1 is %2", name _this, lifeState _this]};
	waitUntil {
		sleep 1;
		if alive _this then _doStuff;
		!alive _this
	};
	systemChat format ["R.I.P. %1", name _this]
};

Chat the unit's name and life state until they are dead and bids fair adieu


Have fun!

  • Like 1

Share this post


Link to post
Share on other sites
5 hours ago, Joe98 said:

Where do I place the commands? 

 

_handle = [] spawn {
	while {true} do {
		//code <--- THIS INDICATES WHERE YOUR CODE SHOULD GO, MINUS THE SLASHES
		sleep 1;
	};
};

Therefore:

_handle = [] spawn {
	while {true} do {
		enemy move getPos player; 
		enemy setCombatMode "RED";
		sleep 1;
	};
};

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
On 8/5/2021 at 1:20 PM, sarogahtyp said:

to get a trigger fire every half second you just have to set all options to none and the condition to true.

 

Other way would be to spawn a script with a loop...

 

12 hours ago, pierremgi said:

Of course, but that can't work if you don't deactivate the trigger.

 

K, what I meant but not tested at this time was to set the Trigger Type to None, the Activation to None,  the Activation Type to Present,  and the condition to true. This works for sure but can not be achieved with Eden ... Its a scripting solution. therefore in Eden one has to do:

 

Trigger Type: None

Activation: None

Condition: true

OnActivation: 

thisTrigger setTriggerActivation [ "NONE","PRESENT", true ];
thisTrigger setTriggerStatements [ "systemChat (str time);", "", "" ];

this will write the current mission time every half second to system chat.

  • Like 1

Share this post


Link to post
Share on other sites
3 hours ago, sarogahtyp said:

 

 

K, what I meant but not tested at this time was to set the Trigger Type to None, the Activation to None,  the Activation Type to Present,  and the condition to true. This works for sure but can not be achieved with Eden ... Its a scripting solution. therefore in Eden one has to do:

 

Trigger Type: None

Activation: None

Condition: true

OnActivation: 


thisTrigger setTriggerActivation [ "NONE","PRESENT", true ];
thisTrigger setTriggerStatements [ "systemChat (str time);", "", "" ];

this will write the current mission time every half second to system chat.

 

As far as the on activation field is concerned, the trigger will not fire as a repetition. It will fire only once if you don't deactivate it.

In your statements, you are just checking that the condition is checked every 0.5 sec which is always the case (even if the trigger is not repeatable and activated, which is utterly useless imho).

 

Your code is same as an edited trigger with:     systemChat (str Time); TRUE 

as condition. It's also a good way for checking thisList in time (if any preset condition), before the trigger fires.
 

  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, pierremgi said:

Your code is same as an edited trigger with:     systemChat (str Time); TRUE 

as condition.

just true...

 

... even if its more like systemChat (str Time); nil

😉

Share this post


Link to post
Share on other sites
On 8/6/2021 at 5:03 PM, Harzach said:

 


_handle = [] spawn {
	while {true} do {
		enemy move getPos player; 
		enemy setCombatMode "RED";
		sleep 1;
	};
};

 

 

I changed the code above to read like this:

 

_handle = [] spawn {
    while {true} do {
        hint "ON ON ON";
        sleep 1;
    };
};

 

I confirm that the hint comes on and stays on.  I need the hint to come on for 5 seconds, turn off for 5 seconds and keep doing so over and over again.

 

How can I do that?

 

 

 

 

 

 

 

 

 

 

Share this post


Link to post
Share on other sites
1 hour ago, Joe98 said:

How can I do that?

 

Any new hint will override the previous one, so use

hintSilent "";

to "turn off" a currently displayed hint.

_handle = [] spawn {
    while {true} do {
        hint "ON ON ON";
        sleep 5;
        hintSilent "";
        sleep 5;
    };
};

Share this post


Link to post
Share on other sites
On 8/6/2021 at 5:03 PM, Harzach said:

 

Therefore:


_handle = [] spawn {
	while {true} do {
		enemy move getPos player; 
		enemy setCombatMode "RED";
		sleep 1;
	};
};

 

 

 

OK,  how do I get the above code,  to run, stop for 5 seconds, run again, over and over again.

The enemy fails to chase me.  Instead he runs to my starting location and then stops there.  So he needs a command to run to my current location.

.

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

that code runs every second already. if u need it to run every 5 seconds then just change sleep 1;  to sleep 5;

 

Edit:

and while we are on the subject it would be much better to not run that loop if player or enemy died already:

 

_handle = [] spawn {
	while {alive player and alive enemy} do {
		enemy move getPos player; 
		enemy setCombatMode "RED";
		sleep 1;
	};
};

 

  • Like 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×