Fix mobs doing stuff after death

This commit is contained in:
Johannes Fritz 2022-04-29 12:40:42 -05:00
parent 93c5127d1c
commit 711eea3a27
14 changed files with 40 additions and 3 deletions

View File

@ -964,8 +964,7 @@ creatura.register_utility("animalia:boid_flee_from_player", function(self, playe
if #mobs_in_group > 0 then
for i = 1, #mobs_in_group do
local mob = mobs_in_group[i]
mob:get_luaentity():initiate_utility("animalia:boid_flee_from_player", mob:get_luaentity(), player)
mob:get_luaentity():set_utility_score(1)
mob:get_luaentity():try_initiate_utility("animalia:boid_flee_from_player", 1, mob:get_luaentity(), player)
end
end
end

View File

@ -256,9 +256,11 @@ creatura.register_mob("animalia:bat", {
death_func = function(self)
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
self:set_utility_score(2)
end
end,
on_rightclick = function(self, clicker)
if self:get_utility() == "animalia:die" then return end
if animalia.feed(self, clicker, false, false) then
return
end
@ -268,6 +270,7 @@ creatura.register_mob("animalia:bat", {
animalia.add_libri_page(self, clicker, {name = "bat", form = "pg_bat;Bats"})
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
if self:get_utility() == "animalia:die" then return end
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
end
})

View File

@ -209,6 +209,7 @@ creatura.register_mob("animalia:bird", {
death_func = function(self)
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
self:set_utility_score(2)
end
end,
deactivate_func = function(self)
@ -224,6 +225,7 @@ creatura.register_mob("animalia:bird", {
end
end,
on_rightclick = function(self, clicker)
if self:get_utility() == "animalia:die" then return end
if animalia.feed(self, clicker, false, false) then
return
end
@ -233,6 +235,7 @@ creatura.register_mob("animalia:bird", {
animalia.add_libri_page(self, clicker, {name = "bird", form = "pg_bird;Birds"})
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
if self:get_utility() == "animalia:die" then return end
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
end
})

View File

@ -207,9 +207,11 @@ creatura.register_mob("animalia:cat", {
death_func = function(self)
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
self:set_utility_score(2)
end
end,
on_rightclick = function(self, clicker)
if self:get_utility() == "animalia:die" then return end
local item_name = clicker:get_wielded_item():get_name()
if item_name == "animalia:net" then return end
local trust = self.trust[clicker:get_player_name()] or 0
@ -286,6 +288,7 @@ creatura.register_mob("animalia:cat", {
end
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
if self:get_utility() == "animalia:die" then return end
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
self:initiate_utility("animalia:flee_from_player", self, puncher)
self:set_utility_score(1)

View File

@ -145,9 +145,11 @@ creatura.register_mob("animalia:chicken", {
death_func = function(self)
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
self:set_utility_score(2)
end
end,
on_rightclick = function(self, clicker)
if self:get_utility() == "animalia:die" then return end
if animalia.feed(self, clicker, false, true) then
return
end
@ -157,6 +159,7 @@ creatura.register_mob("animalia:chicken", {
animalia.add_libri_page(self, clicker, {name = "chicken", form = "pg_chicken;Chickens"})
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
if self:get_utility() == "animalia:die" then return end
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
self:initiate_utility("animalia:flee_from_player", self, puncher)
self:set_utility_score(1)

View File

@ -163,9 +163,11 @@ creatura.register_mob("animalia:cow", {
death_func = function(self)
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
self:set_utility_score(2)
end
end,
on_rightclick = function(self, clicker)
if self:get_utility() == "animalia:die" then return end
if animalia.feed(self, clicker, false, true) then
return
end
@ -205,6 +207,7 @@ creatura.register_mob("animalia:cow", {
animalia.add_libri_page(self, clicker, {name = "cow", form = "pg_cow;Cows"})
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
if self:get_utility() == "animalia:die" then return end
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
self:initiate_utility("animalia:flee_from_player", self, puncher)
self:set_utility_score(1)

View File

@ -173,9 +173,11 @@ creatura.register_mob("animalia:frog", {
death_func = function(self)
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
self:set_utility_score(2)
end
end,
on_rightclick = function(self, clicker)
if self:get_utility() == "animalia:die" then return end
if animalia.feed(self, clicker, false, true) then
local name = clicker:get_player_name()
if self.trust[name] then
@ -193,6 +195,7 @@ creatura.register_mob("animalia:frog", {
animalia.add_libri_page(self, clicker, {name = "frog", form = "pg_frog;Frogs"})
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
if self:get_utility() == "animalia:die" then return end
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
self.trust[puncher:get_player_name()] = 0
self:memorize("trust", self.trust)

View File

@ -260,9 +260,11 @@ creatura.register_mob("animalia:horse", {
death_func = function(self)
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
self:set_utility_score(2)
end
end,
on_rightclick = function(self, clicker)
if self:get_utility() == "animalia:die" then return end
if animalia.feed(self, clicker, false, true) then
return
end
@ -300,6 +302,7 @@ creatura.register_mob("animalia:horse", {
animalia.add_libri_page(self, clicker, {name = "horse", form = "pg_horse;Horses"})
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
if self:get_utility() == "animalia:die" then return end
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
self:initiate_utility("animalia:boid_flee_from_player", self, puncher, true)
self:set_utility_score(1)

View File

@ -153,9 +153,11 @@ creatura.register_mob("animalia:pig", {
death_func = function(self)
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
self:set_utility_score(2)
end
end,
on_rightclick = function(self, clicker)
if self:get_utility() == "animalia:die" then return end
if animalia.feed(self, clicker, false, true) then
return
end
@ -165,6 +167,7 @@ creatura.register_mob("animalia:pig", {
animalia.add_libri_page(self, clicker, {name = "pig", form = "pg_pig;Pigs"})
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
if self:get_utility() == "animalia:die" then return end
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
self:initiate_utility("animalia:flee_from_player", self, puncher)
self:set_utility_score(1)

View File

@ -131,9 +131,11 @@ creatura.register_mob("animalia:reindeer", {
death_func = function(self)
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
self:set_utility_score(2)
end
end,
on_rightclick = function(self, clicker)
if self:get_utility() == "animalia:die" then return end
if animalia.feed(self, clicker, false, true) then
return
end
@ -143,6 +145,7 @@ creatura.register_mob("animalia:reindeer", {
animalia.add_libri_page(self, clicker, {name = "reindeer", form = "pg_reindeer;Reindeer"})
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
if self:get_utility() == "animalia:die" then return end
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
self:initiate_utility("animalia:boid_flee_from_player", self, puncher, true)
self:set_utility_score(1)

View File

@ -190,9 +190,11 @@ creatura.register_mob("animalia:sheep", {
death_func = function(self)
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
self:set_utility_score(2)
end
end,
on_rightclick = function(self, clicker)
if self:get_utility() == "animalia:die" then return end
if animalia.feed(self, clicker, false, true) then
return
end
@ -255,6 +257,7 @@ creatura.register_mob("animalia:sheep", {
animalia.add_libri_page(self, clicker, {name = "sheep", form = "pg_sheep;Sheep"})
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
if self:get_utility() == "animalia:die" then return end
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
self:initiate_utility("animalia:boid_flee_from_player", self, puncher, true)
self:set_utility_score(1)

View File

@ -72,15 +72,18 @@ creatura.register_mob("animalia:tropical_fish", {
death_func = function(self)
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
self:set_utility_score(2)
end
end,
on_rightclick = function(self, clicker)
if self:get_utility() == "animalia:die" then return end
if animalia.set_nametag(self, clicker) then
return
end
animalia.add_libri_page(self, clicker, {name = "tropical_fish", form = "pg_tropical_fish;Tropical Fish"})
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
if self:get_utility() == "animalia:die" then return end
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
end
})

View File

@ -136,9 +136,11 @@ creatura.register_mob("animalia:turkey", {
death_func = function(self)
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
self:set_utility_score(2)
end
end,
on_rightclick = function(self, clicker)
if self:get_utility() == "animalia:die" then return end
if animalia.feed(self, clicker, false, true) then
return
end
@ -148,6 +150,7 @@ creatura.register_mob("animalia:turkey", {
animalia.add_libri_page(self, clicker, {name = "turkey", form = "pg_turkey;Turkeys"})
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
if self:get_utility() == "animalia:die" then return end
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
self:initiate_utility("animalia:flee_from_player", self, puncher)
self:set_utility_score(1)

View File

@ -190,10 +190,11 @@ creatura.register_mob("animalia:wolf", {
death_func = function(self)
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
self:set_utility_score(2)
end
end,
on_rightclick = function(self, clicker)
if not clicker:is_player() then return end
if self:get_utility() == "animalia:die" or not clicker:is_player() then return end
local passive = true
if is_value_in_table(self.enemies, clicker:get_player_name()) then
passive = false
@ -228,6 +229,7 @@ creatura.register_mob("animalia:wolf", {
animalia.add_libri_page(self, clicker, {name = "wolf", form = "pg_wolf;Wolves"})
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
if self:get_utility() == "animalia:die" then return end
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
if puncher:is_player() then
if self.owner