Start guard.lua (WIP)

master
MisterE123 2021-02-10 00:59:18 -05:00
parent ea1d409999
commit a7351e76ce
1 changed files with 200 additions and 0 deletions

200
mobs/guard.lua Normal file
View File

@ -0,0 +1,200 @@
yl_creatures.guard = {}
yl_creatures.guard.pts = {{}}
local guard_brain = function(self)
local pos = mobkit.get_stand_pos(self)
local prty = mobkit.get_queue_priority(self)
local player = mobkit.get_nearby_player(self)
mob_core.random_sound(self, 16/self.dtime)
--death handling
if self.hp <= 0 then
mob_core.on_die(self)
return
end
--decision_making, every second
if mobkit.timer(self,1) then
mob_core.vitals(self)
local status = self.status
local target_patrol = mobkit.recall(self,'target')
local enemy = nil
for _,obj in minetest.get_objects_inside_radius(pos,self.view_range) do
local ent = obj:get_luaentity()
if ent and ent.name == "yl_creatures:sand_man" then
enemy = obj
end
end
if not status then
mobkit.remember(self, "status", "")
status = ''
end
if status == 'patrol' then
if prty < 10 and enemy then
mob_core.hq_hunt(self, 90, enemy)
end
else --status == ''
if prty < 50 and item then
yl_creatures.hq_seek_item(self, math.random(1,49), 'default:desert_sand')
end
if prty < 70 and player then
mob_core.hq_hunt(self, math.random(41,69) , player)
end
if prty < 40 and self.isinliquid then
mobkit.hq_liquid_recovery(self,math.random(41,55))
end
end
if mobkit.is_queue_empty_high(self) then
if self.pts[1] and yl_creatures.guard.pts[2] then
yl_creatures.hq_patrol(self,yl_creatures.guard.pts)
else
mob_core.hq_roam(self, 0, 1)
self.status = mobkit.remember(self,'status','')
end
end
end
end
minetest.register_entity("yl_creatures:guard",{
max_hp = 45,
view_range = 10,
reach = 2,
armor = 100,
damage = 4,
passive = false,
armor_groups = {fleshy=75},
physical = true,
collide_with_objects = true,
collisionbox = {-0.35,-1.0,-0.35, 0.35,0.8,0.35},
visual_size = {x=1,y=1},
scale_stage1 = 0.5,
scale_stage2 = 0.65,
scale_stage3 = 0.80,
visual = "mesh",
mesh = "mobs_character.b3d",
textures = {"yl_creatures_sand_man.png"},
animation = {
stand = {range={x=0,y=79},speed=30,loop=true},
walk={range={x=168,y=187},speed=30,loop=true}, -- single
run={range={x=168,y=187},speed=40,loop=true}, -- single
attack={range={x=200,y=219},speed=30,loop=true}, -- single
},
obstacle_avoidance_range = 5,
surface_avoidance_range = 0,
floor_avoidance_range = 1,
sounds = {
random = "yl_creatures_sand_man_random",
hurt = "yl_creatures_sand_man_random",
attack = "default_sand_footstep",
jump = "default_sand_footstep",
death = "default_item_smoke",
},
max_speed = 4, -- m/s
stepheight = 1.1,
jump_height = 1.1,
buoyancy = .7,
lung_capacity = 10, -- seconds
ignore_liquidflag = false,
timeout = 500,
semiaquatic = false,
core_growth = false,
push_on_collide = true,
catch_with_net = false,
follow = {},
drops = {{name = "default:desert_sand", chance = 1, min = 3, max = 5},},
on_step = mob_core.on_step,
on_activate = mob_core.on_activate,
get_staticdata = mobkit.statfunc,
logic = guard_brain,
attack={range=2,damage_groups={fleshy=4}},
damage_groups={{fleshy=4}},
knockback = .05,
defend_owner = true,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
if time_from_last_punch < .5 then return end --dont hurt more than every .5 sec, cant make this tooo easy
mob_core.on_punch_basic(self, puncher, tool_capabilities, dir)
local prty = mobkit.get_queue_priority(self)
if prty < 60 then
mobkit.clear_queue_high(self)
end
local new_prty = prty + 5
if self.status ~= 'hunting' then
new_prty = math.random(60,100)
end
if new_prty > 95 then
new_prty = 100
end
if self.hp > 5 then
if mobkit.is_alive(self) then
local pos = self.object:get_pos()
if not(self.isinliquid) then
mob_core.hq_hunt(self, new_prty, puncher)
else
mob_core.hq_aqua_attack(self, new_prty, puncher, 1)
end
end
else
if mobkit.is_alive(self) then
local pos = self.object:get_pos()
if not(self.isinliquid) then
mobkit.hq_runfrom(self, new_prty, puncher)
else
mob_core.hq_swimfrom(self, new_prty, puncher, 1)
end
end
end
end,
})
mob_core.register_spawn({
name = 'yl_creatures:guard',
nodes = {"default:sand", "default:desert_sand"},
min_light = 0,
max_light = 7,
min_height = -500,
max_height = 100,
group = 3,
optional = {
reliability = 3
}
}, 10, 60)
mob_core.register_spawn_egg("yl_creatures:guard", "f5cc5b" ,"b57b24")
-- mob_core.register_set("mobs_walrus:walrus", "mobs_walrus_walrus1.png", true)