1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2025-07-20 17:20:23 +02:00

Compare commits

...

8 Commits

Author SHA1 Message Date
469e35d6e0 tidy api 2020-07-23 20:13:15 +01:00
1271570780 nil check in do_states 2020-07-20 18:10:08 +01:00
ec3c6fb518 update api.txt 2020-07-20 07:36:39 +01:00
c4f56f4204 nill check for follow_flop 2020-07-20 07:32:24 +01:00
4814f53885 nil check for get_distance 2020-07-20 07:27:55 +01:00
f033cd401c add nil check to general_attack 2020-07-18 20:39:49 +01:00
903e81bdab another nil check for entity 2020-07-17 21:12:43 +01:00
81dd3d75c0 add randomly_turn setting to mob definition 2020-07-17 20:58:52 +01:00
2 changed files with 35 additions and 20 deletions

49
api.lua
View File

@ -6,7 +6,7 @@ local use_cmi = minetest.global_exists("cmi")
mobs = {
mod = "redo",
version = "20200701",
version = "20200723",
intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {}
}
@ -196,6 +196,8 @@ end
-- calculate distance
local get_distance = function(a, b)
-- if not a or not b then return 50 end -- nil check
local x, y, z = a.x - b.x, a.y - b.y, a.z - b.z
return square(x * x + y * y + z * z)
@ -812,6 +814,11 @@ local remove_mob = function(self, decrease)
--print("-- active mobs: " .. active_mobs .. " / " .. active_limit)
end
-- global function for removing mobs
function mobs:remove(self, decrease)
remove_mob(self, decrease)
end
-- check if mob is dead or only hurt
function mob_class:check_for_death(cmi_cause)
@ -1013,7 +1020,7 @@ function mob_class:do_env_damage()
self:update_tag()
end
local pos = self.object:get_pos()
local pos = self.object:get_pos() ; if not pos then return end
self.time_of_day = minetest.get_timeofday()
@ -1538,7 +1545,9 @@ 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 = self.attack:get_pos()
local target_pos = p
-- is it becoming stuck?
if abs(s1.x - s.x) + abs(s1.z - s.z) < .5 then
@ -1602,10 +1611,6 @@ function mob_class:smart_mobs(s, p, dist, dtime)
minetest.after(1, function(self)
if not self.object:get_luaentity() then
return
end
if self.object:get_luaentity() then
if has_lineofsight then
@ -1687,7 +1692,10 @@ function mob_class:smart_mobs(s, p, dist, dtime)
]]
self.state = ""
if self.attack then
self:do_attack(self.attack)
end
-- no path found, try something else
if not self.path.way then
@ -1790,7 +1798,11 @@ function mob_class:smart_mobs(s, p, dist, dtime)
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
self:set_velocity(self.walk_velocity)
-- follow path now that it has it
@ -1831,7 +1843,7 @@ function mob_class:general_attack()
return
end
local s = self.object:get_pos()
local s = self.object:get_pos() ; if not s then return end
local objs = minetest.get_objects_inside_radius(s, self.view_range)
-- remove entities we aren't interested in
@ -2001,7 +2013,7 @@ function mob_class:follow_flop()
and self.state ~= "attack"
and self.state ~= "runaway" then
local s = self.object:get_pos()
local s = self.object:get_pos() ; if not s then return end
local players = minetest.get_connected_players()
for n = 1, #players do
@ -2132,11 +2144,11 @@ end
-- execute current state (stand, walk, run, attacks)
function mob_class:do_states(dtime)
local yaw = self.object:get_yaw() or 0
local yaw = self.object:get_yaw() ; if not yaw then return end
if self.state == "stand" then
if random(4) == 1 then
if self.randomly_turn and random(4) == 1 then
local lp
local s = self.object:get_pos()
@ -2224,7 +2236,7 @@ function mob_class:do_states(dtime)
yaw = self:set_yaw(yaw, 8)
-- otherwise randomly turn
elseif random(100) <= 30 then
elseif self.randomly_turn and random(100) <= 30 then
yaw = yaw + random(-0.5, 0.5)
@ -2284,12 +2296,12 @@ function mob_class:do_states(dtime)
-- attack routines (explode, dogfight, shoot, dogshoot)
elseif self.state == "attack" then
-- calculate distance from mob and enemy
-- get mob and enemy positions and distance between
local s = self.object:get_pos()
local p = self.attack:get_pos() or s
local dist = get_distance(p, s)
local p = self.attack:get_pos()
local dist = p and get_distance(p, s) or 500
-- stop attacking if player invisible or out of range
-- stop attacking if player out of range or invisible
if dist > self.view_range
or not self.attack
or not self.attack:get_pos()
@ -2425,7 +2437,8 @@ function mob_class:do_states(dtime)
elseif self.attack_type == "dogfight"
or (self.attack_type == "dogshoot" and self:dogswitch(dtime) == 2)
or (self.attack_type == "dogshoot" and dist <= self.reach and self:dogswitch() == 0) then
or (self.attack_type == "dogshoot" and dist <= self.reach
and self:dogswitch() == 0) then
if self.fly
and dist > self.reach then
@ -2472,7 +2485,6 @@ function mob_class:do_states(dtime)
})
end
end
end
-- rnd: new movement direction
@ -3564,6 +3576,7 @@ minetest.register_entity(name, setmetatable({
owner_loyal = def.owner_loyal,
pushable = def.pushable,
stay_near = def.stay_near,
randomly_turn = def.randomly_turn ~= false,
on_spawn = def.on_spawn,

View File

@ -31,13 +31,15 @@ functions needed for the mob to work properly which contains the following:
'hp_max' has the maximum health value the mob can spawn with.
'armor' holds strength of mob, 100 is normal, lower is more powerful
and needs more hits and better weapons to kill.
'passive' when true allows animals to defend themselves when hit,
'passive' when false allows animals to defend themselves when hit,
otherwise they amble onwards.
'walk_velocity' is the speed that your mob can walk around.
'run_velocity' is the speed your mob can run with, usually when attacking.
'stand_chance' has a 0-100 chance value your mob will stand from walking.
'walk_chance' has a 0-100 chance value your mob will walk from standing,
set to 0 for jumping mobs only.
'randomly_turn' if set to false then mob will not turn to face player or
randomly turn while walking or standing.
'jump' when true allows your mob to jump updwards.
'jump_height' holds the height your mob can jump, 0 to disable jumping.
'stepheight' height of a block that your mob can easily walk up onto,