diff --git a/abms.lua b/abms.lua index f149dcd..a5d2d7e 100644 --- a/abms.lua +++ b/abms.lua @@ -184,6 +184,8 @@ minetest.register_globalstep(function(dtime) else fun_caves.db.status[player_name][name] = nil end + elseif def.during then + def.during(player) end end diff --git a/demon.lua b/demon.lua index 586e87f..ef8cd43 100644 --- a/demon.lua +++ b/demon.lua @@ -162,10 +162,6 @@ local snow_demon = { walkmine_end = 219, }, animation_speed = 30, - on_die = function(self) - self.slowed:set_physics_override({speed=1}) - self.slowed = nil - end, do_custom = function(self) if not self.attack then self.fly = false @@ -175,14 +171,7 @@ local snow_demon = { snow_effect(pos, 20) if self.attack then - self.attack:set_physics_override({speed=0.3}) - self.slowed = self.attack - elseif self.slowed then - local player = self.slowed - minetest.after(20, function() - player:set_physics_override({speed=1}) - end) - self.slowed = nil + fun_caves.set_status(self.attack:get_player_name(), 'slow_cold', 20) end if not fun_caves.custom_ready(self) then @@ -193,6 +182,16 @@ local snow_demon = { end, } +fun_caves.register_status({ + name = 'slow_cold', + start = function(player) + player:set_physics_override({speed=0.3}) + end, + terminate = function(player) + player:set_physics_override({speed=1}) + end, +}) + if minetest.registered_entities["mobs_yeti:yeti"] then snow_demon.arrow = "mobs_yeti:snowball" snow_demon.attack_type = 'dogshoot' diff --git a/elixir.lua b/elixir.lua index 40cf112..b36bd77 100644 --- a/elixir.lua +++ b/elixir.lua @@ -54,10 +54,7 @@ local function armor(user, factor) armor.fleshy = math.min(100, math.max(1, math.ceil(armor.fleshy * factor))) user:set_armor_groups(armor) minetest.chat_send_player(player_name, 'Your skin feels harder...') - fun_caves.db.status[player_name].armor_elixir = { - remove = minetest.get_gametime() + elixir_duration, - factor = factor, - } + fun_caves.set_status(player_name, 'armor_elixir', elixir_duration, {factor = factor}) end local descs = { diff --git a/init.lua b/init.lua index f1be9e8..302b70d 100644 --- a/init.lua +++ b/init.lua @@ -112,6 +112,29 @@ function fun_caves.register_status(def) } end +function fun_caves.set_status(player_name, status, time, param) + local player = minetest.get_player_by_name(player_name) + local def = fun_caves.registered_status[status] + if not (def and player) then + return + end + + if not param then + param = {} + end + + if time then + param.remove = minetest.get_gametime() + time + end + + if player_name and status and fun_caves.db.status[player_name] then + fun_caves.db.status[player_name][status] = param + if def.start then + def.start(player) + end + end +end + --dofile(fun_caves.path .. "/recipe_list.lua")