Getting firearm sounds to be heard by all -Solved-

Currently viewing this thread:

Яowan

Grandmaster Knight
M&BWBNW
Been trying to get firearms (Muskets, pistols etc.) to create sound effects that can be heard by everyone, rather than just by the client firing the weapon - in an attempt to fix this, I followed the following tutorial.

http://forums.taleworlds.com/index.php/topic,94854.0.html

I was previously able to get this workings for the native module system with no sweat, but because the PW module system is.. different, I'm not entirely sure where to go.

I added this snippet to the end of game recieve network message:

Code:
    # NEW EVENTS ADDED
       (else_try),
        (eq,":event_type", server_event_sound_made_by_player),
        (neq,":player_no",0),
        (store_script_param, ":sound", 3),
          (get_max_players, ":num_players"),
          (try_for_range, ":cur_player", 0, ":num_players"),
            (player_is_active,":cur_player"),
            (multiplayer_send_2_int_to_player, ":cur_player", server_event_sound_at_player, ":sound",":player_no"),
          (try_end),
        (else_try),
    # END NEW EVENTS ADDED
    # NEW CLIENT EVENTS
          (eq, ":event_type", server_event_sound_at_player),
          (store_script_param, ":sound", 3),
          (store_script_param, ":player", 4),
          (player_get_agent_id,":agent",":player"),
          (try_begin),
          (neq,":agent",-1),
          (display_message,"@BANG!"), # This is just a debug message, it isn't essential.
            (agent_play_sound,":agent",":sound"),
        (try_end),
    # END NEW CLIENT EVENTS

Everything was followed as-is in the tutorial (such as the header commons, except some tweaks to the names of the operations; from multiplayer -> server)

Code:
##PWNM Event For Muskets##
server_event_sound_made_by_player               = 28
server_event_sound_at_player                    = 29

Below is a template for a firearm; specifically a pistol, demonstrating the sound changes.

Code:
["pistol_template", "Pistol", [("flintlock_pistol_1",0)], itp_type_pistol |itp_merchandise|itp_cant_reload_while_moving|itp_cant_use_on_horseback|itp_primary ,itcf_shoot_pistol|itcf_carry_pistol_front_left|itcf_reload_pistol, 7300 , weight(1.5)|difficulty(0)|spd_rtng(35) | shoot_speed(160) | thrust_damage(70 ,pierce)|max_ammo(1)|accuracy(65),imodbits_none,
 [(ti_on_weapon_attack, [(multiplayer_send_int_to_server,server_event_sound_made_by_player,"snd_pistol_shot"),(position_move_x, pos1,27),(position_move_y, pos1,36),(particle_system_burst, "psys_pistol_smoke", pos1, 15)])]],

Compiles without an issue; but no sound is produced whatsoever.

Any help would be greatly appreciated! Thanks!

Actually, sorry about this - a workaround was found, and so this wasn't needed. Sorry for the spam / pointless topic! Please remove if possible.
 

Vornne

Count
M&BWBNWVC
N0body said:
Actually, sorry about this - a workaround was found, and so this wasn't needed. Sorry for the spam / pointless topic! Please remove if possible.
Not at all: a major part of having questions in a forum thread like this is so anyone else interested now or in the future can refer to or search for it. Coding questions in this board are never spam unless something that is repeated very many times.
N0body said:
Been trying to get firearms (Muskets, pistols etc.) to create sound effects that can be heard by everyone, rather than just by the client firing the weapon - in an attempt to fix this, I followed the following tutorial.

http://forums.taleworlds.com/index.php/topic,94854.0.html
That guide is good for the general overview of how to send Warband network messages, but is very old and the sound example is unnecessary: in most cases just use agent_play_sound on the server, which is automatically synchronized with all nearby clients - only use your own network messages if it should be heard far away across the scene, like maybe a cannon explosion, and for playing sounds at a scene prop or postion, use the pw scripts that send specially formatted network events. The particle_system_burst operation works the same way: it only needs to run on the server to be sent to all nearby clients automatically.

For gun sounds, I suggest a trigger like this (not at home with the module system at the moment, so might need to fix mistakes later):
[font=andale_mono](ti_on_weapon_attack,
[(multiplayer_is_server),
  (store_trigger_param_1, ":agent_id"),
  (agent_play_sound, ":agent_id", "snd_pistol_shot"),
  (position_move_x, pos1, 24), # example - use the correct offsets for your gun
  (position_move_z, pos1, 35),
  (particle_system_burst, "psys_pistol_smoke", pos1, 10),
  ])[/font]
If you want to add lots of guns you shouldn't copy and paste all that, rather add a trigger generating function to the top of module items, something like this:
[font=andale_mono]def itm_gun_effect(sound="snd_pistol_shot", offset_x=23, offset_z=35, particles="psys_pistol_smoke", burst_strength=10):
  return (ti_on_weapon_attack,
  [(multiplayer_is_server),
    (store_trigger_param_1, ":agent_id"),
    (agent_play_sound, ":agent_id", sound),
    (position_move_x, pos1, offset_x),
    (position_move_z, pos1, offset_z),
    (particle_system_burst, particles, pos1, burst_strength),
    ])[/font]
Then use it by putting itm_gun_effect() inside the triggers list of the item, or itm_gun_effect(sound="snd_musket", particles="psys_musket_smoke"), or whatever. For a full item entry example:
[font=andale_mono]["flintlock_pistol", "Flintlock Pistol", [("flintlock_pistol",0)], itp_type_pistol|itp_primary, itcf_shoot_pistol|itcf_reload_pistol,
230, weight(1.5)|difficulty(0)|spd_rtng(3:cool:|shoot_speed(160)|thrust_damage(45, pierce)|max_ammo(1)|accuracy(65), imodbits_none, [itm_gun_effect()]],[/font]
 
Top Bottom