X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=mods%2Fmob%2Fapi%2Fdata_handling.lua;h=ac36fa4531ee75209e533c36a627b0ab6471537f;hb=f0ed02f964af90ef2472e98dc99a2b7ac57c9472;hp=9afa35b9750d384f856ca028bce74b80905d30a4;hpb=b2b155f1fbc3261bd7f64fd5e5deb1fa97624778;p=Crafter.git diff --git a/mods/mob/api/data_handling.lua b/mods/mob/api/data_handling.lua index 9afa35b..ac36fa4 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, @@ -22,8 +34,6 @@ mobs.create_data_handling_functions = function(def,mob_register) 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) @@ -66,6 +76,11 @@ mobs.create_data_handling_functions = function(def,mob_register) 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