diff --git a/LICENSE.md b/LICENSE.md index 81a499f..02969ac 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,3 +1,17 @@ #License -- Code: GPLv3 +## Code + +- GPLv3 + +## Sounds: + +- pickp_alarm.ogg +-- Author= djlprojects +-- url= https://freesound.org/people/djlprojects/sounds/413641/ +-- License= This work is licensed under the Creative Commons 0 License. + +- pickp_fail.ogg +-- Author= HipsterTypist +-- url= https://freesound.org/people/HipsterTypist/sounds/527491/ +-- License= This work is licensed under the Creative Commons 0 License. diff --git a/init.lua b/init.lua index 560d8f6..d5bc3ae 100644 --- a/init.lua +++ b/init.lua @@ -21,6 +21,17 @@ local function deepCopy(original) return copy end +function pickp.make_sound(dest_type, dest, soundfile, max_hear_distance) + if dest_type == "object" then + minetest.sound_play(soundfile, {object = dest, gain = 0.5, max_hear_distance = max_hear_distance or 10,}) + elseif dest_type == "player" then + local player_name = dest:get_player_name() + minetest.sound_play(soundfile, {to_player = player_name, gain = 0.5, max_hear_distance = max_hear_distance or 10,}) + elseif dest_type == "pos" then + minetest.sound_play(soundfile, {pos = dest, gain = 0.5, max_hear_distance = 10 or max_hear_distance,}) + end +end + local function enable_steal(clicker, clicked, rob_table, angle_2d) local steal_table = {} steal_table["clicked"] = clicked:get_player_name() @@ -183,7 +194,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end stealth_ratio = stealth_ratio - type_item_reduction_factor - if math.random(0,1) >= stealth_ratio then --NOT detected + if math.random(0,1) >= stealth_ratio then + --NOT detected minetest.chat_send_player(player:get_player_name(), S("Successful robbery!")) else --DETECTION WARNING @@ -196,6 +208,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end if not (msg == "") then minetest.chat_send_player(clicked_name, msg) + if pickp.settings["sound_alarm"] then + pickp.make_sound("player", clicked, "pickp_alarm", 10) + end end end else @@ -237,6 +252,9 @@ local function stealth(clicker, clicked) end --DETECTED! disable_stealth(clicker, true, "Failed Robbery!") + if pickp.settings["sound_fail"] then + pickp.make_sound("player", clicker, "pickp_fail", 10) + end --DETECTION WARNING local msg = "" if math.random(0,1) <= pickp.settings["warning_failed_thief_ratio"] then @@ -246,6 +264,9 @@ local function stealth(clicker, clicked) end if not (msg == "") then minetest.chat_send_player(clicked_name, msg) + if pickp.settings["sound_alarm"] then + pickp.make_sound("player", clicked, "pickp_alarm", 10) + end end end @@ -260,6 +281,9 @@ local function pickpocketing(clicker, clicked) minetest.after(pickp.settings["stealth_timing"], stealth, clicker, clicked) else minetest.chat_send_player(clicker_name, S("Failed robbery!")) + if pickp.settings["sound_fail"] then + pickp.make_sound("player", clicker, "pickp_fail", 10) + end end end diff --git a/pickp.conf b/pickp.conf index b3e69df..ad48b45 100644 --- a/pickp.conf +++ b/pickp.conf @@ -40,3 +40,7 @@ warning_failed_thief_ratio = 0.5 ##it depends on the item type [main|hotbar] warning_hotbar_item = 0.6 warning_main_item = 0.2 + +#Sounds +sound_fail = true +sound_alarm = true diff --git a/settings.lua b/settings.lua index 7022eef..0050dbf 100644 --- a/settings.lua +++ b/settings.lua @@ -17,4 +17,6 @@ pickp.settings.zone3_stealth_ratio = tonumber(settings:get("zone3_stealth_ratio" pickp.settings.warning_failed_thief_ratio = tonumber(settings:get("warning_failed_thief_ratio")) pickp.settings.warning_hotbar_item = tonumber(settings:get("warning_hotbar_item")) pickp.settings.warning_main_item = tonumber(settings:get("warning_main_item")) +pickp.settings.sound_alarm = settings:get_bool("sound_alarm") +pickp.settings.sound_fail = settings:get_bool("sound_fail") diff --git a/sounds/pickp_alarm.ogg b/sounds/pickp_alarm.ogg new file mode 100644 index 0000000..1643c89 Binary files /dev/null and b/sounds/pickp_alarm.ogg differ diff --git a/sounds/pickp_fail.ogg b/sounds/pickp_fail.ogg new file mode 100644 index 0000000..d4f7b89 Binary files /dev/null and b/sounds/pickp_fail.ogg differ