Home   Help Search Login Register  

Author Topic: random weather problem  (Read 875 times)

0 Members and 1 Guest are viewing this topic.

Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
random weather problem
« on: 21 Jan 2005, 12:30:27 »
here is the script I use to randomize the weather, problem is, in MP not everyone gets the same weather effect.  I thought publicvariable was supposed to fix that...any ideas?
Code: [Select]
#init
_wait=300

#Start
~28
?(Local Server):WeatherNumber=Random 7
?(Local Server):WeatherNumber=(WeatherNumber+.05)-((WeatherNumber+.05) mod 1)
PublicVariable "WeatherNumber"
;;_msg=Format["%1",WeatherNumber]
;;titletext[_msg,"PLAIN"]

?(WeatherNumber==0):Goto "ClearandSunny"
?(WeatherNumber==1):Goto "CloudyandClear"
?(WeatherNumber==2):Goto "SunnyandFoggy"
?(WeatherNumber==3):Goto "CloudyandFoggy"
?(WeatherNumber==4):Goto "ExtremelyFoggyandCloudy"
?(WeatherNumber==5):Goto "ClearandSunny"
?(WeatherNumber==6):Goto "CloudyandClear"
?(WeatherNumber==7):Goto "CloudyandFoggy"

#ClearandSunny
Hint "The forecast is clear."
0 SetFog 0

0 SetOvercast 0
0 setfog 0
~_wait
Goto "start"

#CloudyandClear
Hint "The forecast is for scattered clouds."
0 SetFog 0

0 SetOvercast .75
0 setfog 0
~_wait
Goto "start"

#SunnyandFoggy
Hint "The forecast is for fog and clear skies."
0 Setfog .7

0 SetOvercast 0
0 setfog .9
~_wait
Goto "start"

#CloudyandFoggy
Hint "The forecast is for overcast skies and fog."
0 Setfog .7

0 SetOvercast .75
0 setfog .9
~_wait
Goto "start"

#ExtremelyFoggyandCloudy
Hint "The forecast is for overcast skies and extremely dense fog."
0 Setfog 1

0 SetOvercast 1
0 setfog 1
~_wait
Goto "start"

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re:random weather problem
« Reply #1 on: 21 Jan 2005, 14:37:28 »
Maybe it should be like this:

Code: [Select]
#init
_wait=300

#Start
~28
?(Local Server):WeatherNumber=Random 7
?(Local Server):WeatherNumber=(WeatherNumber+.05)-((WeatherNumber+.05) mod 1)

?(local Server):PublicVariable "WeatherNumber"

;;_msg=Format["%1",WeatherNumber]
;;titletext[_msg,"PLAIN"]

~1

?(WeatherNumber==0):Goto "ClearandSunny"
?(WeatherNumber==1):Goto "CloudyandClear"
?(WeatherNumber==2):Goto "SunnyandFoggy"
?(WeatherNumber==3):Goto "CloudyandFoggy"
?(WeatherNumber==4):Goto "ExtremelyFoggyandCloudy"
?(WeatherNumber==5):Goto "ClearandSunny"
?(WeatherNumber==6):Goto "CloudyandClear"
?(WeatherNumber==7):Goto "CloudyandFoggy"
It's the server only who needs to make the variable public.

And you should add a delay between the publicvariable command and the actual 'set weather' commands to make sure everyone really has the new value of "WeatherNumber" before trying to set a new weather. Adjust the delay, I don't know if 1 sec is good for you. A higher value is safer.

CopyrightPhilly

  • Guest
Re:random weather problem
« Reply #2 on: 27 Jan 2005, 04:48:09 »
yup as said about, if you want to use random in mutiplayer eather you make it only run on the server/host or expect the results to be diffrent on each client connected.

Code: [Select]
#init
_wait=300

?(local server):goto "start"
goto "end"

#Start
~28
?(Local Server):WeatherNumber=Random 7
?(Local Server):WeatherNumber=(WeatherNumber+.05)-((WeatherNumber+.05) mod 1)
PublicVariable "WeatherNumber"
;;_msg=Format["%1",WeatherNumber]
;;titletext[_msg,"PLAIN"]

?(WeatherNumber==0):Goto "ClearandSunny"
?(WeatherNumber==1):Goto "CloudyandClear"
?(WeatherNumber==2):Goto "SunnyandFoggy"
?(WeatherNumber==3):Goto "CloudyandFoggy"
?(WeatherNumber==4):Goto "ExtremelyFoggyandCloudy"
?(WeatherNumber==5):Goto "ClearandSunny"
?(WeatherNumber==6):Goto "CloudyandClear"
?(WeatherNumber==7):Goto "CloudyandFoggy"

#ClearandSunny
Hint "The forecast is clear."
0 SetFog 0

0 SetOvercast 0
0 setfog 0
~_wait
Goto "start"

#CloudyandClear
Hint "The forecast is for scattered clouds."
0 SetFog 0

0 SetOvercast .75
0 setfog 0
~_wait
Goto "start"

#SunnyandFoggy
Hint "The forecast is for fog and clear skies."
0 Setfog .7

0 SetOvercast 0
0 setfog .9
~_wait
Goto "start"

#CloudyandFoggy
Hint "The forecast is for overcast skies and fog."
0 Setfog .7

0 SetOvercast .75
0 setfog .9
~_wait
Goto "start"

#ExtremelyFoggyandCloudy
Hint "The forecast is for overcast skies and extremely dense fog."
0 Setfog 1

0 SetOvercast 1
0 setfog 1
~_wait
Goto "start"

