guns4d-cd2025/docs/module/play_sound.html
2025-01-03 16:14:00 -08:00

252 lines
10 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<!-- Documentation generated by LuaDox: https://github.com/jtackaberry/luadox -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>play_sound - Guns4d</title>
<link href="../prism.css?7653a2d" rel="stylesheet" />
<link rel="stylesheet" href="../luadox.css?7653a2d" type="text/css">
</head>
<body class="module-play_sound">
<div class="topbar">
<div class="group one">
<div class="description"><span>Guns4d | The ultimate 3d gun mod.</span></div>
</div>
<div class="group two">
</div>
<div class="group three">
<div class="button iconleft"><a href="../module/misc_helpers.html" title="misc_helpers"><img src="../img/i-left.svg?7653a2d" alt=""/><span>Previous</span></a></div>
<div class="button iconright"><a href="../module/Bullet_hole.html" title="Bullet_hole"><span>Next</span><img src="../img/i-right.svg?7653a2d" alt=""/></a></div>
</div>
</div>
<div class="sidebar">
<form action="../search.html">
<input class="search" name="q" type="search" placeholder="Search" />
</form>
<div class="sections">
<div class="heading">Contents</div>
<ul>
<li><a href="#play_sound">Module <code>play_sound</code></a></li>
<li><a href="#guns4d_soundspec"><p>Guns4d soundspec</p>
</a></li>
</ul>
</div>
<div class="manual">
<div class="heading">Manual</div>
<ul>
<li><a href="../manual/changelog.html">changelog 1.3.0</a></li>
</ul>
</div>
<div class="classes">
<div class="heading">Classes</div>
<ul>
<li><a href="../class/gun.html">Gun.gun</a></li>
<li><a href="../class/player_model_handler.html">Player_model_handler.player_model_handler</a></li>
</ul>
</div>
<div class="modules">
<div class="heading">Modules</div>
<ul>
<li><a href="../module/misc_helpers.html">misc_helpers</a></li>
<li class="selected"><a href="../module/play_sound.html">play_sound</a></li>
<li><a href="../module/Bullet_hole.html">Bullet_hole</a></li>
<li><a href="../module/Control_handler.html">Control_handler</a></li>
<li><a href="../module/Gun-methods.html">Gun-methods</a></li>
</ul>
</div>
</div>
<div class="body">
<div class="section">
<h2 class="module" id="play_sound">Module <code>play_sound</code>
<a class="permalink" href="#play_sound" title="Permalink to this definition"></a>
</h2>
<div class="inner">
<p>implements tools for quickly playing audio.</p>
<div class="synopsis">
<h3>Synopsis</h3>
<div class="heading">Functions</div>
<table class="functions ">
<tr>
<td class="name"><a href="#Guns4d.play_sounds"><var>Guns4d.play_sounds</var></a>()</td>
<td class="doc"><p>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</p>
</td>
</tr>
<tr>
<td class="name"><a href="#Guns4d.get_sounds"><var>Guns4d.get_sounds</var></a>()</td>
<td class="doc"><p>gets a list of currently playing Minetest sound handles from the Guns4d sound handle</p>
</td>
</tr>
<tr>
<td class="name"><a href="#Guns4d.stop_sounds"><var>Guns4d.stop_sounds</var></a>()</td>
<td class="doc"><p>stops a list of sounds</p>
</td>
</tr>
</table>
</div>
<dl class="functions">
<dt id="Guns4d.play_sounds">
<span class="icon"></span><var>Guns4d.play_sounds</var>(<em>soundspecs_list</em>)
<a class="permalink" href="#Guns4d.play_sounds" title="Permalink to this definition"></a>
</dt>
<dd>
<p>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.</p>
<p>WARNING: this function modifies the tables passed to it, use <code>Guns4d.table.shallow_copy()</code> or <code>table.copy</code> for inputted soundspecs</p>
<h5>Example</h5>
<pre><code class="language-lua">{
to_player = &quot;singeplayer&quot;,
min_distance = 100, --soundspec_to_play1 &amp; 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
}
</code></pre>
<div class="heading">Parameters</div>
<table class="parameters">
<tr>
<td class="name"><var>soundspecs_list</var></td>
<td class="types">(<em><a href="../module/misc_helpers.html#table">table</a></em>)</td>
<td class="doc"><p>a list a list of soundspecs optionally accompanied with fields to be used in all of them.</p>
</td>
</tr>
</table>
<div class="heading">Return Values</div>
<table class="returns">
<tr>
<td class="types">(<em>integer</em>)</td>
<td class="doc"><p>guns4d sound handle, used by stop_sounds &amp; get_sounds</p>
</td>
</tr>
</table>
</dd>
<dt id="Guns4d.get_sounds">
<span class="icon"></span><var>Guns4d.get_sounds</var>(<em>handle</em>)
<a class="permalink" href="#Guns4d.get_sounds" title="Permalink to this definition"></a>
</dt>
<dd>
<p>gets a list of currently playing Minetest sound handles from the Guns4d sound handle. Modification of table highly discouraged.</p>
<div class="heading">Parameters</div>
<table class="parameters">
<tr>
<td class="name"><var>handle</var></td>
<td class="types">(<em>integer</em>)</td>
<td class="doc"><p>a sound handle as returned by play_sounds</p>
</td>
</tr>
</table>
<div class="heading">Return Values</div>
<table class="returns">
<tr>
<td class="types">(<em><a href="../module/misc_helpers.html#table">table</a></em>)</td>
<td class="doc"><p>a list of sound handles as returned by minetest.sound_play()</p>
</td>
</tr>
</table>
</dd>
<dt id="Guns4d.stop_sounds">
<span class="icon"></span><var>Guns4d.stop_sounds</var>(<em>handle</em>)
<a class="permalink" href="#Guns4d.stop_sounds" title="Permalink to this definition"></a>
</dt>
<dd>
<p>stops a list of sounds</p>
<div class="heading">Parameters</div>
<table class="parameters">
<tr>
<td class="name"><var>handle</var></td>
<td class="types">(<em>integer</em> or <em><a href="../module/misc_helpers.html#table">table</a></em>)</td>
<td class="doc"><p>a guns4d sound handle OR list of minetest sound handles to stop</p>
</td>
</tr>
</table>
<div class="heading">Return Values</div>
<table class="returns">
<tr>
<td class="types">(<em>bool</em>)</td>
<td class="doc"><p>returns true if successful.</p>
</td>
</tr>
</table>
</dd>
</dl>
</div>
</div>
<div class="section">
<h2 class="table" id="guns4d_soundspec">Guns4d soundspec
<a class="permalink" href="#guns4d_soundspec" title="Permalink to this definition"></a>
</h2>
<div class="inner">
<p>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.</p>
<h5>Example</h5>
<pre><code class="language-lua">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.
}
</code></pre>
<div class="synopsis">
<table class="fields compact">
<tr>
<td class="name"><var id="guns4d_soundspec.min_hear_distance">min_hear_distance</var><a class="permalink" href="#guns4d_soundspec.min_hear_distance" title="Permalink to this definition"></a></td>
<td class="doc"><p><code>float</code> this is useful if you wish to play a sound which has a &quot;far&quot; sound, such as distant gunshots. incompatible <code>with to_player</code></p>
</td>
</tr>
<tr>
<td class="name"><var id="guns4d_soundspec.sounds">sounds</var><a class="permalink" href="#guns4d_soundspec.sounds" title="Permalink to this definition"></a></td>
<td class="doc"><p><a href="../module/misc_helpers.html#table"><code>table</code></a> a weighted_randoms table for randomly selecting sounds. The output will overwrite the <code>sound</code> field.</p>
</td>
</tr>
<tr>
<td class="name"><var id="guns4d_soundspec.to_player">to_player</var><a class="permalink" href="#guns4d_soundspec.to_player" title="Permalink to this definition"></a></td>
<td class="doc"><p><code>objRef</code> 4dguns changes <a href="../module/play_sound.html#guns4d_soundspec.to_player"><code>to_player</code></a> so it only plays positionless audio (as it is only intended for first person audio). If set to string &quot;from_player&quot; and player present</p>
</td>
</tr>
<tr>
<td class="name"><var id="guns4d_soundspec.player">player</var><a class="permalink" href="#guns4d_soundspec.player" title="Permalink to this definition"></a></td>
<td class="doc"><p><code>objRef</code> this is so to_player being set to &quot;from_player&quot;. It's to be set to the player which fired the weapon.</p>
</td>
</tr>
<tr>
<td class="name"><var id="guns4d_soundspec.delay">delay</var><a class="permalink" href="#guns4d_soundspec.delay" title="Permalink to this definition"></a></td>
<td class="doc"><p><code>float</code> delays the playing of the sound</p>
</td>
</tr>
<tr>
<td class="name"><var id="guns4d_soundspec.attenuation_rate">attenuation_rate</var><a class="permalink" href="#guns4d_soundspec.attenuation_rate" title="Permalink to this definition"></a></td>
<td class="doc"><p><code>float</code> 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.</p>
</td>
</tr>
<tr>
<td class="name"><var id="guns4d_soundspec.split_audio_by_perspective">split_audio_by_perspective</var><a class="permalink" href="#guns4d_soundspec.split_audio_by_perspective" title="Permalink to this definition"></a></td>
<td class="doc"><p><code>bool</code> [GUN CLASS SPECIFIC] tells the gun wether to split into third and first person (positionless) audio and adjust gain.</p>
</td>
</tr>
<tr>
<td class="name"><var id="guns4d_soundspec.third_person_gain_multiplier">third_person_gain_multiplier</var><a class="permalink" href="#guns4d_soundspec.third_person_gain_multiplier" title="Permalink to this definition"></a></td>
<td class="doc"><p><code>float</code> [GUN CLASS SPECIFIC] replaces the constant/config value &quot;third_person_gain_multiplier/THIRD_PERSON_GAIN_MULTIPLIER&quot;.</p>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<script src="../prism.js?7653a2d"></script>
</body>
</html>