Jump to content
Romanze

Passing Value outside isServer

Recommended Posts

I cannot figure this out to save my life. I need to pass a value or outside isServer scopeon a Dedicated Server. I have to have the server determine the condition then based on those results tell the clients which side won. Here is a basic idea of how it is. 

 

This is run for everyone.

 

BWR1 = false;

 

if (isServer) then {

    BWR1 = true;

    publicVariable "BWR1";

};

 

//back to everyone...

if (BWR1) then {

    ["round1B","Succeeded",true] call BIS_fnc_taskSetState;

};

 

I have tried publicVariabled and addPublicVariableEventHandlers. I cannot get anything to work. What am I doing wrong?

Share this post


Link to post
Share on other sites

What happens is: while the server is reading the line BWR1 = true the client guys passed it (they are not server) and are reading if (BWR1), and, as it still is false and hasn't been publicVariable'd yet, the if is ignored. So, the server is the only one who's doing the if part.

 

Try this instead of if:

 

waitUntil {BWR1};

  ["round1B","Succeeded",true] call BIS_fnc_taskSetState;

Share this post


Link to post
Share on other sites

Yes it is!

 

I have lots of scripts with this scheme and working. Lots of init.sqf around the scene run this way. publicVariable is the simplest thing to do what you want.

 

If you can, try this:

 

if (isServer) then {

    BWR1 = true;

    publicVariable "BWR1";

};

 

//back to everyone...

waitUntil {sleep 1; !isNil "BWR1"}

if (BWR1) then {

    ["round1B","Succeeded",true] call BIS_fnc_taskSetState;

};

Share this post


Link to post
Share on other sites

Use addPublicVariableEventHandler

 

Thanks for replying KK! I have read a lot of your stuff on this matter, but I cant seem to get that working either.

Yes it is!

 

I have lots of scripts with this scheme and working. Lots of init.sqf around the scene run this way. publicVariable is the simplest thing to do what you want.

 

If you can, try this:

 

if (isServer) then {

    BWR1 = true;

    publicVariable "BWR1";

};

 

//back to everyone...

waitUntil {sleep 1; !isNil "BWR1"}

if (BWR1) then {

    ["round1B","Succeeded",true] call BIS_fnc_taskSetState;

};

I will try the sleep. 

Share this post


Link to post
Share on other sites

Nothing... Just waits at waitUntil {sleep 1; !isNil "BWR1"};

Here is the whole code. http://pastebin.com/7bVW9KEX  I understand its poorly written I have been told already. This is my first mission I am scripting. 

Share this post


Link to post
Share on other sites

I had only a few mins to check the script, but I see the variable management is under a if (isDedicated), so in non dedi environment the variable will stay nil forever...

 

And even that, if there is no WEST unit, the variable will remain undefined...

 

Check that and tomorrow I will be able to test something more.

Share this post


Link to post
Share on other sites

I had only a few mins to check the script, but I see the variable management is under a if (isDedicated), so in non dedi environment the variable will stay nil forever...

 

And even that, if there is no WEST unit, the variable will remain undefined...

 

Check that and tomorrow I will be able to test something more.

Ok thank you very much for looking into this. This is in a dedicated environment. I have a dedi server I try this on. Also, I test this as a west unit only. Once that works I will add in if (!nil BWR1 || !nil OWR1) then { blah...

Share this post


Link to post
Share on other sites

Uhm, have you debugged the dedi part? I mean, are you sure the dedi has reached the proper line?

 

Because you have this on the script begining:

 

waitUntil {!isNull player};

 

AFAIK in Dedi it will return false forever. Isn't it?

 

Anyway I recommend you to debug your code. In dedi environment, you must create a function to broadcast messages and call it with BIS_fnc_MP (the new system is a mistery to me yet). The function I use:

_unit = _this select 0;
_text = _this select 1;

_unit sideChat format ["%1",_text];

So, let's say you called the function "commsMP". To debug, in the (isDedicated) part, put this:

 

[[playableUnits select 0,"We have reached the isDedicated part"],"commsMP", true] call BIS_fnc_MP;

 

If you see the message then I'm still lost :)

 

Anyway the debugging thing is a very valuable ally.

 

Second advice is try to separate client scripts from server scripts. It is not a MUST, but will keep things ordered and specially will make your mind prepared to not thinking they are running the same lines of code, but paralell works instead, which you have to coordinate like this case.

Share this post


Link to post
Share on other sites

barbolani thank you so so so very much. I have been working at this problem everyday, for the last 2 weeks. Thank you very much! I am not sure if I am testing wrong, but here is the steps I do.

1. Change script then save.

2. Open game and create a LAN lobby and edit my mission.

3. Export my mission so I have a PBO.

4. Minimize game, Stop my Dedi server.

5. Use filezilla to delete and upload new PBO.

6. Start dedi Server.

7. Go back into game, join and test.

 

I kind of hope I am doing this the hard way, so that there is an easier way. Any suggestions? I am going to try your debug script. I have also read something about debug_console I am going to find more about.

Share this post


Link to post
Share on other sites

I don't think you may use that method if you are changing the scripts as they are getting saved in the editor folder, and not in the pboed version.

 

I won't say my method is the best, but at least works for me:

 

Save the script

Export mission to MP

Exit editor

Open the Dedi

Go to LAN

Playtest

 

Very boring indeed to make tests in MP, wish the standard editor had some MP emulator. It would save me a couple hundered of hours each year, literally.

Share this post


Link to post
Share on other sites

I don't think you may use that method if you are changing the scripts as they are getting saved in the editor folder, and not in the pboed version.

 

I won't say my method is the best, but at least works for me:

 

Save the script

Export mission to MP

Exit editor

Open the Dedi

Go to LAN

Playtest

 

Very boring indeed to make tests in MP, wish the standard editor had some MP emulator. It would save me a couple hundered of hours each year, literally.

Cool yep thats what I do. When I said export my mission I meant export to MP. Well thanks again.

Share this post


Link to post
Share on other sites

Use Eliteness to make your mission  PBO and save it to the mpmissions directory of the server. Much quicker

Share this post


Link to post
Share on other sites

Use Eliteness to make your mission  PBO and save it to the mpmissions directory of the server. Much quicker

 

Clicking Export to MP mission in editor already makes it a PBO and saves to mpmissions. I can't see how your way would be faster. ;)

Share this post


Link to post
Share on other sites

I assumed the other posted was using a DS install separate from the game client install. Then Eliteness can be told where to save the PBO.

 

I have a 'local dedi' in the same machine as my client, but the dedi runs as a separate instance, so I need the mission PBO in the mpmissions folder of the dedi, not the client.

Share this post


Link to post
Share on other sites

Use Eliteness to make your mission  PBO and save it to the mpmissions directory of the server. Much quicker

Using Eliteness is so much faster thank you! My dedi server isnt hosted locally so I still have to update it manually, but that 1 steps helps a lot!

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

×