OSP Code MP Collection of Scripts & Examples with Server/Client Communication.

Users who are viewing this thread

Simple scripts but it might give you idea how to use server events.
I will try to update this thread later, add more examples and scripts.
Notice: You need general knowledge of M&B module system.

header_common.py
Python:
multiplayer_event_data_client                           = 123 ## pick your own number.
multiplayer_event_data_server                         = 124 ## pick your own number.
# we will use it for server/client communication.



Call horse by whistle​

CLIENT SIDE







module_mission_templates
Python:
whistle_horse = (
0, 0, 0, [(key_clicked, key_c)],
[
   (eq, "$g_whistle_cooldown", 0),
   (multiplayer_get_my_player, ":player"), # Get player
  (player_get_agent_id, ":agent_id", ":player"),
       (gt, ":agent_id", -1),
       (agent_is_alive, ":agent_id"),
(call_script, "script_whistle_horse", ":player", ":agent_id"),
     (display_message,"@You whistle for a horse!",0x6495ed),  
   (assign, "$g_whistle_cooldown", 25),
])

#Note: I don't why I made it in two parts? It was long time ago.
# I probably had reason for that tho...




module_scripts.py
Python:
("whistle_horse",
   [(store_script_param, ":player", 1),
   (store_script_param, ":agent", 2),
   
      (try_begin),
(multiplayer_send_3_int_to_server, multiplayer_event_data_server, 2, ":player", ":agent"),
(try_end),
     
]),


SERVER SIDE



module_scripts.py
Python:
("game_receive_network_message",
    [
      (store_script_param, ":player_no", 1),
      (store_script_param, ":event_type", 2),        
     
      (try_begin),
        ###############
        #SERVER EVENTS#
        ###############


### add your event somewhere here....

(try_begin),
(eq, ":event_type", multiplayer_event_data_server),
      (store_script_param, ":event_type_custom", 3), ### Its sub event. I made it in order to save normal ones.
        (store_script_param, ":value_1", 4), ### useless in this case
          (store_script_param, ":value_2", 5), ### its agent id in this case
(try_begin),
  (eq, ":event_type_custom", 2),
      (agent_get_position, pos1, ":value_2"),
   (agent_play_sound, ":value_2", snd_whistle), ## its custom sound. there is plenty of free sounds available in the internet.
   (assign, ":is_whistled", 0), ### to avoid calling multiple horses at once.


### Try for alive agents (horses) on map, in range of 250 from player. Pick the first which meets the conditions.
  (try_for_agents,":agent"),
 
         (agent_is_alive,":agent"),
         (neg|agent_is_human,":agent"),
     (agent_get_position, pos2, ":agent"),
     (get_distance_between_positions,":distance",pos2,pos1),
     (ge,":distance",250), ### adjust for your own needs
(eq, ":is_whistled", 0),
(agent_set_scripted_destination,":agent",pos1,1),
  (assign, ":is_whistled", 1),
  (try_end),
  (try_end),
(try_end),

#### [...]


Notes: Things you can do to improve -

  • Check for player, let's say riding skill. If it's enough high - then start script. (serverside)
  • Make $g_whistle_cooldown serverside (store it as player slot). (serverside, security)




Multiplayer Helmet Visor & Multiplayer Equipment Synchronisation​




CLIENT SIDE​


module_mission_templates.py

Python:
helmet_visors = (
 0, 0, 5, [(key_clicked, key_q)],
 [
   (store_trigger_param_1, ":agent_id"),
   (multiplayer_get_my_player, ":player"), # Get player info
 
   (player_get_agent_id, ":agent_id", ":player"), # Get agent ID of player
   (agent_get_item_slot,":item_needed",":agent_id",4), # Get item slot for head
   (try_begin),
    
    (try_begin),
     (eq, ":item_needed", "itm_pigface_klappvisor_open"),
     (call_script, "script_agent_equip_sync_multiplayer", ":player", "itm_pigface_klappvisor"),#Use script to change helmet
    (else_try),
     (eq, ":item_needed", "itm_pigface_klappvisor"),
     (call_script, "script_agent_equip_sync_multiplayer", ":player", "itm_pigface_klappvisor_open"),#Use script to change helmet
    (else_try),
     (display_message, "@Your helmet has no visor!"),
    (try_end),
  (try_end),   
 ])

module_scripts.py

Python:
 ("agent_equip_sync_multiplayer",
   [(store_script_param, ":player", 1),
      (store_script_param, ":item_id", 2),
      (try_begin),
(multiplayer_send_3_int_to_server, multiplayer_event_data_server, 1, ":player",  ":item_id"),
(try_end),
      
 ]),

CLIENT EVENT

Python:
### Note: We are in script_game_receive_network_message

### SUB EVENTS CLIENT PITCH BEGIN
          (eq, ":event_type", multiplayer_event_data_client),
          (store_script_param, ":event_type_custom", 3),
           (store_script_param, ":value_1", 4), ### agent id
            (store_script_param, ":value_2", 5), ### item id 
                    
        
         
      (try_begin), 
      (eq, ":event_type_custom", 1),
      (agent_equip_item, ":value_1", ":value_2"),
        (agent_play_sound, ":value_1", 99),
      (try_end),









SERVER SIDE​



module_scripts.py


SERVER EVENT
Python:
("game_receive_network_message",
    [
      (store_script_param, ":player_no", 1),
      (store_script_param, ":event_type", 2),        
     
      (try_begin),
        ###############
        #SERVER EVENTS#
        ###############


### add your event somewhere here....


        (try_begin),
          (eq, ":event_type_custom", 1),
             (assign, reg5, ":value_1"), ### agent
    
    (player_get_agent_id, ":agent_id", ":value_1"),
    (agent_equip_item, ":agent_id", ":value_2"),
    (get_max_players, ":max_players"),
    

### loop throught players, let them know about change of equipment (synchronise)
    (try_for_range, ":other_player_id", 1, ":max_players"),
    (player_is_active, ":other_player_id"),   
 
    (multiplayer_send_3_int_to_player, ":other_player_id", multiplayer_event_data_client, 1, ":agent_id",  ":value_2"),
    (try_end),
    #### VISOR OPEN/CLOSE END
    (try_end),
(try_end),
 
Back
Top Bottom