SP Tutorial Module System Simple Gunshot Sounds Based on Distance w/o WSE

Users who are viewing this thread

Cokjan

Squire
WBNW
Setting up the sounds (optional, you can use whatever sounds you want)
1. Download and extract the sound files from this link. (It is OSP as far as I'm aware of, check page 2)
2. Add the following line to module_sounds.py somewhere.
("gunshot_close",sf_priority_10|sf_vol_2, ["close1.ogg","close2.ogg","close3.ogg","close4.ogg","close5.ogg","close6.ogg"]), #newgunsounds
("gunshot_medium",sf_priority_9|sf_vol_2, ["med1.ogg","med2.ogg","med3.ogg","med4.ogg","med5.ogg","med6.ogg"]), #newgunsounds
("gunshot_far",sf_priority_8|sf_vol_3, ["far1.ogg","far2.ogg","far3.ogg","far4.ogg","far5.ogg","far6.ogg","far7.ogg","far8.ogg","far9.ogg","far10.ogg","far11.ogg"]), #newgunsounds

Setting up item triggers
1. Add the following line to your gun in module_items.py
[(ti_on_weapon_attack,
[
(mission_cam_get_position, pos2),
(get_distance_between_positions_in_meters, ":dist", pos1, pos2),
(try_begin),
(ge, ":dist", 71),
(play_sound, "snd_gunshot_far"),
(else_try),
(is_between, ":dist", 40, 70),
(play_sound, "snd_gunshot_medium"),
(else_try),
(play_sound,"snd_gunshot_close"),
(try_end),
])]],
so it looks something like this
["flintlock_pistol", "Flintlock Pistol", [("flintlock_pistol",0)], itp_type_pistol |itp_merchandise|itp_primary ,itcf_shoot_pistol|itcf_reload_pistol, 230 , weight(1.5)|difficulty(0)|spd_rtng(39) | shoot_speed(200) | thrust_damage(45 ,pierce)|max_ammo(1)|accuracy(95),imodbits_none,
[(ti_on_weapon_attack,
[
(position_move_x, pos1, 27),(position_move_y, pos1, 36), #gun barrel end position
(mission_cam_get_position, pos2),
(get_distance_between_positions_in_meters, ":dist", pos1, pos2),
(try_begin),
(ge, ":dist", 71),
(play_sound, "snd_gunshot_far"),
(else_try),
(is_between, ":dist", 40, 70),
(play_sound, "snd_gunshot_medium"),
(else_try),
(play_sound,"snd_gunshot_close"),
(try_end),
(particle_system_burst, "psys_pistol_smoke", pos1, 15)
])]],
The red colored text is not relevant for the sounds, as its used for smoke effect.
The yellow text are the distance, feel free to adjust it yourself.

On a side note, you can change play_sound to agent_play_sound (or play_sound_at_position, but haven't tested that yet) so it plays at the player/camera's location, in case you want the sound to be clear (because most of the time I can't hear ****).
 
Last edited:

Cokjan

Squire
WBNW
Yup, I was trying to figure out how to use that guide but can't seem to wrap my head around that one. Then got a sudden enlightenment on how to make this one after messing around with making other stuff
 

Eärendil Ardamírë

Subforum Moderator
WBWF&SM&B
Thanks for writing down this tutorial!

You could also make use of the script game_missile_launch (you probably need to add it to your MS) to trigger the sound- and particle- effects. This also ensures that the script is working without problems in multiplayer.
ti_on_weapon_attack is only called server side.
Use the script game_missile_launch instead.
Code:
# script_game_missile_launch
# Input: arg1 = shooter_agent_id, arg2 = weapon_item_id, pos1 = weapon_item_position
# Output: none
("game_missile_launch",
[
    # (store_script_param, ":shooter_agent", 1),
    # (store_script_param, ":item", 2),
    # (neg|multiplayer_is_dedicated_server),#only client side
    #... add your stuf here
]),
Why the heck are you guys allways using the weapon attack trigger to apply sound- and particle effects?
This is horrible when it comes to network traffic, cause you'd have to synce the effects to all clients.

Use a game engine script instead, which is fired server- and clientside everytime a missile launches.

Perhaps your OSP can get improved with this. You can also enhance it with a functionality done by _Sebastian_:
I wrote a speed of sound simulation for Battle of Europe, it's pretty easy to implement;
Just click at the quote to go to the post, his code is posted there too.
 

Cokjan

Squire
WBNW
Ooh! Thanks for the info, I literally have no idea that there are game scripts that check for missile launch. Was that added in the latest module system?

For now, I'll change the topic's title so people know that it only works for singleplayer. Thanks again!
 

Eärendil Ardamírë

Subforum Moderator
WBWF&SM&B
Ooh! Thanks for the info, I literally have no idea that there are game scripts that check for missile launch. Was that added in the latest module system?
There are some game engine scripts which have been added with the DLCs NW and VC, mostly without big announcements. You can see them in your rgl log when they are saying that they are missing a game engine script. You can add them "empty", so without any op codes within the scripts (or commented out ones), so that there is one problem less listed at your module.
 

Cokjan

Squire
WBNW
Aha, that clears a lot on why I can't find any mention of triggers for distanced gun sounds in NW. Apparently there are 6 missing scripts in my rgl_log: game_check_party_sees_party, game_get_party_speed_multiplier ,game_missile_launch, game_missile_dives_into_water, game_troop_upgrades_button_clicked, and game_character_screen_requested. Now I wonder what I could make with those:party:
 
Yup, I was trying to figure out how to use that guide but can't seem to wrap my head around that one. Then got a sudden enlightenment on how to make this one after messing around with making other stuff
That was because the set of scripts was meant for MP, not SP. Yours is simple but should work out nicely.
Aha, that clears a lot on why I can't find any mention of triggers for distanced gun sounds in NW. Apparently there are 6 missing scripts in my rgl_log: game_check_party_sees_party, game_get_party_speed_multiplier ,game_missile_launch, game_missile_dives_into_water, game_troop_upgrades_button_clicked, and game_character_screen_requested. Now I wonder what I could make with those:party:
If you do not need any of those, just make a stub for every such game-engine script.
 
Top Bottom