Jump to content
Sign in to follow this  
resistance-rat

Simple CountDown script

Recommended Posts

Okay I used the script from post 3. Works...

When the timer become 0, I want a objective completed.. Where do I put that script in? :)

Share this post


Link to post
Share on other sites

Just put something like timerDone = true;

At the bottom of the script and in your trigger condition put

timerDone

Then in the act on put your completion task details

Share this post


Link to post
Share on other sites
Just put something like timerDone = true;

At the bottom of the script and in your trigger condition put

timerDone

Then in the act on put your completion task details

Thanks dat worked..

It's dumb of me, but how can I do it if i'm faster then the timer?

something like this? A wild guess :cool:

if (isServer) then {

while {_timer > 0} do {timerDone = true;};

Share this post


Link to post
Share on other sites

use the below:-

Set pstimerstart somewhere to true

i.e in a trigger act

pstimerstart=true;

then if you finish sooner turn it to false and it will stop the timer

if (isServer) then {
while {_timer > 0 && pstimerstart } do {
	_remaining = _timer call glt_timeFormat;
	glt_timerMsg = format ["%1\n\n%2:%3:%4",_msg1, (_remaining select 0), (_remaining select 1), (_remaining select 2)];
	publicVariable "glt_timerMsg";
	if (local player) then {[] call glt_showCountdown};
	_timer = _timer - 1;
	sleep 1;
};
};

Share this post


Link to post
Share on other sites

That didn't do it.

I put pstimerstart=true; in a trigger at start and pstimerstart=false; in the end trigger.

I put the script in the timer.sqf

The time keeps running and stops at 1.

And if it going to stop, where do I put the task completed code and if failed the failed code?

I really hope there is an answere to this...:butbut:

Share this post


Link to post
Share on other sites

I use the following works on SP & MP but not on dedi.

//nul = [951, "Reinforcements arrive:", "Reinforcements arriving..."] execVM "timer.sqf"
private ["_remaining", "_ref", "_timer", "_msg1", "_msg2"];
_timer = _this select 0;
_msg1 = _this select 1;
_msg2 = _this select 2;
_ref = time;
"glt_timerMsg" addPublicVariableEventHandler {[] call glt_showCountdown};
if (isnil "glt_timeFormat") then {
glt_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 "glt_showCountdown") then {
glt_showCountdown = {
	hintsilent glt_TimerMsg;
};
};

if (isServer) then {
while {_timer > 0 && psstarttimer } do {
	_remaining = _timer call glt_timeFormat;
	glt_timerMsg = format ["%1\n\n%2:%3:%4",_msg1, (_remaining select 0), (_remaining select 1), (_remaining select 2)];
	publicVariable "glt_timerMsg";
	if (local player) then {[] call glt_showCountdown};
	_timer = _timer - 1;
	sleep 1;
};
};
glt_timerMsg = _msg2;
publicVariable "glt_timerMsg";
if (local player) then {[] call glt_showCountdown};
timerholdDone = true;

You have to set psstarttimer=true somewhere before you start the timer then set it to false to end the timer it should work fine.

If not let us know and ill send you a demo

Share this post


Link to post
Share on other sites

Spamming publicvariable every second just for a timer is kind of silly really.

Share this post


Link to post
Share on other sites

I used pstimerstart=true; instead of psstarttimer=true; Thats why it didn't work.

And I figured it out how to get the objective completed or failed.

Put this at the end of the script:

if (_timer >= 1 ) then {"1" objStatus "DONE"; tskobj1 setTaskState "SUCCEEDED"; obj_1 = true; savegame;};

if (_timer < 1 ) then {hint "boehoe";};

Share this post


Link to post
Share on other sites

Guys how do I adjust the countdown timer for this script? At the moment it's set for 15 mins 50 secs.

Thanks.

Myke;1647722']MP compatible now (at least i hope)

//nul = [951, "Reinforcements arrive:", "Reinforcements arriving..."] execVM "timer.sqf"

private ["_remaining", "_ref", "_timer", "_msg1", "_msg2"];
_timer = _this select 0;
_msg1 = _this select 1;
_msg2 = _this select 2;
_ref = time;
"glt_timerMsg" addPublicVariableEventHandler {[] call glt_showCountdown};
if (isnil "glt_timeFormat") then {
glt_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 "glt_showCountdown") then {
glt_showCountdown = {
	hintsilent glt_TimerMsg;
};
};

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

Some thoughts about your version' date=' if you don't mind.

Don't use sqs anymore. It is outdated, sqf is better for the prformance and a few other reasons. Just don't use it anymore.

Your countdown.sqs has no exit condition, it will run forever, even if the time has elapsed. This is an absolutely no-go. There shouldn't be any scripts runnin without reason.

Why making 2 scripts? Would fit into one perfectly.

MP compatibility is...well...bad. Although they run on all clients, depending on client machines they might go out of sync. Better to have the timer runnin on server only and broadcasting the elapsed time to the clients.

Do not "hardcode" variables into the script if they're meant to be user-editable. In your script, mainly the countdown time but also the text. Compare with my version.

Oh, and please, do not use sqs anymore.[/quote']

Edited by blood4odin

Share this post


Link to post
Share on other sites

Disregard, its the 951 secs bit in the top line, just overlooked it as its a weird number to put in.

Thanks.

Share this post


Link to post
Share on other sites

Which one of these work on dedi? I just want a timer that everyone can see properly.

Share this post


Link to post
Share on other sites
Which one of these work on dedi? I just want a timer that everyone can see properly.

We are trying to use this script in A3 on Dedi server. Doesnt seem to work. Nor for that matter any versions of a timer. It really nerves me that we had a working timer script that worked with A2OA just by adding the following line to a timer SQS just by using the rhint with the call RE function

As stated we do not think any hinting functionality, whereas the server is running the clock/timer then distributes that to the players, will work with A3. We cannot figure out if this is an issue with A3 or just the code, as all the scripts we have used never show any issues in the server RPT log.

If anyone figured how to make a time published to all users, we would greatly apprecitate any insights.

re. I really wish they never messed with the RE function and/or replaced it with the new MP garbage.

Share this post


Link to post
Share on other sites

Thanks Schatten, did try that. It does not work in dedi. I used the example 2 above in my script, plain vanilla. Can't make it any simpler..

I have a trigger that executes [] execVM "Timers.sqf"

Timers.sqf

[[["Hello"], {hint _this select 0}], "BIS_fnc_spawn", true, false, false] spawn BIS_fnc_MP;

RPT error is

Error in expression <hint _this select 0>

Error position: <hint _this select 0>

Error hint: Type Array, expected String,Text

Share this post


Link to post
Share on other sites

Error in example. This code works:

[[["Hello"], {hint (_this select 0)}], "BIS_fnc_spawn"] spawn BIS_fnc_MP;

Share this post


Link to post
Share on other sites

Thanks Schatten, We got our Multiplayer Timer working, using the Functions FOCK provided earlier, and then understanding how it all links together. This is a easy little Countdown timer that can be used on Dedi. I will document for others that want to expand on it.

Put in init.sqf

//GLOBAL HINT

"FOCK_GHint" addPublicVariableEventHandler

{

private ["_GHint"];

_GHint = _this select 1;

hint format["%1", _GHint];

};

Put this anywhere including triggers to make it run

[] execVM "Timers.sqf"

Code in Timers.sqf:(change timer to any value in seconds)

timer = 60;publicVariable "timer";

while {timer >= 0} do {

FOCK_GHint = parseText format ["<t size=1.5' align='center'>%1</t>",(timer / 3600) call compile loadfile "time.sqf];

publicVariable "FOCK_GHint";

hint FOCK_GHint;

timer = timer - 1;publicVariable "timer";

sleep 1;

};

Code for Time.sqf: (gives you the hh:mm:ss formatting)

_playtime = _this;

_h = (_playtime-(_playtime % 1));

_m = ((_playtime % 1)*60)-((_playtime % 1)*60) % 1;

_s = (((_playtime % 1)*3600)-((_playtime % 1)*3600) % 1) - (_m*60);

_hh = "";

if (_h < 10) then {_hh = "0"};

_mm = "";

if (_m < 10) then {_mm = "0"};

_ss = "";

if (_s < 10) then {_ss = "0"};

_playtimeHMS = format ["%1%2:%3%4:%5%6",_hh,_h,_mm,_m,_ss,_s];

_playtimeHMS;

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  

×