diff --git a/api.lua b/api.lua index 0ebeedd..791cd48 100644 --- a/api.lua +++ b/api.lua @@ -6,7 +6,7 @@ local use_cmi = minetest.global_exists("cmi") mobs = { mod = "redo", - version = "20200723", + version = "20200725", intllib = S, invis = minetest.global_exists("invisibility") and invisibility or {} } @@ -230,7 +230,7 @@ function mob_class:collision() end --- check string against another string or table +-- check if string exists in another string or table local check_for = function(look_for, look_inside) if type(look_inside) == "string" and look_inside == look_for then @@ -291,8 +291,7 @@ function mob_class:set_velocity(v) local new_vel = { x = (sin(yaw) * -v) + c_x, y = vel.y, - z = (cos(yaw) * v) + c_y - } + z = (cos(yaw) * v) + c_y} self.object:set_velocity(new_vel) end @@ -353,9 +352,9 @@ function mob_class:set_animation(anim, force) return end - -- check for more than one animation local num = 0 + -- check for more than one animation (max 4) for n = 1, 4 do if self.animation[anim .. n .. "_start"] @@ -388,7 +387,7 @@ end -- above function exported for mount.lua function mobs:set_animation(entity, anim) - mob_class.set_animation(entity, anim) + entity.set_animation(entity, anim) end @@ -750,7 +749,7 @@ function mob_class:item_drop() -- was mob killed by player? local death_by_player = self.cause_of_death and self.cause_of_death.puncher - and self.cause_of_death.puncher:is_player() or nil + and self.cause_of_death.puncher:is_player() local obj, item, num @@ -970,12 +969,11 @@ function mob_class:is_at_cliff() return false end - -- if object no longer exists then return - if not self.object:get_luaentity() then - return false - end - + -- get yaw but if nil returned object no longer exists local yaw = self.object:get_yaw() + + if not yaw then return false end + local dir_x = -sin(yaw) * (self.collisionbox[4] + 0.5) local dir_z = cos(yaw) * (self.collisionbox[4] + 0.5) local pos = self.object:get_pos() @@ -1035,24 +1033,6 @@ function mob_class:do_env_damage() -- particle appears at random mob height pos.y = pos.y + random(self.collisionbox[2], self.collisionbox[5]) - -- is mob light sensative, or scared of the dark :P - if self.light_damage ~= 0 then - - local light = minetest.get_node_light(pos) or 0 - - if light >= self.light_damage_min - and light <= self.light_damage_max then - - self.health = self.health - self.light_damage - - effect(pos, 5, "tnt_smoke.png") - - if self:check_for_death({type = "light"}) then - return true - end - end - end - local nodef = minetest.registered_nodes[self.standing_in] -- water @@ -1098,6 +1078,24 @@ function mob_class:do_env_damage() end end + -- is mob light sensative, or scared of the dark :P + if self.light_damage ~= 0 then + + local light = minetest.get_node_light(pos) or 0 + + if light >= self.light_damage_min + and light <= self.light_damage_max then + + self.health = self.health - self.light_damage + + effect(pos, 5, "tnt_smoke.png") + + if self:check_for_death({type = "light"}) then + return true + end + end + end + --- suffocation inside solid node if (self.suffocation and self.suffocation ~= 0) and (nodef.walkable == nil or nodef.walkable == true) @@ -1545,8 +1543,7 @@ local height_switcher = false function mob_class:smart_mobs(s, p, dist, dtime) local s1 = self.path.lastpos --- local target_pos = self.attack:get_pos() -local target_pos = p + local target_pos = p -- is it becoming stuck? @@ -1693,9 +1690,9 @@ local target_pos = p self.state = "" -if self.attack then - self:do_attack(self.attack) -end + if self.attack then + self:do_attack(self.attack) + end -- no path found, try something else if not self.path.way then @@ -1785,7 +1782,6 @@ end minetest.add_item(p1, ItemStack(node1)) minetest.set_node(p1, {name = "air"}) end - end end end @@ -1798,11 +1794,12 @@ end self.path.following = true else -- yay i found path -if self.attack then - self:mob_sound(self.sounds.war_cry) -else - self:mob_sound(self.sounds.random) -end + if self.attack then + self:mob_sound(self.sounds.war_cry) + else + self:mob_sound(self.sounds.random) + end + self:set_velocity(self.walk_velocity) -- follow path now that it has it @@ -1812,26 +1809,6 @@ end end --- specific attacks -local specific_attack = function(list, what) - - -- no list so attack default (player, animals etc.) - if list == nil then - return true - end - - -- found entity on list to attack? - for no = 1, #list do - - if list[no] == what then - return true - end - end - - return false -end - - -- general attack function for all mobs function mob_class:general_attack() @@ -1859,7 +1836,8 @@ function mob_class:general_attack() or self.attack_players == false or (self.owner and self.type ~= "monster") or mobs.invis[objs[n]:get_player_name()] - or not specific_attack(self.specific_attack, "player") then + or (self.specific_attack + and not check_for("player", self.specific_attack)) then objs[n] = nil --print("- pla", n) end @@ -1872,7 +1850,8 @@ function mob_class:general_attack() or (not self.attack_animals and ent.type == "animal") or (not self.attack_monsters and ent.type == "monster") or (not self.attack_npcs and ent.type == "npc") - or not specific_attack(self.specific_attack, ent.name) then + or (self.specific_attack + and not check_for(ent.name, self.specific_attack)) then objs[n] = nil --print("- mob", n, self.name, ent.name) end @@ -1915,26 +1894,6 @@ function mob_class:general_attack() end --- specific runaway -local specific_runaway = function(list, what) - - -- no list so do not run - if list == nil then - return false - end - - -- found entity on list to attack? - for no = 1, #list do - - if list[no] == what then - return true - end - end - - return false -end - - -- find someone to runaway from function mob_class:do_runaway_from() @@ -1973,7 +1932,7 @@ function mob_class:do_runaway_from() -- find specific mob to runaway from if name ~= "" and name ~= self.name - and specific_runaway(self.runaway_from, name) then + and (self.runaway_from and check_for(name, self.runaway_from)) then sp = s p = player and player:get_pos() or s @@ -2506,7 +2465,7 @@ function mob_class:do_states(dtime) return end - if abs(p1.x-s.x) + abs(p1.z - s.z) < 0.6 then + if abs(p1.x - s.x) + abs(p1.z - s.z) < 0.6 then -- reached waypoint, remove it from queue table.remove(self.path.way, 1) end @@ -2664,9 +2623,9 @@ function mob_class:falling(pos) -- in water then use liquid viscosity for float/sink speed if (self.standing_in - and minetest.registered_nodes[self.standing_in].groups.liquid) --water) + and minetest.registered_nodes[self.standing_in].groups.liquid) or (self.standing_on - and minetest.registered_nodes[self.standing_in].groups.liquid) then -- water) then + and minetest.registered_nodes[self.standing_in].groups.liquid) then local visc = min( minetest.registered_nodes[self.standing_in].liquid_viscosity, 7) @@ -2928,7 +2887,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage) dir = dir or {x = 0, y = 0, z = 0} -- use tool knockback value or default - kb = tool_capabilities.damage_groups["knockback"] or kb -- (kb * 1.5) + kb = tool_capabilities.damage_groups["knockback"] or kb self.object:set_velocity({ x = dir.x * kb, diff --git a/api.txt b/api.txt index 9dea80a..c26334f 100644 --- a/api.txt +++ b/api.txt @@ -344,6 +344,15 @@ Adding Mobs in World Returns false if mob could not be added, returns mob object if spawned ok. +Removing Mob from World +----------------------- + + mobs:remove(self, decrease) + +Removes mob 'self' from the world and if 'decrease' is true then the mob counter +will also be decreased by one. + + Spawning Mobs in World ----------------------