Jump to content
Sign in to follow this  
clydefrog

How can I make this timer hint global?

Recommended Posts

Hi, I am using this timer in a script that is run from an action on an object. The problem is naturally it only displays for the client who runs the script as it's local. I have tried making a function and running that with BIS_fnc_MP but couldn't get it working properly. How can I do this? Here is the timer code:


_timeleft = 300;


while {true} do {

		hintsilent format ["Charge Explode in :%1", [((_timeleft)/60)+.01,"HH:MM"] call bis_fnc_timetostring];

	if (disarm) exitWith{};  // this is just checking for a variable that has been set true to indicate the disarm action has been used

if (_timeleft < 1) exitWith{};

 _timeleft = _timeleft -1;

sleep 1;

};

Thanks

Edited by clydefrog

Share this post


Link to post
Share on other sites

in your init.sqf

//Spawn script for all  
"FOCK_SpawnScriptEveryone" addPublicVariableEventHandler
 {
   private ["_forAll"];
((_this select 1) select 0) spawn ((_this select 1) select 1);
 };  

FOB_TIMER_FNC = 
{ 
           Private ["_Seconds","_Minutes","_picture"];
	_cacheTime = _this select 0;
	_cacheTimeTotal = _cacheTime / 60;
           _Seconds = 60;
           _Minutes = _cacheTimeTotal - 1;
           _picture = "img\clock.paa";

	TimerDone=false; publicVariable "TimerDone";

           While {!TimerDone} Do 
             {
                  _Seconds = _Seconds -1;
                  If ((_Seconds == 0) && (_Minutes > 0)) Then 

                    {
                        If (Player DisTance getmarkerpos "weapons" > 1) Then {hintSilent parseText format["<img size='1.5' image='%1'/> Cache setup Time Left %2:0%3",_picture,_Minutes, _Seconds]} Else {HintSilent ""};
                        sleep 1;
                       _Minutes = _Minutes - 1;
                       _Seconds = 59;

                    };

                     If (Player DisTance getmarkerpos "weapons" > 1) Then 
                      {                    
                         If (_Seconds >= 10) Then 

                              { 
                                hintSilent parseText format["<img size='1.5' image='%1'/> Cache setup Time Left %2:%3",_picture,_Minutes, _Seconds];                             
                              } 

                               Else 
                                   { 									     
                                     hintSilent parseText format["<img size='1.5' image='%1'/> Cache setup Time Left %2:0%3",_picture,_Minutes, _Seconds];
                                   };

                     }
                     Else
                     {
                       HintSilent "";
                     };

                                 If ((_Minutes == 0) && (_Seconds < 1)) ExitWith 
                                     	 {    
                                             TimerDone=True; publicVariable "TimerDone";
//                                              [nil,nil,rHint, "SecOps Mission has timed out"] call Re;
                                             Sleep 3;
                                             HintSilent "";

                                             ///Need to shut down the mission

                                           };
                      Sleep 1;

            };
       HintSilent ""; 
};

CacheTimer - is the time countdown

FOCK_SpawnScriptEveryone = [[CacheTimer],FOB_TIMER_FNC]; publicVariable "FOCK_SpawnScriptEveryone";
_cacheTimer = [CacheTimer] spawn FOB_TIMER_FNC;

Share this post


Link to post
Share on other sites

Thanks for the reply but I'm a bit confused by it really, it's completely different to the timer code I posted.

Share this post


Link to post
Share on other sites

FNC_Timer = {

_timeleft =  _this select 0;



while {true} do {

		hintsilent format ["Charge Explode in :%1", [((_timeleft)/60)+.01,"HH:MM"] call bis_fnc_timetostring];

	if (disarm) exitWith{};  // this is just checking for a variable that has been set true to indicate the disarm action has been used

if (_timeleft < 1) exitWith{};

 _timeleft = _timeleft -1;

sleep 1;

};
};

FOCK_SpawnScriptEveryone = [[300],FOB_TIMER_FNC]; publicVariable "FOCK_SpawnScriptEveryone";
_cacheTimer = [300] spawn FOB_TIMER_FNC;

Share this post


