OSP Code MP Arch3r OS: Random weather for multiplayer gamemodes (fixed)

Users who are viewing this thread

Works now
Very simple to implement: Random weather effects (rain is still broken it seems :/) for multiplayer! It generates random fog and a random day time (dawn, noon or night).
Just place these commons in module_mission_templates and add them to the "multiplayer_##" templates to have random weather with that gametype.

I've placed these commons after
Code:
common_siege_assign_men_to_belfry = (
  0, 0, ti_once,
  [
    (call_script, "script_cf_siege_assign_men_to_belfry"),
    ], [])

Commons to add:
Code:
##Arch3r OS commons
#Day time
common_random_multiplayer_weather = (
  ti_before_mission_start, 0, 0,
  [ ], [
         (scene_set_day_time, "$day_time"), #time, random between 4 - 22          

         ])
##Arch3r OS serverside above
#Day time
common_random_multiplayer_weather_server = (
  ti_on_multiplayer_mission_end, 0, 0,
  [ ], [
         (try_begin),
            (multiplayer_is_server),
##          (store_current_scene,":cur_scene"), #Later, when set_rain works check for snow scenes
            (store_random_in_range, "$rain_strength", 50,150),
            (store_random_in_range, "$fog_dist", 40,250),
            (store_random_in_range, "$day_time", 4,22),

           (multiplayer_get_my_player, ":my_player_no"),
           (get_max_players, ":num_players"), 
           (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
             (player_is_active, ":player_no"),
             (neq, ":player_no", ":my_player_no"),
             (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_day_time, "$day_time"),
             (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_weather, "$rain_strength", "$fog_dist"),
           (try_end),
         (try_end),
         
         ])
##Arch3r OS serverside above
##Arch3r OS clientside under
common_random_multiplayer_weather_client = (
  ti_after_mission_start, 0, 0,
  [ ], [
##Arch3r OS disabled, set_rain is broken
##            (try_begin),
##               (lt, "$rain_strength", 100),
###               (set_rain,":rain_type",multiplayer_event_return_weather), #1=rain 2=snow (depends on scene), strength between 10-100
##               (set_rain, 1 ,"$rain_strength"), #1=rain 2=snow (depends on scene), strength between 10-100
##            (else_try),
##               (set_rain,0,0), #1=rain 2=snow (depends on scene), strength between 10-100
##            (try_end),

            (try_begin),
               (lt, "$fog_dist", 110),
               (set_fog_distance, "$fog_dist", 0xbfbfbf), #fog distance between 20-250, color is grey
            (else_try),
               (set_fog_distance, 1000000000, 0xbfbfbf), #fog distance between 20-250, color is grey
            (try_end),
         ])
##Arch3r OS
Add them by adding
Code:
common_random_multiplayer_weather,
and below that:
Code:
common_random_multiplayer_weather_client,
and below that:
Code:
common_random_multiplayer_weather_server,

To complete it, add the following below
Code:
multiplayer_event_return_max_num_bots                         = 106
in header_commons:

Code:
##Arch3r OS
multiplayer_event_return_weather                              = 110
multiplayer_event_return_day_time                             = 111
multiplayer_event_return_fog                                  = 112
##Arch3r OS

And finally add in module_scripts, above
Code:
         (try_end),
     ]), 

  # script_cf_multiplayer_evaluate_poll
:
Code:
#Arch3r
        (else_try),
          (eq, ":event_type", multiplayer_event_return_weather),
          (store_script_param, ":value", 3),
          (store_script_param, ":value2", 4),
          (assign, "$rain_strength", ":value"),
          (assign, "$fog_dist", ":value2"),
        (else_try),
          (eq, ":event_type", multiplayer_event_return_day_time),
          (store_script_param, ":value", 3),
          (assign, "$day_time", ":value"),
#Arch3r

 
Managed to fix it, will update it tonight or so. One bug is that the player would have to disconnect and reconnect for it to work properly, but after that he will get the correct weather on each map. I still need to see if there's a solution for that.
 
Rain might work if set_global_cloud_amount is set to 100 first. I can't remember whether set_global_haze_amount needed to be set as well.

The order in which set_global_cloud_amount, set_global_haze_amount, scene_set_day_time and set_rain are called is very specfic. Not sure which order was correct, but it should be quick to test.
 
Works now, with a small problem that you either have to reconnect first, or the map has to get changed. The current map when joining does not work yet as there's no way for the server to get the weather info on the client before he is connected.
 
What I meant was that weather is such an obvious thing you'd expect to be there but here you are needing to work out how to mod it in.
 
This is probably gonna sound stupid, but are there ways to make the weather non-random? I always have the same annoying sun-down skybox/weather, and I'd like to change it to a clear and pristine one.
 
There is.
In the commons of mission_templates look for:

(store_random_in_range, "$day_time", 4,22),

Just set it at 14 or 16 and it will be clear day. It would look like this: (replaces the line above)
(assign, "$day_time", 14),
 
So in regards to the client server problem.  The problem is that you can't get the info to the client without them joining the server, yes?
Once they have joined, why is it then not possible to reset the weather?  (sorry just trying to understand the code) :smile:
Could there be such a thing as a disconnect and rejoin script?
 
When a client joins the scene loads automatically, while the client needs to know the weather before he loads the scene. That's where it goes wrong.
 
I added the code but it has some minor flaws.


The fog is always too thick. You can barely see the tip of you sword through the dense fog.
There is also no randomness in it. (Might not be a bug but I got the impression that it should randomize the weather).
 
NaglFaar said:
The fog is always too thick.

Code:
 (store_random_in_range, "$fog_dist", 40,250),
...
 (lt, "$fog_dist", 110),
find those in code and increase all numbers like 2fold (40 is min fig dist, 110 max, when rnd is in 110-250 there's no fog)
NaglFaar said:
There is also no randomness in it.
change 0xbfbfbf for other numbers to have other colors for fog
 
Arch3r said:
Managed to fix it, will update it tonight or so. One bug is that the player would have to disconnect and reconnect for it to work properly, but after that he will get the correct weather on each map. I still need to see if there's a solution for that.
 
:oops:

Oh, I didn't see that. But it doesn't matter how many times I reconnect and join the server. There is always the dense fog. Other people however managed to get the fog away, but I just can't. I bet Armagan is messing with me again.
 
Back
Top Bottom