WB Coding Assign a sound to scene prop whith pause

Currently viewing this thread:

Command store_mission_timer_a
Hello everyone, I have seen that this command is used to calculate the seconds and execute a certain action, my question is:
How can I occupy it to include it in an object (scene prop) so that every few seconds it makes a sound?
I have other scene prop with sounds, but these are constant sounds (there is no pause) and the sound I want to assign must at least have a pause of 10 or more seconds. Thanks in advance.
 
Last edited:
Solution
1- should I delete the other trigger?
2- in this code you have 2 different variables
3- the global variable, is defined in module_game_menu, where according to the scene and the faction with which I will fight, I assign my ship, I use it to move the ships of the different factions, since I assign a different ship per faction, but my ship , there are only 3
1 and 3) Let's use the first trigger i've written. Your code stores prop types in those global variables. we need prop instance ids so the second code may require additional code and global variables for the each ship.
2) ":prop_kind" and ":prop_type" is the same variable, typing mistake.

I assume you have 4 of...

RecursiveHarmony

I think you can use mission template triggers for that.
Reserve a slot to keep scene prop's time at the scene props. Set it to 0 at initialization.
Create a mission template trigger with a small unit interval like 0.1 seconds. Increase the slot value at every tick and use mod operation to decide when to play the sound. Mod operation can be used to determine whether or not a value is multiplier of another value. It gives you the remainder of a division. It becomes 0 when divident is multiplier of the divider. If you use 0.1 second interval,it takes 100 ticks to reach 10 seconds so you should take the slot mod 100 and compare it to 0. Related operation is 'store_mod'.
You can add some randomization via reserving another slot to keep next play time.Simply comparing the slots and increasing the other slot by a random value at each sound play. You should also set it to a random initial value at the start too.
 
Upvote 0
I think you can use mission template triggers for that.
Reserve a slot to keep scene prop's time at the scene props. Set it to 0 at initialization.
Create a mission template trigger with a small unit interval like 0.1 seconds. Increase the slot value at every tick and use mod operation to decide when to play the sound. Mod operation can be used to determine whether or not a value is multiplier of another value. It gives you the remainder of a division. It becomes 0 when divident is multiplier of the divider. If you use 0.1 second interval,it takes 100 ticks to reach 10 seconds so you should take the slot mod 100 and compare it to 0. Related operation is 'store_mod'.
You can add some randomization via reserving another slot to keep next play time.Simply comparing the slots and increasing the other slot by a random value at each sound play. You should also set it to a random initial value at the start too.
I forgot to mention that I am not a coder, I understand how coding works but what you kindly propose, for me it is impossible to develop for now.
I thought you could create a simpler code ... something with 5 lines or something like that.
I'm sorry you wasted your time explaining your idea ... sorry.
 
Upvote 0

RecursiveHarmony

I forgot to mention that I am not a coder, I understand how coding works but what you kindly propose, for me it is impossible to develop for now.
I thought you could create a simpler code ... something with 5 lines or something like that.
I'm sorry you wasted your time explaining your idea ... sorry.
It may sound difficult when you read my overly detailed explanation,but actually it's not that complicated. Here is a sample code i've written.
Code:
# Reserved to store tick counts. Can be anything unused.
# Place this into the module_constants. Under scene prop slots.
scene_prop_slot_tick_count = 20

# Mission template trigger.
(0.1, 0, 0, [],
       [
       # Loop through the props.
       (try_for_prop_instances, ":prop"),
         # Get tick counts. Increase it. Set it back. Once per trigger tick.
         (scene_prop_get_slot, "tick_count", ":prop", scene_prop_slot_tick_count),
         (val_add, "tick_count", 1),
         # Check for time to play sound.
         (try_begin),
           (store_mod, ":result", "tick_count", 100),
           (eq, ":result", 0),
           (prop_instance_play_sound, ":prop", "snd_click"),
         (try_end),
         (scene_prop_set_slot, ":prop", scene_prop_slot_tick_count, "tick_count"),
       (try_end),                     
        ]),
Writing the code took less time than that comment :lol:
I skipped setting the slot to zero. It's probably done automatically by the engine. Also there is an operation named as 'prop_instance_stop_sound'. I guess you don't have to use it unless you set the 'sf_looping' flag of the sound to play.
 
Upvote 0
It may sound difficult when you read my overly detailed explanation,but actually it's not that complicated. Here is a sample code i've written.
Code:
# Reserved to store tick counts. Can be anything unused.
# Place this into the module_constants. Under scene prop slots.
scene_prop_slot_tick_count = 20