Link to post
Share on other sites

Cheers Mikey, I have the same problem I had before now which is after the timer reaches 0 and goes out of the loop it goes to this code:


//exit the script in the bombs been disarmed
if (disarm) exitWith{};

// charge explodes
"M_Mo_82mm_AT" createvehicle getpos _object;
{_x setdamage 1} foreach crew _object + [_object];
deleteVehicle _object;

but this all happens straight away when the timer starts as it's no longer waiting to come out of a loop before doing it. How can I make the script wait to do this until the timer has reached 0?

Share this post


Link to post
Share on other sites
Cheers Mikey, I have the same problem I had before now which is after the timer reaches 0 and goes out of the loop it goes to this code:


//exit the script in the bombs been disarmed
if (disarm) exitWith{};

// charge explodes
"M_Mo_82mm_AT" createvehicle getpos _object;
{_x setdamage 1} foreach crew _object + [_object];
deleteVehicle _object;

but this all happens straight away when the timer starts as it's no longer waiting to come out of a loop before doing it. How can I make the script wait to do this until the timer has reached 0?

could you post your complete code?

Share this post


Link to post
Share on other sites

_timeleft = 300;

while {true} do {

		hintsilent format ["Charge Explode in :%1", [((_timeleft)/60)+.01,"HH:MM"] call bis_fnc_timetostring];

	if (disarm) exitWith{};

if (_timeleft < 1) exitWith{};

 _timeleft = _timeleft -1;

sleep 1;

};

if (disarm) exitWith{};


"M_Mo_82mm_AT" createvehicle getpos _object;
{_x setdamage 1} foreach crew _object + [_object];
deleteVehicle _object;

and this is it with Mikeys suggestion



FOCK_SpawnScriptEveryone = [[300],FNC_Timer]; publicVariable "FOCK_SpawnScriptEveryone";
_cacheTimer = [300] spawn FNC_Timer;


if (disarm) exitWith{};


"M_Mo_82mm_AT" createvehicle getpos _object;
{_x setdamage 1} foreach crew _object + [_object];
deleteVehicle _object;

Share this post


Link to post
Share on other sites

What about:


_timeleft = 300;

while {_timeleft > 0} do {

           hintsilent format ["Charge Explode in :%1", [((_timeleft)/60)+.01,"HH:MM"] call bis_fnc_timetostring];

       if (disarm) exitWith{};

   if (_timeleft < 1) exitWith{};

 _timeleft = _timeleft -1;

sleep 1;

};

if (disarm) exitWith{};

if (_timeleft <= 0) then {

"M_Mo_82mm_AT" createvehicle getpos _object;
{_x setdamage 1} foreach crew _object + [_object];
deleteVehicle _object;  

};





Share this post


Link to post
Share on other sites
What about:


_timeleft = 300;

while {_timeleft > 0} do {

           hintsilent format ["Charge Explode in :%1", [((_timeleft)/60)+.01,"HH:MM"] call bis_fnc_timetostring];

       if (disarm) exitWith{};

   if (_timeleft < 1) exitWith{};

 _timeleft = _timeleft -1;

sleep 1;

};

if (disarm) exitWith{};

if (_timeleft <= 0) then {

"M_Mo_82mm_AT" createvehicle getpos _object;
{_x setdamage 1} foreach crew _object + [_object];
deleteVehicle _object;  

};





Cheers, the countdown stops at 00:00 though and then nothing happens.

Share this post


Link to post
Share on other sites

Hm, and if you put the check inside the loop?

_timeleft = 300;

while {_timeleft > 0} do {

           hintsilent format ["Charge Explode in :%1", [((_timeleft)/60)+.01,"HH:MM"] call bis_fnc_timetostring];

       if (disarm) exitWith{};

   if (_timeleft < 1) exitWith{};

 _timeleft = _timeleft -1;


if (_timeleft <= 0) then {

"M_Mo_82mm_AT" createvehicle getpos _object;
{_x setdamage 1} foreach crew _object + [_object];
deleteVehicle _object;  

};


sleep 1;

};

if (disarm) exitWith{};







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
Sign in to follow this  

×