From 9af6b017524b0419aaa1fa5e44a1fdf34a9f9330 Mon Sep 17 00:00:00 2001 From: runs Date: Sat, 2 Jan 2021 00:46:51 +0100 Subject: [PATCH] addons --- LICENSE.md | 3 ++ init.lua | 74 ++++++++++++++++++++++++++++++++++------------ locale/pickp.es.tr | 2 ++ pickp.conf | 6 +++- settings.lua | 2 ++ 5 files changed, 67 insertions(+), 20 deletions(-) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..81a499f --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,3 @@ +#License + +- Code: GPLv3 diff --git a/init.lua b/init.lua index 77df973..b43cbd1 100644 --- a/init.lua +++ b/init.lua @@ -21,9 +21,10 @@ local function deepCopy(original) return copy end -local function enable_steal(clicker, clicked, rob_table) +local function enable_steal(clicker, clicked, rob_table, angle_2d) local steal_table = {} steal_table["clicked"] = clicked:get_player_name() + steal_table["angle_2d"] = angle_2d steal_table["items"] = deepCopy(rob_table) _contexts[clicker:get_player_name()] = steal_table end @@ -112,7 +113,7 @@ local function get_rob_list(clicked) .. item_name .. ";item_name;"..tostring(i).."]" end end - minetest.chat_send_all("rob_list="..rob_list) + --minetest.chat_send_all("rob_list="..rob_list) return rob_list, list_hotbar end @@ -123,6 +124,27 @@ local function get_formspec(clicker, clicked, rob_list) return formspec end +local function get_angle(clicker, clicked) + local clicker_look_view = clicker:get_look_dir() + local x1 = clicker_look_view.x + local z1 = clicker_look_view.z + local clicked_look_view = clicked:get_look_dir() + local x2 = clicked_look_view.x + local z2 = clicked_look_view.z + return math.deg(math.acos((x1 * x2 + z1 * z2) / (math.sqrt(x1^2 + z1^2) * math.sqrt(x2^2 + z2^2)))) +end + +local function get_stealth_ratio(angle_2d) + if angle_2d <= pickp.settings["zone_1_2_limit"] then + stealth_ratio = pickp.settings["zone1_stealth_ratio"] + elseif angle_2d > pickp.settings["zone_1_2_limit"] and angle_2d < pickp.settings["zone_2_3_limit"] then + stealth_ratio = pickp.settings["zone2_stealth_ratio"] + else + stealth_ratio = pickp.settings["zone3_stealth_ratio"] + end + return stealth_ratio +end + minetest.register_on_player_receive_fields(function(player, formname, fields) if formname ~= "pickp:form" then return @@ -146,9 +168,35 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) inv_clicked:remove_item("main", final_steal_itemstack) inv_clicker:add_item("main", final_steal_itemstack) disable_stealth(player, true, false) + --DETECTION WARNING + --Check the angle/ratio + local angle_2d = get_angle(player, clicked) + local stealth_ratio = get_stealth_ratio(angle_2d) + local type_item_reduction_factor + if steal_itemstack.type == "main" then + type_item_reduction_factor = pickp.settings["warning_main_item"] + else + type_item_reduction_factor = pickp.settings["warning_hotbar_item"] + end + stealth_ratio = stealth_ratio - type_item_reduction_factor else disable_stealth(player, true, "The player has moved his items!") end + if math.random(0,1) >= stealth_ratio then --NOT detected + minetest.chat_send_player(player:get_player_name(), S("Successful robbery!")) + else + --DETECTION WARNING + local msg = "" + local clicked_name = clicked:get_player_name() + if math.random(0,1) <= pickp.settings["warning_failed_thief_ratio"] then + msg = S("Someone has stolen from you!") + else + msg = clicked_name.." "..S("has stolen from you") + end + if not (msg == "") then + minetest.chat_send_player(clicked_name, msg) + end + end return true end) @@ -175,23 +223,10 @@ local function stealth(clicker, clicked) return end --2) CHECK THE ANGLE - local clicker_look_view = clicker:get_look_dir() - local x1 = clicker_look_view.x - local z1 = clicker_look_view.z - local clicked_look_view = clicked:get_look_dir() - local x2 = clicked_look_view.x - local z2 = clicked_look_view.z - local angle_2d = math.deg(math.acos((x1 * x2 + z1 * z2) / (math.sqrt(x1^2 + z1^2) * math.sqrt(x2^2 + z2^2)))) + local angle_2d = get_angle(clicker, clicked) --minetest.chat_send_all(tostring(angle_2d)) - local stealth_ratio - --Detect the zone --> - if angle_2d <= pickp.settings["zone_1_2_limit"] then - stealth_ratio = pickp.settings["zone1_stealth_ratio"] - elseif angle_2d > pickp.settings["zone_1_2_limit"] and angle_2d < pickp.settings["zone_2_3_limit"] then - stealth_ratio = pickp.settings["zone2_stealth_ratio"] - else - stealth_ratio = pickp.settings["zone3_stealth_ratio"] - end + local stealth_ratio = get_stealth_ratio(angle_2d) + --Detect the zone & get the ratio accordingly--> if math.random(0,1) >= stealth_ratio then --NOT detected minetest.after(pickp.settings["stealth_timing"], stealth, clicker, clicked) return @@ -216,7 +251,8 @@ local function pickpocketing(clicker, clicked) if not(rob_list == "") then minetest.show_formspec(clicker_name, "pickp:form", get_formspec(clicker, clicked, rob_list)) - enable_steal(clicker, clicked, rob_table) --mark as stealing + local angle_2d = get_angle(clicker, clicked) + enable_steal(clicker, clicked, rob_table, angle_2d) --mark as stealing minetest.after(pickp.settings["stealth_timing"], stealth, clicker, clicked) else minetest.chat_send_player(clicker_name, S("Failed robbery!")) diff --git a/locale/pickp.es.tr b/locale/pickp.es.tr index a155c67..e42bcde 100644 --- a/locale/pickp.es.tr +++ b/locale/pickp.es.tr @@ -6,3 +6,5 @@ The player has moved his items!=El jugador a cambiado sus objetos de sitio Someone has tried to steal from you!=¡Alguien ha intentado robarte! tried to steal from you!=intentó robarte! The victim has walked away!=¡La victima se ha alejado! +Successful robbery!=¡Robo exitoso! +Someone has stolen from you!=¡Alguien te ha robado! diff --git a/pickp.conf b/pickp.conf index 94f5330..b3e69df 100644 --- a/pickp.conf +++ b/pickp.conf @@ -34,5 +34,9 @@ zone2_stealth_ratio = 0.4 zone3_stealth_ratio = 0.9 #Detection Warning (0-1) -##Chance to info the victim of the thief's name +##Chance to info the victim of the thief's name if the theft failed (form closes) warning_failed_thief_ratio = 0.5 +##once the theft is perpetrated, chance to inform the victim +##it depends on the item type [main|hotbar] +warning_hotbar_item = 0.6 +warning_main_item = 0.2 diff --git a/settings.lua b/settings.lua index e31c995..7022eef 100644 --- a/settings.lua +++ b/settings.lua @@ -15,4 +15,6 @@ pickp.settings.zone1_stealth_ratio = tonumber(settings:get("zone1_stealth_ratio" pickp.settings.zone2_stealth_ratio = tonumber(settings:get("zone2_stealth_ratio")) 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"))