Jump to content
macusercom

Help with timer script for explosion

Recommended Posts

I'd need a little help with a script. After _time is 0 it should execute:

_bomb = "R_60mm_HE" createVehicle (getPos XYZ);
XYZ setDamage 1;

I have this script called with a value of 60 seconds:

private "_time";
_time = _this select 0;

while {_time > 0} do {
	_time = _time - 1;  
	hintSilent format["Time left: \n %1", [((_time)/60)+.01,"HH:MM"] call BIS_fnc_timetostring];	
	sleep 1;
};

I know this is a pretty basic question but I've been trying to do this for an hour and I cannot seem to get it working. Thanks in advance!  :)

Share this post


Link to post
Share on other sites

Are you literally calling this script? With sleep inside the script you should rather spawn it instead.

I guess _time is declared as simple number? like n in seconds?

n = 10;
_boom = [n] spawn {
params ["_time"];
while {time < time + _time} do {
hintSilent format["Time left: \n %1", [((_time)/60)+.01,"HH:MM"] call BIS_fnc_timetostring];
_time = _time - 1;
sleep 1;
};
_bomb = "R_60mm_HE" createVehicle (getPos XYZ);
XYZ setDamage 1;
hint "Boom.";
};

Will show the hint for n seconds, counting down each second, triggering the explosion when n is equal to 0.

Didn't try it but should work non the less.

 

Cheers

Share this post


Link to post
Share on other sites

Seems like a strange way to do it, why not...
 

To execute: Also never use call with anything that has a waituntil, sleep, or any type of delay in it, only ever use spawn or execVM

[10] execVM "bang.sqf";

bang.sqf


_delay = _this select 0;
_time = time;

waituntil {time > _time + _delay};

_bomb = "R_60mm_HE" createVehicle (getPos XYZ);
XYZ setDamage 1;

Not tested but I do this all the time. That code should wait 10 seconds, with no hints, and then boom. Hints cant be added to that with a loop which I can demonstrate if you need.

Share this post


Link to post
Share on other sites

Well, it worked just fine. Sorry for the late answer. You helped me out a lot! :)

 

But still @MKD3 how to add hints without a loop (especially the countdown)?

Share this post


Link to post
Share on other sites


        _counter = 15;

        while {_counter > 0} do {

    

            hintSilent format ["Time to explosion %1", _counter];

            playsound "FD_Timer_F";

            _counter = _counter - 1;

            sleep 1;

            

        };

Share this post


Link to post
Share on other sites

Sorry, I meant with a loop (typo), and davidoss here has got it sorted for you.

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

×