PDA

View Full Version : Random Weather in MP



bn880
Nov 7 2001, 18:43
In one of my MP missions I have:
1. ceated random time of day after loading mission
2. created a random length fog in the morning
3. a random overcast to occur during a 24h period

The problem is that the Random() function is used to generate random times for all these functions. If I put a Random() in a trigger or script, it is executed on all client machines seperatly giving different random numbers.

I tried using PublicVariable and that does not help.  Is there a simple way to pass Variables in this sim?

The solution I came up with is placing a GameLogic Object at some known coords on the map with a placement radius of 1/2 of what I want the maximum random number to be.  Reading the X  or Z coords of the GameLogic objects after the mission starts and doing some subtracting will provide a random number that all clients can access.

Anyway, there should and probably is a proper way to pass variables to all clients.

DEMONIAC
Nov 7 2001, 23:23
This is a very simple script to change the weather, fog level, date and time of day at the start of the mission. It can be useful to add variability to missions.

Script "environment.sqs"

-----

; Set weather type:
_W = Random 1
0 setovercast _W

; Set fog level:
_F = Random 1
0 setfog _F

; Change date (note 8760 = 365days * 24 hours):
_D = Random 8760
skiptime _D

; Exit the script
exit

------

It is important to set the date and time of the level in which you use this script to January 1st, at 0000hrs as it uses the SkipTime function to add a random number of hours to this time.

You can call this through another initialise script, or by placing the following line into a "true" trigger or unit's Initialize line:

[] exec "environment.sqs"

One thing I'll add is that you might want to change the fog random number to 0.5 instead of 1. I tried a mission last night which had a fog level of 0.98 - it was practically impossible to play - I couldn't see 3ft in front of me!

i found this somewhere might be helpfull to ya

bn880
Nov 7 2001, 23:39
Thanks but this script will still create different weather and time for every client in a MP game. As far as I know.

The trick I am looking for is to make sure it is the same on all clients.

DEMONIAC
Nov 7 2001, 23:51
ahh ok ill look into that

Shirson
Nov 8 2001, 05:10
</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">Quote: from bn880 on 8:39 am on Nov. 8, 2001
Thanks but this script will still create different weather and time for every client in a MP game. As far as I know.

The trick I am looking for is to make sure it is the same on all clients.
[/QUOTE]<span id='postcolor'>

Try this idea.

Create two 5t trucks named tFog and tOvercast and place far away. (or put underground)
After start mission start script
[tFog, tOvercast] exec "enviroment.sqs"
;-------------------------
_Fog = _this select 0
_Over = _thist select 1
_fog setdammage random 1
_Over setdammage random 1
; http://www.flashpoint1985.com/ikonboard3/non-cgi/emoticons/wink.gif
~1
0 setfog getdammage _fog
0 setovercast getdammage _Over
exit
;-------------------------

Heh. šUsing two trucks for global variables. http://www.flashpoint1985.com/ikonboard3/non-cgi/emoticons/smile.gif

P.S. How u using publicVariable?

Like this?
;-------------------------
_fog=random1
_over = random 1
PublicVariable _fog
PublicVariable _over
~1
0 setfog _fog
0 setover _fog
exit
;-------------------------



(Edited by Shirson at 6:52 pm on Nov. 8, 2001)

bn880
Nov 8 2001, 17:14
Yes well that's alot like placing GameLogic objects in a random pos and getting their X&#0124;Y&#0124;Z. I think your way is simpler but generates a number from 0 to 1, I actually need different maximum value random numbers such as 0-2 and 0-24.
I guess I can just multiply the truck damage by 2 or 24.

I used public variable like this:
---------------------------------
PublicVariable "startOvercast"

startOvercast = Random 24
.
.
---------------------------------

Even your method is just a workaround to something that should or is implemented in the game (passing variables) 8¬)

zovirl
Nov 16 2001, 18:56
How exactly does it work in MP when everyone has different random numbers? Everyone gets different time/weather/fog and play continues normally? What happens if you try to do something like a SetPos with a random number? The bad guy is in a different spot for everyone? Seems like this would start to break things...

bn880
Nov 16 2001, 19:23
Yes, this means there is different time/rain/fog for everyone...

If you do SetPos then the object position will be the same for everyone. If two clients do a SetPos then the one that executes later is going to determine the final position of the object. I am sure even this can break multiplayer games.

HappyG
Nov 19 2001, 15:51
I also have the same problem. I think that solution with vehicles is quite s**tty, also in 24 players game there would be 24 clients trying to change the position of the vehicle... Is there any chance to check out if script is running on server or on client, so we could perform random functions only on server? I would also like to get the answer from one of the developers...

zovirl
Nov 19 2001, 16:28
</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">Quote: from HappyG on 6:51 pm on Nov. 19, 2001
I also have the same problem. I think that solution with vehicles is quite s**tty, also in 24 players game there would be 24 clients trying to change the position of the vehicle... Is there any chance to check out if script is running on server or on client, so we could perform random functions only on server? I would also like to get the answer from one of the developers...[/QUOTE]<span id='postcolor'>

