X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=mods%2Fmob%2Fapi%2Fdata_handling.lua;h=2a92786ce0a0c663d6a006b3e5cfdaa6f83cf852;hb=abbb18dfb6d68163c04cbbf2f9cd97681800d730;hp=f971f1af1c1c0fd6c6e130b9beb9e4ea0c649e37;hpb=f50031b5a6e2675312185c64cd0a2fb9f811796f;p=Crafter.git diff --git a/mods/mob/api/data_handling.lua b/mods/mob/api/data_handling.lua index f971f1a..2a92786 100644 --- a/mods/mob/api/data_handling.lua +++ b/mods/mob/api/data_handling.lua @@ -1,6 +1,18 @@ -- mobs.create_data_handling_functions = function(def,mob_register) mob_register.get_staticdata = function(self) + if self.deactivating == false then + global_mob_amount = global_mob_amount + 1 + --print("Mob Spawned. Current Mobs: "..global_mob_amount) + elseif self.deactivating == true then + minetest.after(0, function() + if not self.object:get_luaentity() then + global_mob_amount = global_mob_amount - 1 + --print("Mob Deactivated. Current Mobs: "..global_mob_amount) + end + end) + end + return minetest.serialize({ --range = self.range, hp = self.hp, @@ -13,14 +25,15 @@ mobs.create_data_handling_functions = function(def,mob_register) tnt_tick_timer = self.tnt_tick_timer, tnt_mod_state = self.tnt_mod_state, punch_timer = self.punch_timer, - projectile_timer = self.projectile_timer + projectile_timer = self.projectile_timer, + scared = self.scared, + scared_timer = self.scared_timer, + c_mob_data = self.c_mob_data, }) end mob_register.on_activate = function(self, staticdata, dtime_s) - global_mob_amount = global_mob_amount + 1 - print("Mobs Spawned. Current Mobs: "..global_mob_amount) self.object:set_armor_groups({immortal = 1}) --self.object:set_velocity({x = math.random(-5,5), y = 5, z = math.random(-5,5)}) self.object:set_acceleration(def.gravity) @@ -39,6 +52,9 @@ mobs.create_data_handling_functions = function(def,mob_register) self.tnt_mod_state = data.tnt_mod_state self.punch_timer = data.punch_timer self.projectile_timer = data.projectile_timer + self.scared = data.scared + self.scared_timer = data.scared_timer + self.c_mob_data = data.c_mob_data end end @@ -55,7 +71,16 @@ mobs.create_data_handling_functions = function(def,mob_register) end self.is_mob = true self.object:set_armor_groups({immortal = 1}) + + if self.custom_on_activate then + self.custom_on_activate(self) + end --self.object:set_yaw(math.pi*math.random(-1,1)*math.random()) + + --use this to handle the global mob table + minetest.after(0,function() + self.deactivating = true + end) end --this is the info on the mob