# Mission template trigger.
(0.1, 0, 0, [],
       [
       # Loop through the props.
       (try_for_prop_instances, ":prop"),
         # Get tick counts. Increase it. Set it back. Once per trigger tick.
         (scene_prop_get_slot, "tick_count", ":prop", scene_prop_slot_tick_count),
         (val_add, "tick_count", 1),
         # Check for time to play sound.
         (try_begin),
           (store_mod, ":result", "tick_count", 100),
           (eq, ":result", 0),
           (prop_instance_play_sound, ":prop", "snd_click"),
         (try_end),
         (scene_prop_set_slot, ":prop", scene_prop_slot_tick_count, "tick_count"),
       (try_end),                    
        ]),
Writing the code took less time than that comment :lol:
I skipped setting the slot to zero. It's probably done automatically by the engine. Also there is an operation named as 'prop_instance_stop_sound'. I guess you don't have to use it unless you set the 'sf_looping' flag of the sound to play.
Thanks friend, I will try it and tell you, basically the sound I want is to set my ship on the high seas (I already have several sounds that I will try), in naval battles, so as I told you, I will test it and then tell you ... ..
Your comment made me laugh because it took you hands off your explanation hahaha. :grin:
 
Upvote 0
@RecursiveHarmony
I tried the trigger, but I modified some things, I got an error about the tick prefix, I concluded that it was a variable so I put 2 points (: tick_count). First I tried my sound, which lasted 9 seconds and had a strange sound, which I could barely distinguish and it repeated, the closer I got to the other boats. Then I put the click sound, to see how it worked, I realized that I had a 2d flag and added it to my sound, then I put another variable, replacing the: prop (another global one that identifies any of the ships in which I mobilize), the click, it sounded good, every few seconds, but once in the enemy ship, it was repeated many times, lower and higher, sometimes one on top of the other ...
I lowered the power to the sound with an editor, so it sounds better, but in one way or another, the sound with 1 priority and 1 volume, when it sounds, does not let you hear the other sounds, for example gunshots, screams , steps, etc.
What should I do to change that?
 
Upvote 0

RecursiveHarmony

I tried the trigger, but I modified some things, I got an error about the tick prefix, I concluded that it was a variable so I put 2 points (: tick_count)
Yeah i missed that :smile: it's a local variable. Sorry for that.
First I tried my sound, which lasted 9 seconds and had a strange sound, which I could barely distinguish and it repeated, the closer I got to the other boats. Then I put the click sound, to see how it worked, I realized that I had a 2d flag and added it to my sound, then I put another variable, replacing the: prop (another global one that identifies any of the ships in which I mobilize), the click, it sounded good, every few seconds, but once in the enemy ship, it was repeated many times, lower and higher, sometimes one on top of the other ...
I lowered the power to the sound with an editor, so it sounds better, but in one way or another, the sound with 1 priority and 1 volume, when it sounds, does not let you hear the other sounds, for example gunshots, screams , steps, etc.
What should I do to change that?
In the code, as i said 'sample code', i didn't write anything to distinguish between the scene props. It's probably playing the sound for every prop in the scene, if you didn't write anything for that job.
try_for_prop_instances = 16 # (try_for_prop_instances, <destination>, [<scene_prop_id>]), # if scene_prop_id is not given, it loops through all prop instances.
Loop has an optional variable. You can pass ship prop's type to it and it only plays for the ship.
Code:
# Reserved to store tick counts. Can be anything unused.
# Place this into the module_constants. Under scene prop slots.
scene_prop_slot_tick_count = 20

# Mission template trigger.
(0.1, 0, 0, [],
       [
       # Loop through the props.
       (try_for_prop_instances, ":prop", "spr_ship"),
         # Get tick counts. Increase it. Set it back. Once per trigger tick.
         (scene_prop_get_slot, ":tick_count", ":prop", scene_prop_slot_tick_count),
         (val_add, ":tick_count", 1),
         # Check for time to play sound.
         (try_begin),
           (store_mod, ":result", ":tick_count", 100),
           (eq, ":result", 0),
           (prop_instance_play_sound, ":prop", "snd_click"),
         (try_end),
         (scene_prop_set_slot, ":prop", scene_prop_slot_tick_count, ":tick_count"),
       (try_end),                   
        ]),
 
Upvote 0
Yeah i missed that :smile: it's a local variable. Sorry for that.

In the code, as i said 'sample code', i didn't write anything to distinguish between the scene props. It's probably playing the sound for every prop in the scene, if you didn't write anything for that job.

