StendhalScripting/Lua: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>AntumDeluge
Adding Transitions: nested tables
imported>AntumDeluge
Setting Zone: add zone music
Line 232: Line 232:
* <code>npcHelper:addBuyer(npc, items, offer)</code> - Adds buyer merchant behavior to <code>npc</code>.
* <code>npcHelper:addBuyer(npc, items, offer)</code> - Adds buyer merchant behavior to <code>npc</code>.


== Setting Zone ==
== Zones ==

=== Setting Zone ===


To set the zone to work with, use the <code>game</code> object:
To set the zone to work with, use the <code>game</code> object:
Line 248: Line 250:
else
else
logger:error("Could not set zone: " .. zone)
logger:error("Could not set zone: " .. zone)
end
</pre>

=== Create New Zone ===

It is recommended to create new zones in the XML configurations in {{StendhalFile|master|data/conf/zones|data/conf/zones}}.

Currently creating new zones via Lua is not supported.

=== Add Zone Music ===

Music can be added to zones with the <code>setZoneMusic</code> global function. It supports the following arguments:
* ''filename:'' Basename of the OGG audio file to use stored in {{StendhalFile|master|data/music|data/music}}.
* ''volume:'' (optional) Volume level.
* ''x:'' (optional) The horizontal point for the source of the music.
* ''y:'' (optional) The vertical point for the source of the music.
* ''radius:'' (optional) The radial range at which the music can be heard.

Example:
<pre>
if game:setZone("0_semos_plains_n") then
setZoneMusic("pleasant_creek_loop", 85)
end
end
</pre>
</pre>