Add kill_mob and punch_entity triggers; it's now possible to create awards for killing mobs and punching entities

This commit is contained in:
Methacrylon 2018-06-14 07:54:44 +02:00
parent 21e1ce6675
commit d25e638cfb
3 changed files with 93 additions and 0 deletions

@ -958,3 +958,35 @@ if minetest.get_modpath("nyancat") then
}
})
end
if minetest.get_modpath("mobs_animal") then
awards.register_award("mobs:kill_chicken", {
title = S("Chicken"),
description = S("A test award when mobs mod on"),
difficulty = 0.001,
trigger = {
type = "kill_mob",
mob = "mobs_animal:chicken",
target = 5
}
})
awards.register_award("mobs:kill_cow", {
title = S("Cows"),
description = S("A test award when mobs mod on"),
difficulty = 0.001,
trigger = {
type = "kill_mob",
mob = "mobs_animal:cow",
target = 5
}
})
awards.register_award("mobs:kill_all", {
title = S("All"),
description = S("A test award when mobs mod on"),
difficulty = 0.001,
trigger = {
type = "kill_mob",
target = 5
}
})
end

@ -12,3 +12,4 @@ moreblocks?
fire?
flowers?
nyancat?
mobs_animal?

@ -135,3 +135,63 @@ minetest.register_on_item_eat(function(_, _, itemstack, player, _)
itemname = minetest.registered_aliases[itemname] or itemname
awards.notify_craft(player, itemname, itemstack:get_count())
end)
-- trigger for killing entities with more than 1 point of health
awards.register_trigger("kill_mob", {
type = "counted_key",
progress = "@1/@2 killed",
auto_description = { "Kill @2", "Kill @1×@2" },
auto_description_total = { "Kill @1 mob", "Kill @1 mobs." },
get_key = function(self, def)
return minetest.registered_aliases[def.trigger.mob] or def.trigger.mob
end
})
-- wait for all mobs to be registered
minetest.after(0, function()
local ents = minetest.registered_entities
local mobs = {}
for _, ent in pairs(ents) do
if ent.hp_max ~= nil and ent.hp_max > 0 then
table.insert(mobs,ent)
end
end
for _, mob in pairs(mobs) do
local old_func = mob.on_punch
mob.on_punch = function(self, player, a, b, c, d)
old_func(self, player, a, b, c, d)
if player and player:is_player() then
if self.health <= 0 then
awards.notify_kill_mob(player, self.name)
end
end
end
end
end)
-- trigger for killing an entity
awards.register_trigger("punch_entity", {
type = "counted_key",
progress = "@1/@2 killed",
auto_description = { "Punch @2", "Punch @1×@2" },
auto_description_total = { "Punch @1 entity", "Punch @1 entities." },
get_key = function(self, def)
return minetest.registered_aliases[def.trigger.mob] or def.trigger.mob
end
})
-- wait for all entities to be registered
minetest.after(0, function()
local ents = minetest.registered_entities
for _, ent in pairs(ents) do
if ent.hp_max == nil then
local old_func = ent.on_punch
ent.on_punch = function(self, player, a, b, c, d)
old_func(self, player, a, b, c, d)
if player and player:is_player() then
awards.notify_punch_entity(player, self.name)
end
end
end
end
end)