forked from mtcontrib/awards
		
	Compare commits
	
		
			3 Commits
		
	
	
		
			8702b6cdd8
			...
			github/for
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					95991ce94f | ||
| 
						 | 
					7a7ddc88af | ||
| 
						 | 
					d25e638cfb | 
							
								
								
									
										42
									
								
								awards.lua
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								awards.lua
									
									
									
									
									
								
							@@ -958,3 +958,45 @@ 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
 | 
			
		||||
 | 
			
		||||
awards.register_award("pnch_entity_test", {
 | 
			
		||||
	title = S("All"),
 | 
			
		||||
	description = S("A test award for punching"),
 | 
			
		||||
	difficulty = 0.001,
 | 
			
		||||
	trigger = {
 | 
			
		||||
		type = "punch_entity",
 | 
			
		||||
		target = 5
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
 
 | 
			
		||||
@@ -12,3 +12,4 @@ moreblocks?
 | 
			
		||||
fire?
 | 
			
		||||
flowers?
 | 
			
		||||
nyancat?
 | 
			
		||||
mobs_animal?
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										60
									
								
								triggers.lua
									
									
									
									
									
								
							
							
						
						
									
										60
									
								
								triggers.lua
									
									
									
									
									
								
							@@ -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 punched",
 | 
			
		||||
	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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user