Loop has an optional variable. You can pass ship prop's type to it and it only plays for the ship.
Code:
# Reserved to store tick counts. Can be anything unused.
# Place this into the module_constants. Under scene prop slots.
scene_prop_slot_tick_count = 20

# Mission template trigger.
(0.1, 0, 0, [],
       [
       # Loop through the props.
       (try_for_prop_instances, ":prop", "spr_ship"),
         # Get tick counts. Increase it. Set it back. Once per trigger tick.
         (scene_prop_get_slot, ":tick_count", ":prop", scene_prop_slot_tick_count),
         (val_add, ":tick_count", 1),
         # Check for time to play sound.
         (try_begin),
           (store_mod, ":result", ":tick_count", 100),
           (eq, ":result", 0),
           (prop_instance_play_sound, ":prop", "snd_click"),
         (try_end),
         (scene_prop_set_slot, ":prop", scene_prop_slot_tick_count, ":tick_count"),
       (try_end),                  
        ]),
well, I tried the following:
I assigned the global variable of my ships to prop (assign, ": prop", "$ g_my_boat"), and left my sound like this ("tide", sf_2d | sf_priority_1 | sf_vol_1, ["tide.wav"]), the sound , with the volume at the maximum of the game, it is heard moderate, but, even with that description in module sound, it does not allow the other sounds to be heard ... that is, the sound of the sea takes precedence over any sound that exists in the scene, no matter what volume or priority they have.
 
Upvote 0

RecursiveHarmony

well, I tried the following:
I assigned the global variable of my ships to prop (assign, ": prop", "$ g_my_boat"), and left my sound like this ("tide", sf_2d | sf_priority_1 | sf_vol_1, ["tide.wav"]), the sound , with the volume at the maximum of the game, it is heard moderate, but, even with that description in module sound, it does not allow the other sounds to be heard ... that is, the sound of the sea takes precedence over any sound that exists in the scene, no matter what volume or priority they have.
If you're using a global variable, you don't need to loop through all the props. You can use something like this.
Code:
(10.0, 0, 0, 
       [
         # Conditions.
         # Checking the global variable for null cases.
         (prop_instance_is_valid, "$ g_my_boat")
         (prop_instance_get_scene_prop_kind, ":prop_type", "$ g_my_boat")
         (eq, ":prop_kind", "spr_ship") # Replace the prop type.
       ],
       [
         (prop_instance_play_sound, "$ g_my_boat", "snd_tide"),
       ]),
If you can be sure about when the trigger runs, the global variable is set properly, then you can delete the conditions part.
 
Upvote 0
Si está utilizando una variable global, no necesita recorrer todos los accesorios. Puedes usar algo como esto.
[CÓDIGO] (10.0, 0, 0,
[
# Condiciones.
# Verificando la variable global para casos nulos.
(prop_instance_is_valid, "$ g_my_boat")
(prop_instance_get_scene_prop_kind, ": prop_type", "$ g_my_boat")
(eq, ": prop_kind", "spr_ship") # Reemplaza el tipo de prop.
],
[
(prop_instance_play_sound, "$ g_my_boat", "snd_tide"),
]),[/CÓDIGO]
Si puede estar seguro de cuándo se ejecuta el activador, la variable global está configurada correctamente, entonces puede eliminar la parte de condiciones.
well, but ...
1- should I delete the other trigger?
2- in this code you have 2 different variables
3- the global variable, is defined in module_game_menu, where according to the scene and the faction with which I will fight, I assign my ship, I use it to move the ships of the different factions, since I assign a different ship per faction, but my ship , there are only 3
 
Last edited:
Upvote 0
here is an excerpt of the code in game_menu, under the one that moves one of the ships in mission_template (mission ship_battle)

Code:
(try_begin),
               (party_get_template_id, ":encountered_party_template", "$g_encountered_party"),
               (neq, ":encountered_party_template", "pt_kingdom_caravan_party"),
               (neq, ":encountered_party_template", "pt_village_farmers"),
               (eq, "$g_encountered_party_faction", "fac_kingdom_1"),
               (assign, "$g_mi_barco", "spr_fragata_4"),
               (assign, "$g_barco2", "spr_fragata1"),
               (jump_to_scene, "scn_sea_5"),
            (try_end), [/ CODE]

and on the mission template.

[CODE](0, 0, ti_once, [
    (entry_point_get_position, pos0, 45),(set_spawn_position, pos0),(spawn_scene_prop,"$g_mi_barco"),
    ], []),

