You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
4.2 KiB

local get_distance = function(a, b)
local x, y, z = a.x - b.x, a.y - b.y, a.z - b.z
return (x * x + y * y + z * z)
end
mobs:register_mob('scorpion:pet', {
type = 'npc',
passive = false,
attack_type = 'dogfight',
owner_loyal = true,
pathfinding = true,
damage = 10,
hp_min = 30, hp_max = 75, armor = 20,
collisionbox = {-0.6, -0.35, -0.5, 0.6, 0.3, 0.5},
visual = 'mesh',
mesh = 'scorpion.b3d',
textures = {
{'scorpion_red.png^scorpion_pet.png'},
{'scorpion_green.png^scorpion_pet.png'},
{'scorpion_tan.png^scorpion_pet.png'},
},
follow = {'mobs:meat_raw', 'mobs:chicken_raw'},
blood_texture = 'mobs_blood.png',
visual_size = {x=8,y=8},
makes_footstep_sound = true,
sounds = {
war_cry = 'scorpion_squeak',
},
walk_velocity = 3,
run_velocity = 6,
jump = true,
stepheight = 1.7,
reach = 4,
view_range = 15,
fear_height = 2,
owner = '',
order = 'follow',
drops = {
{name = 'mobs:meat_raw', chance = 1, min = 2, max = 8},
{name = 'scorpion:shell', chance = 1, min = 5, max = 20},
},
water_damage = 1,
lava_damage = 6,
light_damage = 0,
animation = {
speed_normal = 45, speed_run = 90,
stand_start = 0, stand_end = 60,
walk_start = 150, walk_end = 210,
run_start = 150, run_end = 210,
punch_start = 220, punch_end = 260,
punch2_start = 265, punch2_end = 305,
punch3_start = 70, punch3_end = 140,
},
on_spawn = function(self)
local pos = self.object:get_pos()
local objs = minetest.get_objects_inside_radius(pos, 4)
for _, obj in pairs(objs) do
if obj:is_player() then
local owner = obj:get_player_name()
self.owner = owner
minetest.chat_send_player(owner, "Aww, a baby scorpion think you're its parent!")
end
end
return true
end,
on_rightclick = function(self, clicker)
local name = clicker:get_player_name()
if mobs:feed_tame(self, clicker, 10, false, true) then
return
end
if self.owner and self.owner == name then
if item ~= 'mobs:saddle' then
if self.order == 'follow' then
self.order = 'stand'
minetest.chat_send_player(name, ('Scorpion holding ground.'))
else
self.order = 'follow'
minetest.chat_send_player(name, ('Scorpion following you.'))
end
mobs:capture_mob(self, clicker, 20, 0, 100, false, nil)
end
-- detatch player
if self.driver and clicker == self.driver then
mobs.detach(clicker, {x = 1, y = 0, z = 1})
-- add saddle back to inventory
if inv:room_for_item("main", "mobs:saddle") then
inv:add_item("main", "mobs:saddle")
else
minetest.add_item(clicker:get_pos(), "mobs:saddle")
end
self.saddle = nil
-- attach player
elseif (not self.driver and not self.child and item == "mobs:saddle")
or self.saddle then
self.object:set_properties({stepheight = 1.1})
mobs.attach(self, clicker)
if not self.saddle then
inv:remove_item("main", "mobs:saddle")
end
self.saddle = true
end
end
end,
on_grown = function(self)
local owner = self.owner
minetest.chat_send_player(owner, ('Your pet scorpion grew up!'))
end,
do_custom = function(self, dtime) --Thanks to IhrFussel for many ideas used in this code block.
self.dtime = (self.dtime or 0) + dtime
if self.dtime < 5 then
return
end
self.dtime = 0
local pet_pos = self.object:get_pos()
local owner = minetest.get_player_by_name(self.owner) or false
if owner then --and self.state == "walk
local distance = get_distance(owner:getpos(), pet_pos)
if distance > 1000 then --should teleport to player
if self.order == 'follow' then --but only if following
self.object:set_pos(owner:getpos())
end
end
end
end,
})
mobs:register_egg('scorpion:pet', 'Pet Scorpion', 'default_grass.png', 1)