summaryrefslogtreecommitdiff
path: root/api.lua
diff options
context:
space:
mode:
authorWuzzy <almikes@aol.com>2016-09-01 16:05:42 +0200
committerrubenwardy <rubenwardy@gmail.com>2016-09-01 16:32:05 +0100
commit90bf9b061ad58fdf4c62d2d064cf7826a466f9b6 (patch)
tree80ca48fe036cecbe2b10b2d1a4341f1c8415b9af /api.lua
parent0e48cd8675268700797b9365c2c7bc64fcc50f4a (diff)
Add notification sound
License of default sound: CC-0 Source: https://www.freesound.org/people/Kastenfrosch/sounds/162482/
Diffstat (limited to 'api.lua')
-rw-r--r--api.lua14
1 files changed, 14 insertions, 0 deletions
diff --git a/api.lua b/api.lua
index 19f055f..23a9ef9 100644
--- a/api.lua
+++ b/api.lua
@@ -227,6 +227,11 @@ function awards.unlock(name, award)
local desc = awdef.description or ""
local background = awdef.background or "awards_bg_default.png"
local icon = awdef.icon or "awards_unknown.png"
+ local sound = awdef.sound
+ if sound == nil then
+ -- Explicit check for nil because sound could be `false` to disable it
+ sound = {name="awards_got_generic", gain=0.25}
+ end
local custom_announce = awdef.custom_announce
if not custom_announce then
if awdef.secret then
@@ -237,6 +242,15 @@ function awards.unlock(name, award)
end
-- Do Notification
+ if sound then
+ -- Enforce sound delay to prevent sound spamming
+ local lastsound = awards.players[name].lastsound
+ if lastsound == nil or os.difftime(os.time(), lastsound) >= 1 then
+ minetest.sound_play(sound, {to_player=name})
+ awards.players[name].lastsound = os.time()
+ end
+ end
+
if awards.show_mode == "formspec" then
-- use a formspec to send it
minetest.show_formspec(name, "achievements:unlocked", "size[4,2]"..