#end
exit

Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
Re:random weather problem
« Reply #3 on: 27 Jan 2005, 12:57:56 »
ok, thanks  I will give it a try...I never much messed with publicvariable

Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
Re:random weather problem
« Reply #4 on: 28 Jan 2005, 13:15:01 »
OK, I tried the script from copyrightphilly and when I play it as a mp mission alone on my pc, it works just fine, but when played on our dedicated server with a few people the script didnt run.  I know I am missing something simple here, anyone see it?

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re:random weather problem
« Reply #5 on: 28 Jan 2005, 17:32:01 »
Because CopyrightPhilly's script is run _only_ in the server... clients exit it right at the start.

Think about this:

1. Server calculates a value for 'WeatherNumber'

2. Server, and ONLY the server tells clients the value of 'WeatherNumber'

3. _DELAY_ (or a condition line with a boolean variable which server sets to true when ok for clients to continue)

4. Clients set their weather now according to the value of 'WeatherNumber'.

The part of the script I posted should do it this way.

I think the delay could be even more than 1 second so consider putting some higher value there. Note that if you use the variable method to check if clients can continue then in a looping script like yours it needs to be set to false after clients have set their weather for it to work again.
« Last Edit: 28 Jan 2005, 18:09:21 by Baddo »

Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
Re:random weather problem
« Reply #6 on: 28 Jan 2005, 18:13:14 »
doh! you're right.  Making changes now, then will try it out

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re:random weather problem
« Reply #7 on: 28 Jan 2005, 18:36:16 »

Please note:

Of course also the server should set the new weather in '4.'

Mission could be run on a non-dedi server.

Animal

  • Guest
Re:random weather problem
« Reply #8 on: 30 Jan 2005, 08:33:34 »
Your doing pretty good so far but you should script it so the server does the waiting by time and the client waits by condition or @.  try something like this

#init
_wait=300

?!local server:goto "client"

#Server
~28
WeatherNumber=Random 7
WeatherNumber=(WeatherNumber+.05)-((WeatherNumber+.05) mod 1)
PublicVariable "WeatherNumber"

?(WeatherNumber==0):Goto "ClearandSunny"
?(WeatherNumber==1):Goto "CloudyandClear"
?(WeatherNumber==2):Goto "SunnyandFoggy"
?(WeatherNumber==3):Goto "CloudyandFoggy"
?(WeatherNumber==4):Goto "ExtremelyFoggyandCloudy"
?(WeatherNumber==5):Goto "ClearandSunny"
?(WeatherNumber==6):Goto "CloudyandClear"
?(WeatherNumber==7):Goto "CloudyandFoggy"

#ClearandSunny
Hint "The forecast is clear."
0 SetOvercast 0
0 setfog 0
~_wait
Goto "Server"


#client
@!weathernumber==-1

?(WeatherNumber==0):Goto "ClearandSunny"
?(WeatherNumber==1):Goto "CloudyandClear"
?(WeatherNumber==2):Goto "SunnyandFoggy"
?(WeatherNumber==3):Goto "CloudyandFoggy"
?(WeatherNumber==4):Goto "ExtremelyFoggyandCloudy"
?(WeatherNumber==5):Goto "ClearandSunny"
?(WeatherNumber==6):Goto "CloudyandClear"
?(WeatherNumber==7):Goto "CloudyandFoggy"

#ClearandSunny
Hint "The forecast is clear."
0 SetOvercast 0
0 setfog 0
Goto "client"

This way it will work on a ded or a client ran server.  
I have a script something like this i will send ya.

Animal

  • Guest
Re:random weather problem
« Reply #9 on: 30 Jan 2005, 09:10:06 »
here is a weather script i made a long time ago.
note how both these scripts use @ to keep server and client running in sync.

;delay while mission starts
~60
#init
timetochange=0
calmb4storm=0
weather=0
stormready=false
forcast=0

#forecast
~timetochange

;skip making weather if client
   ?(!local server):goto "changeweather"
;watch a variable used for turning weather off in mission.  I.E. radio 0-0-1
   ?(resetweather):goto "end"
   forecast=random 20
   weather=(forecast/10)-1
   ?(weather<0):weather=0
   ?(weather>1):weather=1
;use big delays to make weather change slower, more realistic
   timetochange=(random 600)+600
;use this to make a storm stay around awhile before changing weather again.
   calmb4storm=(random 600)+600
   ;hint format["Calm B4 Storm %2 secs\nForcasted Weather %1\nStorm Duration %3", weather, calmb4storm, timetochange]
;send settings to clients
   publicvariable "timetochange";publicvariable "weather";publicvariable "calmb4storm"
   
#getreadytorumble
;makes server wait random time before starting the storm
   ~calmb4storm
;tell clients to start the storm now
   stormready=1
   publicvariable "stormready"
;check if weather was turned off
   ?(resetweather):goto "end"

#changeweather
;this wait is used to make sure server and client start storm at same time.
   @(stormready==1)
;once a system has started a storm, set to 0 so it will wait till server makes a new one
   stormready=0
   ?(resetweather):goto "end"
   ;hint "storm"
;set storm on all systems
   timetochange setovercast weather
                ?(!local server):goto "changeweather"
   goto "forecast"
   
#end
;if weather was shut off, tell all system to exit script
stormready=1;publicvariable "stormready"
;reset weather to clear skies
20 setovercast 0
resetweather=false
weatheron=false
titletext[format ["Weather is now off (you may enable with radio again now)"], "Plain down"]
exit