Jump to content
Sign in to follow this  
1para{god-father}

Timer script on Dedi

Recommended Posts

Can anyone help please I am trying to get this to work on a dedi server, basically it is a timer that fires when a trigger is activated and should show on everyone’s screen.

Run locally works fine, but not on a dedi :(

//nul = [120, "Arming in  :", "Launching..."] 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 && ps_timeok} 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};

Share this post


Link to post
Share on other sites

If it's just a simple timer that will start and then run to 0 no matter what. Then it's kind of pointless to make server sync it, just do it locally for every client.

Do you need to stop/change the time at any point?

Share this post


Link to post
Share on other sites

It is for a scud launch, so if spotted start timer and show how long they have - if Scud is destroyed stop timer .

So I just need a simple timer to show on each screen how long theye have left any help would be welcome :)

Share this post


Link to post
Share on other sites

scudAlive = true;
private ["_t","_min","_sec"];

_t = _this * 60;

while {_t > 0 && scudAlive} do {
 _min = floor (_t / 60);
 _sec = floor (_t mod 60);

 _min = (if (_min <= 9) then {"0"} else {""}) + str _min;
 _sec = (if (_sec <= 9) then {"0"} else {""}) + str _sec;

 hintsilent format["%1:%2",_min,_sec];

 _t = _t - 1;
 sleep 1;
};
hintsilent "";

Just make the scudAlive false to stop it.

Edited by Shuko

Share this post


Link to post
Share on other sites

To the players on whose machines the trigger is fired. So, most of the time all players.

Share this post


Link to post
Share on other sites

thanks ill set a little delay to make sure they all get in :)

---------- Post added at 02:36 PM ---------- Previous post was at 02:03 PM ----------

Just tested it on the dedi and i get no timer ? but works fine on my PC ?

Any suggestions ?

Share this post


Link to post
Share on other sites

It is supposed to be started locally on each machines, thus it doesn't matter if it's host or dedi. So, where/how are you starting it?

Share this post


Link to post
Share on other sites

We that is why I am also confused! As it works when i test it but as soon as I try on the dedi I get no timer.

Trigger 400x400

Activation : Bluefor - detected by OpFor

Timeout 10,10,10

Cond:- this

Act :nul = 10 execvm "timer.sqf";

Share this post


Link to post
Share on other sites

Just tested with that trigger. It seems to be the timeout that causes it. Don't as me why. :) With 0 it worked just fine.

I suggest you do it like this:

Trigger 1:

400x400 blufor detected by opfor

cond: this

onact: ohcrap = true; publicvariable "ohcrap"

Trigger 2:

cond: ohcrap

onact: nul = 10 execvm "timer.sqf"

Share this post


Link to post
Share on other sites

Great will give that a go now - love the publicvariable name :)

---------- Post added at 05:18 PM ---------- Previous post was at 04:14 PM ----------

Hmmmmmmmmmm it works again on local host but not on dedi :( could there be an issue with our dedi server ?

Share this post


Link to post
Share on other sites

Just do simple hint "bleh" in the onact to make sure the trigger and pv is worked. Never heard of pubvar failing.

Share this post


Link to post
Share on other sites

Hi Shk,

Is it possible to set a PV to true once the timer runs out in timer.sqf ? , that way I can trigger something else.

Sorry no idea where to put it !?!

Thanks

Share this post


Link to post
Share on other sites

timerDone = false;
scudAlive = true;
private ["_t","_min","_sec"];

_t = _this * 60;

while {_t > 0 && scudAlive} do {
 _min = floor (_t / 60);
 _sec = floor (_t mod 60);

 _min = (if (_min <= 9) then {"0"} else {""}) + str _min;
 _sec = (if (_sec <= 9) then {"0"} else {""}) + str _sec;

 hintsilent format["%1:%2",_min,_sec];

 _t = _t - 1;
 sleep 1;
};
hintsilent "";
timerDone = true;
publicvariable "timerDone";

Of course that gets made true if/when you make scudAlive false as well.

Share this post


Link to post
Share on other sites

Hi Shk,

Still having a little issue with this timer!?!

Sometimes when I enter the trigger area I do not get the timer, yet other times I do?. This only seems to happen on Dedi - when testing local it works 100% dedi only the odd time i get it to work ?

Any suggestion /ideas ?

I am using it as you suggested as follows:-

Trigger 1:

400x400 blufor detected by opfor

cond: this

onact: ohcrap = true; publicvariable "ohcrap"

Trigger 2:

cond: ohcrap

onact: nul = 10 execvm "timer.sqf"

Also not a major issue but would a JIP restart the timer if they come into the trigger after we get there and would they then see the correct countdown or would it start again for them ?

Share this post


Link to post
Share on other sites

SP/Host/Dedi shouldn't matter or at least there's nothing that's affected directly. The trigger conditions are always checked locally.

As I said, triggers are local to each machine. JIP coming in late would see wrong timer, but it won't have any effect on other players' timers. With some modifications that can be fixed if needed.

Share this post


Link to post
Share on other sites

Hi Shk,

Still having a problem with this timer !

It all works fine on MP but as soon as I try it on Dedi with a few players I get no timer, not even the hint I put in there to test , but if i go in the dedi on my own to test it works fine. Every come across this issue before ?

Cheers

Share this post


Link to post
Share on other sites

And the trigger(s) actually fire and start the script?

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  

×