forked from mtcontrib/awards
		
	Fix group total, fix item increment count argument, add player checks, resize award icon, fix log output
This commit is contained in:
		| @@ -43,6 +43,11 @@ end | ||||
| -- name - the name of the player | ||||
| -- award - the name of the award to give | ||||
| function awards.unlock(name, award) | ||||
| 	-- Ensure the player is online. | ||||
| 	if not minetest.get_player_by_name(name) then | ||||
| 		return | ||||
| 	end | ||||
|  | ||||
| 	-- Access Player Data | ||||
| 	local data  = awards.player(name) | ||||
| 	local awdef = awards.registered_awards[award] | ||||
| @@ -60,7 +65,7 @@ function awards.unlock(name, award) | ||||
| 	end | ||||
|  | ||||
| 	-- Unlock Award | ||||
| 	minetest.log("action", name.." has unlocked award "..name) | ||||
| 	minetest.log("action", name.." has unlocked award "..award) | ||||
| 	data.unlocked[award] = award | ||||
| 	awards.save() | ||||
|  | ||||
| @@ -91,7 +96,7 @@ function awards.unlock(name, award) | ||||
| 	local title = awdef.title or award | ||||
| 	local desc = awdef.description or "" | ||||
| 	local background = awdef.background or "awards_bg_default.png" | ||||
| 	local icon = awdef.icon or "awards_unknown.png" | ||||
| 	local icon = (awdef.icon or "awards_unknown.png") .. "^[resize:32x32" | ||||
| 	local sound = awdef.sound | ||||
| 	if sound == nil then | ||||
| 		-- Explicit check for nil because sound could be `false` to disable it | ||||
|   | ||||
| @@ -160,8 +160,9 @@ function awards.register_trigger(tname, tdef) | ||||
| 			data[tname] = data[tname] or {} | ||||
| 			local currentVal = (data[tname][key] or 0) + n | ||||
| 			data[tname][key] = currentVal | ||||
| 			data[tname].__total = (data[tname].__total or 0) | ||||
| 			if key:sub(1, 6) ~= "group:" then | ||||
| 				data[tname].__total = (data[tname].__total or 0) + n | ||||
| 				data[tname].__total = data[tname].__total + n | ||||
| 			end | ||||
|  | ||||
| 			tdef:run_callbacks(player, data, function(entry) | ||||
| @@ -173,7 +174,6 @@ function awards.register_trigger(tname, tdef) | ||||
| 				else | ||||
| 					return | ||||
| 				end | ||||
|  | ||||
| 				if current >= entry.target then | ||||
| 					return entry.award | ||||
| 				end | ||||
| @@ -201,7 +201,7 @@ end | ||||
|  | ||||
| function awards.increment_item_counter(data, field, itemname, count) | ||||
| 	itemname = minetest.registered_aliases[itemname] or itemname | ||||
| 	data[field][itemname] = (data[field][itemname] or 0) + 1 | ||||
| 	data[field][itemname] = (data[field][itemname] or 0) + (count or 1) | ||||
| end | ||||
|  | ||||
| function awards.get_item_count(data, field, itemname) | ||||
|   | ||||
| @@ -141,5 +141,5 @@ minetest.register_on_item_eat(function(_, _, itemstack, player, _) | ||||
|  | ||||
| 	local itemname = itemstack:get_name() | ||||
| 	itemname = minetest.registered_aliases[itemname] or itemname | ||||
| 	awards.notify_eat(player, itemname, itemstack:get_count()) | ||||
| 	awards.notify_eat(player, itemname) | ||||
| end) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user