I saw this on one of the boards. I haven't had a chance to try it yet, so hopefully someone more knowledgable will comment if I make a mistake with it http://www.flashpoint1985.com/ikonboard3/non-cgi/emoticons/smile.gif

Make a game logic item on your map, call it Server. Now, you can use the Local command to see if the map is on the server or not

? (local Server) : goto "Server"
? !(local Server) : goto "Client"

#Server
//Server Code Here

#Client
//Client code here

HappyG
Nov 19 2001, 19:03
Thank you very much!

OK guys here you have it:

Put an empty jeep named "server" somewhere on the map, than run those 2 scripts...

server-vars.sqs
-----------------------

!? (local server) : goto "exit"

time = random 12
weather = random 1
fog = random 0.8

publicvariable "time"
publicvariable "weather"
publicvariable "fog"

#exit
exit



environment.sqs
---------------------

~0.5
skiptime time
0 setovercast weather
0 setfog fog



It works perfectly!

Have fun, HappyG

bn880
Nov 24 2001, 15:49
Okay,

that sure is a better way of doing it. Thanks, I'll try it.

Jason Alaska
Nov 26 2001, 22:26
Phuue! Let us know if that works!

(Edited by Jason Alaska at 1:30 pm on Nov. 26, 2001)

Noodles067
Aug 31 2002, 12:52
Hello, i know the answer is right in front of me, but i cant make sense of it. How do i make the server run the two scripts? []exec "server-vars.sqs"; ??
Also are there two scripts, as in two different .sqs files in the mission map or are there two scripts running under the same name?
And if i already have a game logic as a server for vehicle repsawn does that mean i cannot have random weather too?
Hope You can help me thanks a lot,
Noodles

bn880
Aug 31 2002, 14:09
WOW, aincient thread man... ok, BTW, I was using PublicVariable incorrectly before

PublicVariable does not create a network shared variable, it broadcasts the variable over the network only when it is called. (I was thinking (C++ Java variable declaration)

Noodles, try this instead:
In init.sqs do:</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">
ztime = -1;
?&#33;&#40;local server&#41; &#58; goto &#34;wait&#34;

ztime = random 24
weather = random 1
fog = random 0.8

publicvariable &#34;weather&#34;
publicvariable &#34;fog&#34;
publicvariable &#34;ztime&#34;
#wait
@<hidden>&#40;ztime &#33;= -1&#41;

skiptime ztime
0 setovercast weather
0 setfog fog
[/QUOTE]<span id='postcolor'>

This should do it (not tested, but corrected)

Noodles067
Aug 31 2002, 14:39
ok thx for ur quick reply but it get an error. It says that the
&#33;? (local server) : goto "wait"
is an invalid number when u get to briefing.
and 1 more question if only want the weather to be random and fog level and time set what do i change>
Thx a million

bn880
Aug 31 2002, 15:02
Yea, sorry I cut and pasted the above script and changed it...

use this line

?&#33;(local Server): goto "wait"


At this point you have to try and understand what&#39;s going on there... it&#39;s not hard. Anyway, just for a quick answer you can erase some of the bottom 3 lines to your likings. http://www.flashpoint1985.com/ikonboard301/iB_html/non-cgi/emoticons/smile.gif

Don&#39;t forget the game logic named &#39;server&#39;

Noodles067
Aug 31 2002, 15:41
http://www.flashpoint1985.com/ikonboard301/iB_html/non-cgi/emoticons/biggrin.gif http://www.flashpoint1985.com/ikonboard301/iB_html/non-cgi/emoticons/biggrin.gif http://www.flashpoint1985.com/ikonboard301/iB_html/non-cgi/emoticons/biggrin.gif
Thanx a lot u made my day
http://www.flashpoint1985.com/ikonboard301/iB_html/non-cgi/emoticons/tounge.gif

Noodles067
Aug 31 2002, 23:08
http://www.flashpoint1985.com/ikonboard301/iB_html/non-cgi/emoticons/sad.gif
Hey it works...........kinda. Only problem is that when i run mission with ur code in the init.sqs is that the mission wont end. My guess is that it has something to do with the word time that it maybe confuses time (i.e. hour of the day) with time( duration of game). They both have the same name. So plz tell me what i need to change to get that sorted. Apart from that it works.
Thx a lot
http://www.flashpoint1985.com/ikonboard301/iB_html/non-cgi/emoticons/wink.gif
Noodles

bn880
Aug 31 2002, 23:11
Hmmm, what do you mean the mission won&#39;t end? How are you ending it?

bn880
Aug 31 2002, 23:12
Yes, time is a reserved variable, rename it.

This is the last time I trust someone elses code that much... 2 errors like that is ... bad

EDIT: will change that post...

The_Captain
Sep 1 2002, 05:46
Heh, I spent about a month on just this problem, and i still happens on slower machines (desyncing). Took me a hell of a long time to fix. =)

Of course, then a thread like this comes along adn solve sit after the fact. =)