mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2025-03-27 06:20:29 +01:00
add 'homing' setting to mob definition so that arrows can follow player when visible.
This commit is contained in:
parent
d1f23e8ed8
commit
682d76d7b3
26
api.lua
26
api.lua
@ -11,7 +11,7 @@ local use_mc2 = minetest.get_modpath("mcl_core")
|
|||||||
-- Global
|
-- Global
|
||||||
mobs = {
|
mobs = {
|
||||||
mod = "redo",
|
mod = "redo",
|
||||||
version = "20231111",
|
version = "20231116",
|
||||||
translate = S,
|
translate = S,
|
||||||
invis = minetest.global_exists("invisibility") and invisibility or {},
|
invis = minetest.global_exists("invisibility") and invisibility or {},
|
||||||
node_snow = minetest.registered_aliases["mapgen_snow"]
|
node_snow = minetest.registered_aliases["mapgen_snow"]
|
||||||
@ -2653,6 +2653,12 @@ function mob_class:do_states(dtime)
|
|||||||
ent.switch = 1
|
ent.switch = 1
|
||||||
ent.owner_id = tostring(self.object) -- add unique owner id to arrow
|
ent.owner_id = tostring(self.object) -- add unique owner id to arrow
|
||||||
|
|
||||||
|
-- setup homing arrow and target
|
||||||
|
if self.homing then
|
||||||
|
ent._target = self.attack
|
||||||
|
ent.homing = true
|
||||||
|
end
|
||||||
|
|
||||||
-- offset makes shoot aim accurate
|
-- offset makes shoot aim accurate
|
||||||
vec.y = vec.y + self.shoot_offset
|
vec.y = vec.y + self.shoot_offset
|
||||||
vec.x = vec.x * (v / amount)
|
vec.x = vec.x * (v / amount)
|
||||||
@ -3593,6 +3599,7 @@ minetest.register_entity(":" .. name, setmetatable({
|
|||||||
arrow = def.arrow,
|
arrow = def.arrow,
|
||||||
arrow_override = def.arrow_override,
|
arrow_override = def.arrow_override,
|
||||||
shoot_interval = def.shoot_interval,
|
shoot_interval = def.shoot_interval,
|
||||||
|
homing = def.homing,
|
||||||
sounds = def.sounds,
|
sounds = def.sounds,
|
||||||
animation = def.animation,
|
animation = def.animation,
|
||||||
follow = def.follow,
|
follow = def.follow,
|
||||||
@ -4224,6 +4231,23 @@ function mobs:register_arrow(name, def)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- make homing arrows follow target if seen
|
||||||
|
if self.homing and self._target then
|
||||||
|
|
||||||
|
local p = self._target:get_pos()
|
||||||
|
|
||||||
|
if p then
|
||||||
|
|
||||||
|
if minetest.line_of_sight(self.object:get_pos(), p) then
|
||||||
|
|
||||||
|
self.object:set_velocity(
|
||||||
|
vector.direction(self.object:get_pos(), p) * self.velocity)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self._target = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if self.hit_player or self.hit_mob or self.hit_object then
|
if self.hit_player or self.hit_mob or self.hit_object then
|
||||||
|
|
||||||
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
|
||||||
|
1
api.txt
1
api.txt
@ -150,6 +150,7 @@ functions needed for the mob to work properly which contains the following:
|
|||||||
'shoot_interval' has the number of seconds between shots.
|
'shoot_interval' has the number of seconds between shots.
|
||||||
'shoot_offset' holds the y position added as to where the
|
'shoot_offset' holds the y position added as to where the
|
||||||
arrow/fireball appears on mob.
|
arrow/fireball appears on mob.
|
||||||
|
'homing' When True arrows will follow player when visible.
|
||||||
'specific_attack' has a table of entity names that mob can also attack
|
'specific_attack' has a table of entity names that mob can also attack
|
||||||
e.g. {"player", "mobs_animal:chicken"}.
|
e.g. {"player", "mobs_animal:chicken"}.
|
||||||
'friendly_fire` when set to false, mobs will not be able to harm other
|
'friendly_fire` when set to false, mobs will not be able to harm other
|
||||||
|
Loading…
x
Reference in New Issue
Block a user