Guns4d | The ultimate 3d gun mod.
Previous
Next

## Module `play_sound` ¶

implements tools for quickly playing audio.

### Synopsis

Functions

Guns4d.play_sounds() | allows you to play one or more sounds with more complex features, so sounds can be easily coded for guns without the need for functions
Guns4d.get_sounds() | gets a list of currently playing Minetest sound handles from the Guns4d sound handle
Guns4d.stop_sounds() | stops a list of sounds

Guns4d.play_sounds(soundspecs_list) ¶

  allows you to play one or more sounds with more complex features, so sounds can be easily coded for guns without the need for functions.

  WARNING: this function modifies the tables passed to it, use `Guns4d.table.shallow_copy()` or `table.copy` for inputted soundspecs

  ##### Example

      {
          to_player = "singeplayer",
          min_distance = 100, --soundspec_to_play1 & soundspec_to_play2 will share this field as it is in the higher level table (as well as the above field)
          soundspec_to_play1, --a sound parameter table
          soundspec_to_play2
      }

  Parameters

  soundspecs_list | (table) | a list a list of soundspecs optionally accompanied with fields to be used in all of them.

  Return Values

  (integer) | guns4d sound handle, used by stop_sounds & get_sounds

Guns4d.get_sounds(handle) ¶

  gets a list of currently playing Minetest sound handles from the Guns4d sound handle. Modification of table highly discouraged.

  Parameters

  handle | (integer) | a sound handle as returned by play_sounds

  Return Values

  (table) | a list of sound handles as returned by minetest.sound_play()

Guns4d.stop_sounds(handle) ¶

  stops a list of sounds

  Parameters

  handle | (integer or table) | a guns4d sound handle OR list of minetest sound handles to stop

  Return Values

  (bool) | returns true if successful.

## Guns4d soundspec ¶

simple specification for playing a sound in relation to an action, acts as a layer of minetest.play_sound. ATTENTION: read lua_api.md for more parameters! all parameters from there are valid unless otherwise stated here, these are auxillary.

##### Example

    soundspec = {
      sounds = { --weighted randoms
          fire_fp = .5.
          fire_fp_2 = .2.
          fire_fp_3 = .3
      },
      pitch = {
          min = .6,
          max = 1
      },
      gain = 1, --format for pitch and gain is interchangable.
      min_hear_distance = 20, --this is for distant gunshots, for example. Entirely optional. Cannot be used with to_player
      exclude_player
      to_player
        --when present it automatically plays positionless audio, as this is for first person effects.
    }

min_hear_distance¶ | `float` this is useful if you wish to play a sound which has a "far" sound, such as distant gunshots. incompatible `with to_player`
sounds¶ | `table` a weighted_randoms table for randomly selecting sounds. The output will overwrite the `sound` field.
to_player¶ | `objRef` 4dguns changes `to_player` so it only plays positionless audio (as it is only intended for first person audio). If set to string "from_player" and player present
player¶ | `objRef` this is so to_player being set to "from_player". It's to be set to the player which fired the weapon.
delay¶ | `float` delays the playing of the sound
attenuation_rate¶ | `float` the rate of dropoff for a sound. I figure this is a bit more intuitive then jacking the gain up super high for every sound... Set the default in config.
split_audio_by_perspective¶ | `bool` [GUN CLASS SPECIFIC] tells the gun wether to split into third and first person (positionless) audio and adjust gain.
third_person_gain_multiplier¶ | `float` [GUN CLASS SPECIFIC] replaces the constant/config value "third_person_gain_multiplier/THIRD_PERSON_GAIN_MULTIPLIER".