Jump to content
Sign in to follow this  
carlostex

Timer Script Need Help!!!

Recommended Posts

Guys i have this code:

//Timer.sqf
//Script by CarlosTex
_timeleft = 300;

while {true} do {

// 5 minutes counter
if (round _timeleft == 300) then { hintsilent format ["%1", [_timeleft/60,"HH:MM"] call bis_fnc_timetostring]; };	
if (round _timeleft < 300) then { hintsilent format ["%1", [_timeleft/60,"HH:MM"] call bis_fnc_timetostring]; };

if (_timeleft < 1) exitWith{};

};

It does the hint allright but it doesn't do the countdown. Using the function time to string will gurantee it will work on a dedi. Now i just need the countdown to happen.

Share this post


Link to post
Share on other sites
Guys i have this code:

Snip

It does the hint allright but it doesn't do the countdown. Using the function time to string will gurantee it will work on a dedi. Now i just need the countdown to happen.

Hm, I'm not home currently but I have a pretty good countdown script that would even display the time to the players. I think I had trouble with the timer showing on dedicated servers though...It's a simple enough fix though.

Once I get home I can post up mine if you'd like.

Share this post


Link to post
Share on other sites

Ok i got it to count now like this:

//Timer.sqf
//Script by CarlosTex
_timeleft = 300;


while {true} do {

_timeleft = _timeleft -1;

// 5 minutes counter
if (round _timeleft == 300) then { hintsilent format ["%1", [_timeleft/60,"HH:MM"] call bis_fnc_timetostring]; };	
if (round _timeleft < 300) then { hintsilent format ["%1", [_timeleft/60,"HH:MM"] call bis_fnc_timetostring]; };

sleep 1;

if (_timeleft < 1) exitWith{};

};

But counting is very irregular.

Edited by CarlosTex

Share this post


Link to post
Share on other sites

_nil = [60,"60 seconds until we arrive...","We are arriving..."] execVM "countdown.sqf"

private ["_remaining", "_timer", "_msg1", "_msg2"];
_timer = _this select 0;
_msg1 = _this select 1;
_msg2 = _this select 2;

"timerMsg" addPublicVariableEventHandler {[] call showCountdown};
if (isnil "timeFormat") then {
timeFormat = {
	private ["_hours", "_minutes", "_seconds"];
	_hours = 0;
	_minutes = 0;
	_seconds = 0;
	_seconds = _this;
	if (_seconds > 59) then {
		_minutes = floor (_seconds / 60);
		_seconds = _seconds - (_minutes * 60);
	};
	if (_minutes > 59) then {
		_hours = floor (_minutes / 60);
		_minutes = _minutes - (_hours * 60);
	};
	if (_seconds < 10) then {
		_seconds = format ["0%1", _seconds];
	};
	if (_minutes < 10) then {
		_minutes = format ["0%1", _minutes];
	};
	[_hours, _minutes, _seconds]
};
};

if (isnil "showCountdown") then {
showCountdown = {
	hintsilent TimerMsg;
};
};

if (isServer) then {
while {_timer != 0} do {
	_remaining = _timer call timeFormat;
	timerMsg = format ["%1\n\n%2:%3:%4",_msg1, (_remaining select 0), (_remaining select 1), (_remaining select 2)];
	publicVariable "timerMsg";
	if (local player) then {[] call showCountdown};
	_timer = _timer - 1;
	sleep 1;
};
};
timerMsg = _msg2;
publicVariable "timerMsg";
if (local player) then {[] call showCountdown};

Edited by cobra4v320

Share this post


Link to post
Share on other sites
Does that work on a dedi server?

No way! Commands like addPublicVariableEventHandler, isServer or publicVariable are only singleplayer commands...

:rolleyes:

Share this post


Link to post
Share on other sites
No way! Commands like addPublicVariableEventHandler, isServer or publicVariable are only singleplayer commands...

