Jump to content
Sign in to follow this  
KeyCat

Random overcast (weather) in mp missions?

Recommended Posts

Please bear with me since I'm a newbie when it comes to the script language in OFP...

I want to make random weather on each start in a co-op map I'm working on and using the following lines in init.sqs does work, somewhat...

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_Weather = Random 1

0 setOvercast _Weather

<span id='postcolor'>

...but (and you knew there was one coming didn't you ;-) the problem is that it makes different weather on each clien't.

This tells me the random function is executed separately for each client, so the question is how get the same weather (but randomly each time) on all machines?

Thankfull for any help you can give a script n00b tounge.gif

/Christer (a.k.a KeyCat)

Share this post


Link to post
Share on other sites

Get the random command to work on the server (!local) then transmit the global variable to the clients to use the setOvercast command on.

RED

Share this post


Link to post
Share on other sites

I did search but guess not hard enough tounge.gif

Anyway thanks for the pointer....

/Christer (a.k.a KeyCat)

BTW: I've used the search for another question and found answers after some hard work but honestly the search function on this board could need a bit work....

Share this post


Link to post
Share on other sites

bn880, did you test this script ? Is it working correctly ?

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">ztime = -1;

?!(local server) : goto "wait"

ztime = random 24

weather = random 1

fog = random 0.8

publicvariable "weather"

publicvariable "fog"

publicvariable "ztime"

#wait

@(ztime != -1)

skiptime ztime

0 setovercast weather

0 setfog fog<span id='postcolor'>

Share this post


Link to post
Share on other sites

no I did not test, but the script I posted on the other topic should work, don't forget to create the proper game logic

Share this post


Link to post
Share on other sites

Sorry but I couldn't get it to work in MP, works in SP... Could be me doing something wrong but I did create the game logic?

Anyone has this working OK?

/Christer (a.k.a KeyCat)

Share this post


Link to post
Share on other sites

* bump *

Sorry for beeing little impatient but adding random weather would mean so much. I can get it to work just fine in SP but not MP? Anyone?

/Christer (a.k.a KeyCat)

Share this post


Link to post
Share on other sites

Here's something that might work (I just wrote it, havent tried it tounge.gif):

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

waitforweather = true

if (name player == "Error: No Vehicle") then goto "server"

#loop

~0.01

? waitforweather : goto "loop"

0 setovercast weather

0 setfog fog

exit

#server

weather = random 1

fog = random 1

waitforweather = false

publicvariable "weather"

publicvariable "fog"

publicvariable "waitforweather"

<span id='postcolor'>

put that in init.sqs or something.

Edit: correct, red tounge.gif

Share this post


Link to post
Share on other sites

:server should be #server, but otherwise it looks good.

RED

Share this post


Link to post
Share on other sites

Alright I just noticed this thread again.

If it works in SP then it will work in MP, are you using a dedicated server to test on? That's what it's designed for.

Put that code into init.sqs. Create a gameLogic called "Server".

EDIT: If you tell me it doesn't work again I'll check it myself. smile.gif

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (bn880 @ Dec. 16 2002,22:29)</td></tr><tr><td id="QUOTE">If it works in SP then it will work in MP, are you using a dedicated server to test on?  That's what it's designed for.<span id='postcolor'>

hmmm I see... No I wasn't using a dedicated server while testing so this must be the culpritt!!!! Will try to get access to a dedicated server and try again.

BTW, does this mean that other script functions etc can be porked if not running the mission on a ded. server?

Tonight we tried a simple thing (again me hosting) where you could  call in a support Gunship via the radio meny. As before it works like a champ in SP but in MP my friend was unable to get the support Gunship to take off even if it looked like the script was executed on his end (he got the prompt for co-ordinates and clicked the map), for me (as host) it worked fine?

Strange thing is that some scripts like Doolittles arty script worked fine for both of us (even if the shell calculations in that script must be way off) using the same method...

Thanks for taking the time it's invaluable to have guru's like you around xmas.gif

/Christer (a.k.a KeyCat)

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (KeyCat @ Dec. 16 2002,17:29)</td></tr><tr><td id="QUOTE"></span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (bn880 @ Dec. 16 2002,22:29)</td></tr><tr><td id="QUOTE">If it works in SP then it will work in MP, are you using a dedicated server to test on? That's what it's designed for.<span id='postcolor'>

hmmm I see... No I wasn't using a dedicated server while testing so this must be the culpritt!!!! Will try to get access to a dedicated server and try again.

BTW, does this mean that other script functions etc can be porked if not running the mission on a ded. server?<span id='postcolor'>

As far as I can remember, MP scripts using the local Server condition had problems on non-ded. servers. I could be wrong. I think I will check out that random weather script for you anyway. smile.gif Btw, that script was written before setRain was around, so that you can add in.

Share this post


Link to post
Share on other sites

OK.

The simple script I used for the support Gunship didn't use the local server condition so thats a bit strange but will test more, could be me since I'm still learning! Anyway if you do test it before I do please let us all know...

Noticed the thing about setRain... Thanks again!

/Christer (a.k.a KeyCat)

Share this post


Link to post
Share on other sites

sad.gif Wholly cow

I'v been working on that script for 1.9 until now! I expected to spend 3 minutes on it. wow.gif

This works on dedicated server for sure

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">~0.001

skipHours = -1;

?!(local Server): goto "wait"

skipHours = Random (24);

weather = Random (1);

fog = Random (0.8);

PublicVariable "weather";

PublicVariable "fog";

PublicVariable "skipHours";

#wait

@(skipHours > -1)

skiptime skipHours;

0 setovercast weather;

0 setfog fog;<span id='postcolor'>

Whats important here? Well only ONE thing, it turns out that a ~0.001 is needed for the init to be executed after the mission editor settings are set. xmas.gif That will put a screw in peoples code. biggrin.gif

I recon this will work on non dedi as well now.

Share this post


Link to post
Share on other sites

This thread is a funny one, keeps not showing up in "New Posts" search for me, that's why I did not reply to it for so long before. confused.gif Iknoboard seems a little sick. smile.gif

EDIT: its there now, lets see what happens confused.gif

Share this post


Link to post
Share on other sites

What can I say.... You guys are incredible and I'm glad to be part (even if very very tiny <G>) of such a community!

Will try it as soon as I get a chance and report back.

/Christer (a.k.a KeyCat)

Share this post


Link to post
Share on other sites

Haven't tested the dynamic weather yet since I added quite a few other features to my mission that I have to test first before adding yet another bug source.

However I did som pre-testing today while hosting (no dedicated) and it looks like the "? !(local Server) : exit" trick works on both a client hosting and a dedicated server.

Here what I did... I placed a Game Logic named "Server" and had a radio trigger run the following code...

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

? !(local Server) : goto "Client"

hint "DEBUG: I'm a server"

exit

#Client

hint "DEBUG: I'm a client"

exit

<span id='postcolor'>

When some of us clicked on the radio trigger it corretly indicated me as a server and my friend as a client.

Hope BIS will continue to improve the script support for MP! Read Snypir's post over at OFPEC and understood that it requires quite a few workarounds to get things to work correctly in MP...

Anyway, just wanted to share and will report back after I tested the weather stuff.

/Christer (a.k.a KeyCat)

Share this post


Link to post
Share on other sites

Here is the one that i used and it works in MP, sometimes it gives strange messages at the top in the hint box, but it still works fine..

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">;Interval is the time for Weather to Change.

;Wait is a Delay Between Weather Changes.

;Report Enables or disables Wheather Reports (true/false)

_Interval = _this Select 0

_Wait = _this select 1

_Report = _this Select 2

#loop

_num = 0

_Fog = random 1

_cast = random 1

_Interval setfog (_Fog)

~.001

_Interval SetOvercast (_Cast)

?(_cast <= .2): _msgC = "Clear Skies and"

?((_cast > .2) and (_cast < .5)): _msgC = "Some Clouds and"

?((_cast > .5) and (_cast < .9)): _msgC = "Heavy Clouds and"

?(_cast >= .9): _msgC = "ThunderStorms and"

?(_Fog <= .3): _msgF = "No Fog"

?((_Fog > .4) and (_fog < .8)): _msgF = "Some Fog"

?(_Fog >= .8): _msgF = "Heavy Fog"

?(_report): hint format["Weather Report:\n%1\n%2",_msgC, _msgF]

#clock

~1

_num = _num + 1

?(_num <= (_interval + _wait)): goto "clock"

goto "loop"

exit<span id='postcolor'>

ok HK over and out, and ty to the guy that wrote that cause it wasn't me i aint that clever biggrin.gif

Share this post


Link to post
Share on other sites

Thanks for the additional script HK, and it looks like all of them will work when they have ~ somewhere before making the settings. Which is diffrent from 1.46 as far as I know.

What I always wanted to do is set the mission time to system time, so it always matches real life... but I don't think there is a systemTime function. smile.gif I had some C or VB program edit the mission.sqm for me with the system time etc, but that's not very convenient, and I don't know where it went either. biggrin.gif

Share this post


Link to post
Share on other sites

OK, I managed to do two tests today and here is my result....

1st test was on the Desert island with very few objects and everything worked as expected.

2nd test was in my pretty big MP Nam mission using the same code and the result was like before, i.e didn't work and all clients had different weather and time.

Since you mention that a delay is critical my guess is that I need to increase major in my MP mission since it take quite some time to load. Will increase to ~5 and see if that can prevent the editors settings from interfer...

/Christer (a.k.a KeyCat)

Share this post


Link to post
Share on other sites

Finally I've have it working also in my big Nam mission. I was only able to get it to work if I made it an external SQS and then called that from a game logic but now it works and thanks for your help!

PS: Could of course be me doing something wrong since I'm still learning xmas.gif

/Christer (a.k.a KeyCat)

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  

×