mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2024-12-25 02:00:21 +01:00
harden is_player checks
This commit is contained in:
parent
e2ee5c62c7
commit
07dce8208b
41
api.lua
41
api.lua
@ -260,6 +260,15 @@ local get_distance = function(a, b)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- are we a real player ?
|
||||||
|
local function is_player(player)
|
||||||
|
|
||||||
|
if player and type(player) == "userdata" and minetest.is_player(player) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- collision function based on jordan4ibanez' open_ai mod
|
-- collision function based on jordan4ibanez' open_ai mod
|
||||||
function mob_class:collision()
|
function mob_class:collision()
|
||||||
|
|
||||||
@ -270,7 +279,7 @@ function mob_class:collision()
|
|||||||
|
|
||||||
for _,object in ipairs(minetest.get_objects_inside_radius(pos, width)) do
|
for _,object in ipairs(minetest.get_objects_inside_radius(pos, width)) do
|
||||||
|
|
||||||
if object:is_player() then
|
if is_player(object) then
|
||||||
|
|
||||||
local pos2 = object:get_pos()
|
local pos2 = object:get_pos()
|
||||||
local vec = {x = pos.x - pos2.x, z = pos.z - pos2.z}
|
local vec = {x = pos.x - pos2.x, z = pos.z - pos2.z}
|
||||||
@ -800,7 +809,7 @@ function mob_class:item_drop()
|
|||||||
-- was mob killed by player?
|
-- was mob killed by player?
|
||||||
local death_by_player = self.cause_of_death
|
local death_by_player = self.cause_of_death
|
||||||
and self.cause_of_death.puncher
|
and self.cause_of_death.puncher
|
||||||
and self.cause_of_death.puncher:is_player()
|
and is_player(self.cause_of_death.puncher)
|
||||||
|
|
||||||
-- check for tool 'looting_level' under tool_capabilities as default, or use
|
-- check for tool 'looting_level' under tool_capabilities as default, or use
|
||||||
-- meta string 'looting_level' if found (max looting level is 3).
|
-- meta string 'looting_level' if found (max looting level is 3).
|
||||||
@ -1954,7 +1963,7 @@ function mob_class:general_attack()
|
|||||||
local ent = objs[n]:get_luaentity()
|
local ent = objs[n]:get_luaentity()
|
||||||
|
|
||||||
-- are we a player?
|
-- are we a player?
|
||||||
if objs[n]:is_player() then
|
if is_player(objs[n]) then
|
||||||
|
|
||||||
-- if player invisible or mob cannot attack then remove from list
|
-- if player invisible or mob cannot attack then remove from list
|
||||||
if not damage_enabled
|
if not damage_enabled
|
||||||
@ -2052,7 +2061,7 @@ function mob_class:do_runaway_from()
|
|||||||
-- loop through entities surrounding mob
|
-- loop through entities surrounding mob
|
||||||
for n = 1, #objs do
|
for n = 1, #objs do
|
||||||
|
|
||||||
if objs[n]:is_player() then
|
if is_player(objs[n]) then
|
||||||
|
|
||||||
pname = objs[n]:get_player_name()
|
pname = objs[n]:get_player_name()
|
||||||
|
|
||||||
@ -2156,7 +2165,7 @@ function mob_class:follow_flop()
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- stop following player if not holding specific item or mob is horny
|
-- stop following player if not holding specific item or mob is horny
|
||||||
if self.following and self.following:is_player()
|
if self.following and is_player(self.following)
|
||||||
and (self:follow_holding(self.following) == false or self.horny) then
|
and (self:follow_holding(self.following) == false or self.horny) then
|
||||||
self.following = nil
|
self.following = nil
|
||||||
end
|
end
|
||||||
@ -2169,7 +2178,7 @@ function mob_class:follow_flop()
|
|||||||
local s = self.object:get_pos()
|
local s = self.object:get_pos()
|
||||||
local p
|
local p
|
||||||
|
|
||||||
if self.following:is_player() then
|
if is_player(self.following) then
|
||||||
p = self.following:get_pos()
|
p = self.following:get_pos()
|
||||||
elseif self.following.object then
|
elseif self.following.object then
|
||||||
p = self.following.object:get_pos()
|
p = self.following.object:get_pos()
|
||||||
@ -2316,7 +2325,7 @@ function mob_class:do_states(dtime)
|
|||||||
|
|
||||||
for n = 1, #objs do
|
for n = 1, #objs do
|
||||||
|
|
||||||
if objs[n]:is_player() then
|
if is_player(objs[n]) then
|
||||||
lp = objs[n]:get_pos()
|
lp = objs[n]:get_pos()
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -2428,7 +2437,7 @@ function mob_class:do_states(dtime)
|
|||||||
or not self.attack
|
or not self.attack
|
||||||
or not self.attack:get_pos()
|
or not self.attack:get_pos()
|
||||||
or self.attack:get_hp() <= 0
|
or self.attack:get_hp() <= 0
|
||||||
or (self.attack:is_player()
|
or (is_player(self.attack)
|
||||||
and is_invisible(self, self.attack:get_player_name())) then
|
and is_invisible(self, self.attack:get_player_name())) then
|
||||||
|
|
||||||
--print(" ** stop attacking **", self.name, self.health, dist, self.view_range)
|
--print(" ** stop attacking **", self.name, self.health, dist, self.view_range)
|
||||||
@ -2819,7 +2828,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
|
|||||||
if self.protected then
|
if self.protected then
|
||||||
|
|
||||||
-- did player hit mob and if so is it in protected area
|
-- did player hit mob and if so is it in protected area
|
||||||
if hitter:is_player() then
|
if is_player(hitter) then
|
||||||
|
|
||||||
local player_name = hitter:get_player_name()
|
local player_name = hitter:get_player_name()
|
||||||
|
|
||||||
@ -2880,7 +2889,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
|
|||||||
-- check if hit by player item or entity
|
-- check if hit by player item or entity
|
||||||
local hit_item = weapon_def.name
|
local hit_item = weapon_def.name
|
||||||
|
|
||||||
if not hitter:is_player() then
|
if not is_player(hitter) then
|
||||||
hit_item = hitter:get_luaentity().name
|
hit_item = hitter:get_luaentity().name
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -2987,7 +2996,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
|
|||||||
local entity = hitter and hitter:get_luaentity()
|
local entity = hitter and hitter:get_luaentity()
|
||||||
|
|
||||||
-- check if arrow from same mob, if so then do no damage
|
-- check if arrow from same mob, if so then do no damage
|
||||||
if (entity and entity.name ~= self.arrow) or hitter:is_player() then
|
if (entity and entity.name ~= self.arrow) or is_player(hitter) then
|
||||||
self.health = self.health - floor(damage)
|
self.health = self.health - floor(damage)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -3350,7 +3359,7 @@ function mob_class:mob_expire(pos, dtime)
|
|||||||
|
|
||||||
for n = 1, #objs do
|
for n = 1, #objs do
|
||||||
|
|
||||||
if objs[n]:is_player() then
|
if is_player(objs[n]) then
|
||||||
|
|
||||||
self.lifetimer = 20
|
self.lifetimer = 20
|
||||||
|
|
||||||
@ -3730,7 +3739,7 @@ local function count_mobs(pos, type)
|
|||||||
|
|
||||||
for n = 1, #objs do
|
for n = 1, #objs do
|
||||||
|
|
||||||
if not objs[n]:is_player() then
|
if not is_player(objs[n]) then
|
||||||
|
|
||||||
ent = objs[n]:get_luaentity()
|
ent = objs[n]:get_luaentity()
|
||||||
|
|
||||||
@ -4052,7 +4061,7 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter
|
|||||||
|
|
||||||
for n = 1, #objs do
|
for n = 1, #objs do
|
||||||
|
|
||||||
if objs[n]:is_player() then
|
if is_player(objs[n]) then
|
||||||
--print("--- player too close", name)
|
--print("--- player too close", name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -4248,7 +4257,7 @@ function mobs:register_arrow(name, def)
|
|||||||
|
|
||||||
for _,player in pairs(minetest.get_objects_inside_radius(pos, 1.0)) do
|
for _,player in pairs(minetest.get_objects_inside_radius(pos, 1.0)) do
|
||||||
|
|
||||||
if self.hit_player and player:is_player() then
|
if self.hit_player and is_player(player) then
|
||||||
|
|
||||||
self:hit_player(player)
|
self:hit_player(player)
|
||||||
|
|
||||||
@ -4496,7 +4505,7 @@ end
|
|||||||
function mobs:capture_mob(
|
function mobs:capture_mob(
|
||||||
self, clicker, chance_hand, chance_net, chance_lasso, force_take, replacewith)
|
self, clicker, chance_hand, chance_net, chance_lasso, force_take, replacewith)
|
||||||
|
|
||||||
if not self or not clicker:is_player() or not clicker:get_inventory() then
|
if not self or not is_player(clicker) or not clicker:get_inventory() then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
11
mount.lua
11
mount.lua
@ -174,6 +174,15 @@ local function find_free_pos(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- are we a real player ?
|
||||||
|
local function is_player(player)
|
||||||
|
|
||||||
|
if player and type(player) == "userdata" and minetest.is_player(player) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function mobs.attach(entity, player)
|
function mobs.attach(entity, player)
|
||||||
|
|
||||||
entity.player_rotation = entity.player_rotation or {x = 0, y = 0, z = 0}
|
entity.player_rotation = entity.player_rotation or {x = 0, y = 0, z = 0}
|
||||||
@ -212,7 +221,7 @@ function mobs.attach(entity, player)
|
|||||||
|
|
||||||
minetest.after(0.2, function()
|
minetest.after(0.2, function()
|
||||||
|
|
||||||
if player and player:is_player() then
|
if is_player(player) then
|
||||||
|
|
||||||
if is_50 then
|
if is_50 then
|
||||||
player_api.set_animation(player, "sit", 30)
|
player_api.set_animation(player, "sit", 30)
|
||||||
|
13
spawner.lua
13
spawner.lua
@ -1,8 +1,17 @@
|
|||||||
|
|
||||||
local S = mobs.intllib
|
local S = mobs.intllib
|
||||||
|
|
||||||
-- mob spawner
|
|
||||||
|
|
||||||
|
-- are we a real player ?
|
||||||
|
local function is_player(player)
|
||||||
|
|
||||||
|
if player and type(player) == "userdata" and minetest.is_player(player) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- mob spawner
|
||||||
local spawner_default = "mobs_animal:pumba 10 15 0 0 0"
|
local spawner_default = "mobs_animal:pumba 10 15 0 0 0"
|
||||||
|
|
||||||
minetest.register_node("mobs:spawner", {
|
minetest.register_node("mobs:spawner", {
|
||||||
@ -148,7 +157,7 @@ minetest.register_abm({
|
|||||||
|
|
||||||
for _, oir in pairs(objsp) do
|
for _, oir in pairs(objsp) do
|
||||||
|
|
||||||
if oir:is_player() then
|
if is_player(oir) then
|
||||||
|
|
||||||
in_range = 1
|
in_range = 1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user