:rolleyes:

:eek::p

Share this post


Link to post
Share on other sites

That should countdown correctly but I have no idea if it will work in MP.

//Timer.sqf
//Script by CarlosTex
_timeleft = 300;

while {true} do {

// 5 minutes counter
hintsilent format ["%1", [((_timeleft)/60)+.01,"HH:MM"] call bis_fnc_timetostring];

if (_timeleft < 1) exitWith{};
 _timeleft = _timeleft -1;
sleep 1;


};

Share this post


Link to post
Share on other sites
No way! Commands like addPublicVariableEventHandler, isServer or publicVariable are only singleplayer commands...

:rolleyes:

:aa:

FU

---------- Post added at 11:26 PM ---------- Previous post was at 11:23 PM ----------

That should countdown correctly but I have no idea if it will work in MP.

Thanks man i'll try. I'm always looking forward with solutions that use the bis_fnc_timetostring.

Share this post


Link to post
Share on other sites
:aa:

FU

---------- Post added at 11:26 PM ---------- Previous post was at 11:23 PM ----------

WOW guy, totally unnecessary. :j: You do realize that there are smart asses on here but its all in good fun.

Share this post


Link to post
Share on other sites

Foxtrot Uniform, it stands for Frankly Unimpressed, nothing vulgar I'm sure. ;)

Share this post


Link to post
Share on other sites
WOW guy, totally unnecessary. :j: You do realize that there are smart asses on here but its all in good fun.

Yes you are right, it wasn't really necessary i could just ignore, but patience has some limits. It was a simple question. For his information, i have seen scripts with some of those commands that had problems working on a dedi. That's why i was looking forward to see a solution with bis_fnc_timetostring.

Share this post


Link to post
Share on other sites
Please share the script when you figure it out.

Yes of course! I always do. :)

Share this post


Link to post
Share on other sites

I made something which might be useful:

//timer.sqf
private ["_countdown","_serverTime","_totalTime","_numbersToTimeString"];

_serverTime = _this select 0;

_totalTime = 5*60;

_numbersToTimeString = {
   private ["_hours", "_minutes","_chars"];
   _hours = _this select 0;
   _minutes = _this select 1;
   _chars = [];
   _chars set [0, (floor (_hours / 10)) + 48];
   _chars set [1, (floor (_hours mod 10)) + 48];
   _chars set [2, 58];
   _chars set [3, (floor (_minutes / 10)) + 48];
   _chars set [4, (floor (_minutes mod 10)) + 48];
   toString _chars
};

_countdown = _totalTime - time + _serverTime;
while {sleep 0.5; _countdown > 0} do {
   //Find how much time is left
   _countdown = _totalTime - time + _serverTime;
   if (_countdown > 0) then {
       hintSilent parseText format ["<t size='2' color='#ffffba0c'>%1</t>", ([floor (_countdown / 60), _countdown mod 60] call _numbersToTimeString)];
   };
};

This is the countdown script. You change change from how much it counts from to something else than 300 seconds.

This is the line that activates it (you might need to put the functions module down):

[nil, nil, rEXECVM, "timer.sqf", time] call RE;

You should only call this line on one machine. You can call it on the server for example and the countdown will be in sync with the server. This doesn't use sleep to delay seconds but instead the machine running sends the time the command was executed and the scripts uses that to calculate how much time has passed. This makes it more accurate and alike for everbody. Also instead of a sleep 1 it uses a sleep 0.5 so the time won't skip a second sometimes.

If there somehow is severe lag and the another player receives the "message", late some seconds will already have passed. Thus time is synchronized between all.

Instead of the server you can have the activation in an action instead since it only runs on the player who performed it. Just only activate it on one machine.

EDIT:

If you want the hint to disappear immediately after the countdown instead of hanging for like a minute add this to the very bottom of the script:

sleep 1.0;
hintSilent "";

Edited by Muzzleflash

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  

×