From 1eb0bc363e1e7e4e4a754d0b0ca7df73ac3a1f11 Mon Sep 17 00:00:00 2001 From: sys4 Date: Fri, 27 Dec 2019 01:22:46 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Ajoute=20remplissage=20des=20coffres=2030?= =?UTF-8?q?=20minutes=20apr=C3=A8s=20ouverture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit et modifie les items générés par ceux de nalc_trm --- init.lua | 11 +++++++---- nodes.lua | 27 +++++++++++++++++++++++++++ room.lua | 16 +++++++++++++++- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index 86f1997..231d7bf 100644 --- a/init.lua +++ b/init.lua @@ -67,13 +67,16 @@ end function tsm_pyramids.fill_chest(pos, stype, flood_sand, treasure_chance) local sand = "default:sand" + local n = minetest.get_node(pos) + local meta = minetest.get_meta(pos) if not treasure_chance then treasure_chance = 100 end - if stype == "desert_sandstone" or stype == "desert_stone" then + if meta:get_string("tsm_pyramids:stype") == "desert_sandstone" or + meta:get_string("tsm_pyramids:stype") == "desert_stone" or + stype == "desert_sandstone" or stype == "desert_stone" then sand = "default:desert_sand" end - local n = minetest.get_node(pos) local treasure_added = false if n and n.name and n.name == "default:chest" then local meta = minetest.get_meta(pos) @@ -81,13 +84,13 @@ function tsm_pyramids.fill_chest(pos, stype, flood_sand, treasure_chance) inv:set_size("main", 8*4) local stacks = {} -- Fill with sand in sand-flooded pyramids - if flood_sand then + if meta:get_int("tsm_pyramids:sanded") == 1 or flood_sand then table.insert(stacks, {name=sand, count = math.random(1,32)}) end -- Add treasures if math.random(1,100) <= treasure_chance then if minetest.get_modpath("treasurer") ~= nil then - stacks = treasurer.select_random_treasures(3,7,9,{"minetool", "food", "crafting_component"}) + stacks = treasurer.select_random_treasures(3,1,5,{"armes", "armures", "precieux", "nourriture"}) else for i=0,2,1 do local stuff = chest_stuff.normal[math.random(1,#chest_stuff.normal)] diff --git a/nodes.lua b/nodes.lua index 6c3cb0f..4ea9a39 100644 --- a/nodes.lua +++ b/nodes.lua @@ -97,3 +97,30 @@ register_trap_stone("desert_trap", "default_desert_sandstone_brick.png", { items = { { items = { "default:desert_sand" }, rarity = 1 }, { items = { "default:desert_sand" }, rarity = 2 }, } }) +local chest = minetest.registered_nodes["default:chest"] +local def_on_rightclick = chest.on_rightclick +local def_on_timer = chest.on_timer +minetest.override_item( + "default:chest", + { + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + if minetest.get_meta(pos):get_string("tsm_pyramids:stype") ~= "" then + local timer = minetest.get_node_timer(pos) + if not timer:is_started() then + timer:start(1800) -- remplissages des coffres toutes les 30 minutes + end + end + return def_on_rightclick(pos, node, clicker, itemstack, pointed_thing) + end, + on_timer = function(pos, elapsed) + if minetest.get_meta(pos):get_string("tsm_pyramids:stype") ~= "" then + minetest.log("action", "[DEBUG] chest refilling") + tsm_pyramids.fill_chest(pos) + return false + else + if def_on_timer then return def_on_timer(pos, elapsed) else return false end + end + end, +}) + +minetest.register_alias("tsm_pyramids:chest", "default:chest") diff --git a/room.lua b/room.lua index a794c6e..a7edc6f 100644 --- a/room.lua +++ b/room.lua @@ -960,6 +960,7 @@ function tsm_pyramids.make_room(pos, stype, room_id, rotations) end tries = tries + 1 end + local sanded = room.flood_sand ~= false and stype ~= "desert_stone" and math.random(1,8) == 1 local chests = {} local column_style if stype == "desert_stone" then @@ -1002,6 +1003,13 @@ function tsm_pyramids.make_room(pos, stype, room_id, rotations) local nn = replace(n_str, iy, code_table, deco, column_style) minetest.set_node(cpos, {name=nn, param2=p2}) if nn == "default:chest" then + local meta = minetest.get_meta(cpos) + meta:set_string("tsm_pyramids:stype", stype) + if sanded then + meta:set_int("tsm_pyramids:sanded", 1) + else + meta:set_int("tsm_pyramids:sanded", 0) + end table.insert(chests, cpos) end end @@ -1045,6 +1053,13 @@ function tsm_pyramids.make_room(pos, stype, room_id, rotations) local nn = code_table[n_str] minetest.set_node(cpos, {name=nn, param2=p2}) if nn == "default:chest" then + local meta = minetest.get_meta(cpos) + meta:set_string("tsm_pyramids:stype", stype) + if sanded then + meta:set_int("tsm_pyramids:sanded", 1) + else + meta:set_int("tsm_pyramids:sanded", 0) + end table.insert(chests, cpos) end end @@ -1053,7 +1068,6 @@ function tsm_pyramids.make_room(pos, stype, room_id, rotations) else minetest.log("error", "Invalid pyramid room style! room type ID="..r) end - local sanded = room.flood_sand ~= false and stype ~= "desert_stone" and math.random(1,8) == 1 if #chests > 0 then -- Make at least 8 attempts to fill chests local filled = 0 From d4d89c5cc4c4bcb02eae3436454632b2ad185ddf Mon Sep 17 00:00:00 2001 From: sys4 Date: Sun, 4 Sep 2022 19:00:44 +0200 Subject: [PATCH 2/2] Fix crash caused by lack of luaentity nil check and minetest 5.6 --- mummy.lua | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/mummy.lua b/mummy.lua index 4364cce..42ebf6c 100644 --- a/mummy.lua +++ b/mummy.lua @@ -284,20 +284,23 @@ MUMMY_DEF.on_step = function(self, dtime) if self.state == 1 then self.yawwer = true self.attacker = "" - for _,object in ipairs(minetest.get_objects_inside_radius(self.object:get_pos(), 4)) do - if object:is_player() then - self.yawwer = false - local NPC = self.object:get_pos() - local PLAYER = object:get_pos() - self.vec = {x=PLAYER.x-NPC.x, y=PLAYER.y-NPC.y, z=PLAYER.z-NPC.z} - self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2 - if PLAYER.x > NPC.x then - self.yaw = self.yaw + math.pi - end - self.yaw = self.yaw - 2 - self.object:set_yaw(self.yaw) - self.attacker = object - end + local pos_obj = self.object:get_pos() + if pos_obj then + for _,object in ipairs(minetest.get_objects_inside_radius(pos_obj, 4)) do + if object:is_player() then + self.yawwer = false + local NPC = self.object:get_pos() + local PLAYER = object:get_pos() + self.vec = {x=PLAYER.x-NPC.x, y=PLAYER.y-NPC.y, z=PLAYER.z-NPC.z} + self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2 + if PLAYER.x > NPC.x then + self.yaw = self.yaw + math.pi + end + self.yaw = self.yaw - 2 + self.object:set_yaw(self.yaw) + self.attacker = object + end + end end if self.attacker == "" and self.turn_timer > math.random(1,4) then @@ -306,7 +309,8 @@ MUMMY_DEF.on_step = function(self, dtime) self.turn_timer = 0 self.direction = {x = math.sin(self.yaw)*-1, y = -20, z = math.cos(self.yaw)} end - self.object:set_velocity({x=0,y=self.object:get_velocity().y,z=0}) + local old_vel = self.object:get_velocity() + self.object:set_velocity({x=0,y=old_vel and old_vel.y or 0,z=0}) if self.npc_anim ~= ANIM_STAND then self.anim = get_animations() self.object:set_animation({x=self.anim.stand_START,y=self.anim.stand_END}, mummy_animation_speed, mummy_animation_blend) @@ -321,7 +325,12 @@ MUMMY_DEF.on_step = function(self, dtime) if self.state == 2 then if self.direction ~= nil then - self.object:set_velocity({x=self.direction.x*mummy_chillaxin_speed,y=self.object:get_velocity().y,z=self.direction.z*mummy_chillaxin_speed}) + local old_vel = self.object:get_velocity() + self.object:set_velocity({ + x=self.direction.x*mummy_chillaxin_speed, + y=old_vel and old_vel.y or 0, + z=self.direction.z*mummy_chillaxin_speed, + }) end if self.turn_timer > math.random(1,4) and not self.attacker then self.yaw = 360 * math.random()