Jump to content
Sign in to follow this  

Recommended Posts

Hello all, I have this script that I've used for a couple SP missions but in MP it seems to get a little...wonky. It's just a display that get's 1 added to it every second but in MP it seems to be adding 2-3 per 1 second? I'm not sure what I did wrong to make it MP proof.

countdown.sqs

if (!isServer) exitWith {};
~5
#loop
if (alive TEST) then {goto "loop"}; 

timer = 1;  publicvariable "timer";

@!isnil "timer"
#loop1
hintSilent parsetext format ["<t size='1.5' align='center'>%1</t>",(timer / 3600) call compile loadfile "time.sqf"];
timer = timer + 1; publicvariable "timer";
~1
if (timer >= 0) then {goto "loop1"};

timer = 0;

newvariable = true;
publicvariable "newvariable";
exit

Time.sqf

_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;

I've tried starting the script using many different methods as well. I this kind of script too demanding for dedicated servers?

Edited by Foxhound
Topic moved to correct section

Share this post


Link to post
Share on other sites

Please contact a Moderator/Admin to move your thread to the appropriate section "Mission editing". Thank you.

Share this post


Link to post
Share on other sites
Myke;1995061']Please contact a Moderator/Admin to move your thread to the appropriate section "Mission editing". Thank you.

Woops! I must have went 1 down too far! Ha, thanks for pointing that out. I was starting to wonder where my thread went O_O

Share this post


Link to post
Share on other sites

You are mixing SQS and SQF in there for some reason.

Like this line:

timer = 1;  publicvariable "timer";

In SQS the publicVarible part never happens since you've commented it out with the ; after timer = 1. SQS uses ; as a comment designator. SQF uses it as end of command designator.

If you're running it as SQF however your "sleeps" do nothing since ~1 for waiting a second is an SQS command, you'd use

sleep 1;

in SQF.

So, pick a language and write your script again in it. :)

Share this post


Link to post
Share on other sites

It sounds like the script that keeps track of the timer is running on multiple clients. Try replacing the first line of your .sqs script with:

? !isServer : exit

Share this post


Link to post
Share on other sites

Yes but he's using .sqs anyway so he may as well use the proper commands for it. I'm not certain that exitWith even works with .sqs, but I know that exit does.

Share this post


Link to post
Share on other sites

Alright. I stopped being lazy and changed both scripts into .sqf's. But now I'm having an issue where the timer will not show up in MP at all. In singleplayer it will run as expected but not at all in MP. I do not recieve any errors from the script either.

New scripts:

Init.sqf

null = [] execVM "countdown.sqf";
Count = true;

countdown.sqf

if (!isServer) exitWith {};
sleep 5;

newvariable = true;
publicvariable "newvariable";
timer = 1;  
publicvariable "timer";
timer = 0;
if (!isnil "timer") then {};
while {Count} do {
hintSilent parsetext format ["<t size='1.5' align='center'>%1</t>",(timer / 3600) call compile loadfile "time.sqf"];
timer = timer + 1; publicvariable "timer";
sleep 1;
if (timer >= 0) then {Count = true};
};

Time.sqf

_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;

It might be the "if (!isServer) exitWith {};" command but I'm not exactly sure how to fix it to where the script doesnt get ran on all the clients then... Thanks for the help guys

Share this post


Link to post
Share on other sites

The Armory has a seconds countdown script, you might look into that.

Share this post


Link to post
Share on other sites
The Armory has a seconds countdown script, you might look into that.

Hm, will do.

Edit: I took a look and it seemed to be a bit more complicated than I can handle by myself honestly. Bah, I didn't realize a timer would be such a difficult thing!

Edited by Genesis92x

Share this post


Link to post
Share on other sites

It is a locality problem. hintSilent is a local command, it's effects aren't broadcasted to other machines.

That said, your script does show the hintSilent text on the server and nowhere else.

In you countdown.sqf, at the point you display the text, put the string into a global variable aswell, including the publicVariable command.

And at the start of your script, before the isServer check (or inside the brackets after exitwith) us a addPublicVariableEventHandler which also contains a hintsilent command.

This should then display the timer on all machines.

Share this post


Link to post
Share on other sites

count is a ingame command, you have assigned it to true in init.sqf.

use something else, like GEN_count etc..

if (!isServer) exitWith {};

this will exit all that is not server, so no player will see it on dedi, and only host will see it on local hosted, remove that line.

whats this??

newvariable = true;
publicvariable "newvariable";

newvariable is never used in your script..

also:

if (!isnil "timer") then {};

????? remove that, if something do nothing... you see?

if (timer >= 0) then {Count = true};

shouldnt you use

if (timer == 0) then {GEN_Count = false};

as the purpose would be to stop the hint of timer???

making it true (what it already is), makes no sence, and when you keep adding to timer instead of subtracting the line is just empty fillings.

something like this should it look like:

init.sqf

null = player execVM "countdown.sqf";

if (!isServer) exitWith {};
sleep 5;

if (isnil "timer") then {
timer = 0;
publicvariable "timer";
};

while {true} do {
hintSilent parsetext format ["<t size='1.5' align='center'>%1</t>",(timer / 3600) call compile loadfile "time.sqf"];
timer = timer + 1; publicvariable "timer";
sleep 1;
};

maybe you need in init.sqf this instead to work with JIP:

if (isNull player) then {
null = player execVM "countdown.sqf";
};

Edited by Demonized

Share this post


Link to post
Share on other sites
-snip-

Thank you! I will give these a try when I get the time. Obviously I am new to scripting and I appreciate the effort. Really means a lot!

I realize that a lot of that script is useless :D (Some of those variables are for further testing purposes, this isn't for an actual mission). You gotta realize that script is very old and has gone through many changes and different ways to make it work, once I got it working I was going to go back and refine/remove useless parts. I usually only get like 10-15 minutes to work on certain scripts for fun like that as I am currently really busy...So even though deleting a couple of lines is really easy, I just can't be arsed with it until the script at least works as intended. I call it being lazy, others call it bad scripting ;)

Thank you all for your time!

Dominic

Edited by Genesis92x

Share this post


Link to post
Share on other sites

Hey guys, I just wanted to run this by everyone (Since I don't have the time to test it :| )

This is what I've got for the script (Trying to learn about addpublicvariableeventhandler's)

Countdown.sqf

if (!isServer) exitWith {};
sleep 5;
if (isnil "timer") then {
   timer = 0;
   publicvariable "timer";
};

while {true} do {
   timer = timer + 1; publicvariable "timer";
   "timer" addPublicVariableEventHandler {hintSilent parsetext format ["<t size='1.5' align='center'>%1</t>",(timer / 3600) call compile loadfile "time.sqf"]};
   sleep 1;
};

Will this work? Or do I need to add a client-part of the script so the clients will "catch" the variables too?

Share this post


Link to post
Share on other sites

Wouldn't the addPublicVariableEventHandler thing be outside/before the loop?

Share this post


Link to post
Share on other sites
Wouldn't the addPublicVariableEventHandler thing be outside/before the loop?

Hm, from what I could gather I thought it had to stay inside the loop so it would constantly update the timer for the non-server clients. But then again, scripting is obviously not my knack. I will give it a try both ways.

Edit: Bah, something went wrong. I will have to take a look tomorrow. Why do I have to be so busy this week!?

Edited by Genesis92x

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  

×