Jump to content
Sign in to follow this  
bn880

Random Weather in MP

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

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 </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.

<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

; wink.gif

~1

0 setfog getdammage _fog

0 setovercast getdammage _Over

exit

;-------------------------

Heh. Å¡Using two trucks for global variables. 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)

Share this post


Link to post
Share on other sites

Yes well that's alot like placing GameLogic objects in a random pos and getting their X|Y|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¬)

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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...

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 </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...<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 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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Okay,

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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;

?!(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'>

This should do it (not tested, but corrected)

Share this post


Link to post
Share on other sites

ok thx for ur quick reply but it get an error. It says that the

!? (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

Share this post


Link to post
Share on other sites

Yea, sorry I cut and pasted the above script and changed it...

use this line

?!(local Server): goto "wait"

At this point you have to try and understand what's going on there... it's not hard. Anyway, just for a quick answer you can erase some of the bottom 3 lines to your likings. smile.gif

Don't forget the game logic named 'server'

Share this post


Link to post
Share on other sites

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

wink.gif

Noodles

Share this post


Link to post
Share on other sites

Hmmm, what do you mean the mission won't end? How are you ending it?

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

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. =)

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  

×