(0, 0, ti_once,
    [
    (entry_point_get_position, pos21, 21),
    (scene_prop_get_instance,":prop","$g_mi_barco", 0),
    (prop_instance_get_starting_position, pos1, ":prop"),
    (scene_prop_get_instance,":prop","$g_mi_barco", 0),
    (prop_instance_get_position, pos1, ":prop"),
    (get_distance_between_positions, ":dist_falcon", pos1, pos21),
    (store_div,":falcon_hiz",":dist_falcon",3),
    (prop_instance_animate_to_position, ":prop", pos21, ":falcon_hiz"),
], []),
 
Last edited:
Upvote 0

RecursiveHarmony

1- should I delete the other trigger?
2- in this code you have 2 different variables
3- the global variable, is defined in module_game_menu, where according to the scene and the faction with which I will fight, I assign my ship, I use it to move the ships of the different factions, since I assign a different ship per faction, but my ship , there are only 3
1 and 3) Let's use the first trigger i've written. Your code stores prop types in those global variables. we need prop instance ids so the second code may require additional code and global variables for the each ship.
2) ":prop_kind" and ":prop_type" is the same variable, typing mistake.

I assume you have 4 of those ship models. "spr_fragata_1", "spr_fragata_2", "spr_fragata_3" and "spr_fragata_4". If you have more, change the code accordingly.
Code:
# Reserved to store tick counts. Can be anything unused.
# Place this into the module_constants. Under scene prop slots.
scene_prop_slot_tick_count = 20

# Mission template trigger.
(0.1, 0, 0, [],
       [
       # Loop through the props.
       (try_for_prop_instances, ":prop"),
         # Check for ships.
         (prop_instance_get_scene_prop_kind, ":prop_kind", ":prop"),
         (this_or_next | eq, ":prop_kind", "spr_fragata_1"),
         (this_or_next | eq, ":prop_kind", "spr_fragata_2"),
         (this_or_next | eq, ":prop_kind", "spr_fragata_3"),
         (eq, ":prop_kind", "spr_fragata_4"),
         # Get tick counts. Increase it. Set it back. Once per trigger tick.
         (scene_prop_get_slot, ":tick_count", ":prop", scene_prop_slot_tick_count),
         (val_add, ":tick_count", 1),
         # Check for time to play sound.
         (try_begin),
           (store_mod, ":result", ":tick_count", 100),
           (eq, ":result", 0),
           (prop_instance_play_sound, ":prop", "snd_tide"),
         (try_end),
         (scene_prop_set_slot, ":prop", scene_prop_slot_tick_count, ":tick_count"),
       (try_end),                  
        ]),
 
Upvote 1
Solution
1 and 3) Let's use the first trigger i've written. Your code stores prop types in those global variables. we need prop instance ids so the second code may require additional code and global variables for the each ship.
2) ":prop_kind" and ":prop_type" is the same variable, typing mistake.

I assume you have 4 of those ship models. "spr_fragata_1", "spr_fragata_2", "spr_fragata_3" and "spr_fragata_4". If you have more, change the code accordingly.
Code:
# Reserved to store tick counts. Can be anything unused.
# Place this into the module_constants. Under scene prop slots.
scene_prop_slot_tick_count = 20

# Mission template trigger.
(0.1, 0, 0, [],
       [
       # Loop through the props.
       (try_for_prop_instances, ":prop"),
         # Check for ships.
         (prop_instance_get_scene_prop_kind, ":prop_kind", ":prop"),
         (this_or_next | eq, ":prop_kind", "spr_fragata_1"),
         (this_or_next | eq, ":prop_kind", "spr_fragata_2"),
         (this_or_next | eq, ":prop_kind", "spr_fragata_3"),
         (eq, ":prop_kind", "spr_fragata_4"),
         # Get tick counts. Increase it. Set it back. Once per trigger tick.
         (scene_prop_get_slot, ":tick_count", ":prop", scene_prop_slot_tick_count),
         (val_add, ":tick_count", 1),
         # Check for time to play sound.
         (try_begin),
           (store_mod, ":result", ":tick_count", 100),
           (eq, ":result", 0),
           (prop_instance_play_sound, ":prop", "snd_tide"),
         (try_end),
         (scene_prop_set_slot, ":prop", scene_prop_slot_tick_count, ":tick_count"),
       (try_end),                 
        ]),
Now it works well friend, thank you, pass it by, so fighting in a naval battle gives it more realism --- excellent:wink:

PS Sorry, for not answering earlier, you know there is a time difference, last night when you answered me, I couldn't try and it was too late.
 
Upvote 0
Top Bottom