mirror of
				https://gitlab.com/rubenwardy/awards.git
				synced 2025-11-04 14:45:29 +01:00 
			
		
		
		
	Secret awards, fixes
This commit is contained in:
		
							
								
								
									
										79
									
								
								api.lua
									
									
									
									
									
								
							
							
						
						
									
										79
									
								
								api.lua
									
									
									
									
									
								
							@@ -261,15 +261,15 @@ minetest.register_chatcommand("list_awards", {
 | 
			
		||||
	end
 | 
			
		||||
})
 | 
			
		||||
minetest.register_chatcommand("awards", {
 | 
			
		||||
	params = "Empty params for your awards, player name for someone else's awards",
 | 
			
		||||
	params = "",
 | 
			
		||||
	description = "awards: list awards",
 | 
			
		||||
	func = function(name, param)
 | 
			
		||||
		awards.showto(name, name, nil, false)
 | 
			
		||||
	end
 | 
			
		||||
})
 | 
			
		||||
minetest.register_chatcommand("cawards", {
 | 
			
		||||
	params = "Empty params for your awards, player name for someone else's awards",
 | 
			
		||||
	description = "awards: list awards",
 | 
			
		||||
	params = "",
 | 
			
		||||
	description = "awards: list awards in chat",
 | 
			
		||||
	func = function(name, param)
 | 
			
		||||
		awards.showto(name, name, nil, true)
 | 
			
		||||
	end
 | 
			
		||||
@@ -313,15 +313,27 @@ function awards._order_awards(name)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function awards.showto(name, to, sid, text)
 | 
			
		||||
	if name == "" or name == nil then
 | 
			
		||||
		name = to
 | 
			
		||||
	end
 | 
			
		||||
	if text then
 | 
			
		||||
		if not awards.players[name] or not awards.players[name].unlocked  then
 | 
			
		||||
			minetest.chat_send_player(name, "You do not have any awards")
 | 
			
		||||
			minetest.chat_send_player(to, "You have not unlocked any awards")
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
		minetest.chat_send_player(to, name.."'s awards:")
 | 
			
		||||
 | 
			
		||||
		for _, str in pairs(awards.players[name].unlocked) do
 | 
			
		||||
			minetest.chat_send_player(to, str)
 | 
			
		||||
			local def = awards.def[str]
 | 
			
		||||
			if def and def.title then
 | 
			
		||||
				if def.description then				
 | 
			
		||||
					minetest.chat_send_player(to, def.title..": "..def.description)
 | 
			
		||||
				else
 | 
			
		||||
					minetest.chat_send_player(to, def.title)
 | 
			
		||||
				end
 | 
			
		||||
			else
 | 
			
		||||
				minetest.chat_send_player(to, str)
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	else
 | 
			
		||||
		if sid == nil or sid < 1 then
 | 
			
		||||
@@ -334,21 +346,29 @@ function awards.showto(name, to, sid, text)
 | 
			
		||||
		if sid then
 | 
			
		||||
			local item = listofawards[sid+0]
 | 
			
		||||
			local def = awards.def[item.name]
 | 
			
		||||
			local title = item.name
 | 
			
		||||
			if def and def.title then
 | 
			
		||||
				title = def.title
 | 
			
		||||
			end
 | 
			
		||||
			local status = ""
 | 
			
		||||
			if item.got then
 | 
			
		||||
				status = " (got)"
 | 
			
		||||
			end
 | 
			
		||||
			if def and def.icon then
 | 
			
		||||
				icon = def.icon
 | 
			
		||||
			end
 | 
			
		||||
			formspec = formspec .. "label[1,2.75;"..title..status.."]"..
 | 
			
		||||
								"image[1,0;3,3;"..icon.."]"
 | 
			
		||||
			if def and def.description then
 | 
			
		||||
				formspec = formspec	.. "label[0,3.25;"..def.description.."]"				
 | 
			
		||||
			if def and def.secret and not item.got then
 | 
			
		||||
				formspec = formspec .. "label[1,2.75;Secret Award]"..
 | 
			
		||||
									"image[1,0;3,3;unknown.png]"
 | 
			
		||||
				if def and def.description then
 | 
			
		||||
					formspec = formspec	.. "label[0,3.25;Unlock this award to find out what it is]"				
 | 
			
		||||
				end
 | 
			
		||||
			else
 | 
			
		||||
				local title = item.name
 | 
			
		||||
				if def and def.title then
 | 
			
		||||
					title = def.title
 | 
			
		||||
				end
 | 
			
		||||
				local status = ""
 | 
			
		||||
				if item.got then
 | 
			
		||||
					status = " (got)"
 | 
			
		||||
				end
 | 
			
		||||
				if def and def.icon then
 | 
			
		||||
					icon = def.icon
 | 
			
		||||
				end
 | 
			
		||||
				formspec = formspec .. "label[1,2.75;"..title..status.."]"..
 | 
			
		||||
									"image[1,0;3,3;"..icon.."]"
 | 
			
		||||
				if def and def.description then
 | 
			
		||||
					formspec = formspec	.. "label[0,3.25;"..def.description.."]"				
 | 
			
		||||
				end
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
		
 | 
			
		||||
@@ -361,16 +381,19 @@ function awards.showto(name, to, sid, text)
 | 
			
		||||
			end
 | 
			
		||||
			first = false
 | 
			
		||||
			local def = awards.def[award.name]
 | 
			
		||||
			local title = award.name
 | 
			
		||||
			
 | 
			
		||||
			if def and def.title then
 | 
			
		||||
				title = def.title
 | 
			
		||||
			end
 | 
			
		||||
			
 | 
			
		||||
			if award.got then
 | 
			
		||||
				formspec = formspec .. minetest.formspec_escape(title)
 | 
			
		||||
			if def and def.secret and not award.got then
 | 
			
		||||
				formspec = formspec .. "#ACACACSecret Award"
 | 
			
		||||
			else
 | 
			
		||||
				formspec = formspec .. "#ACACAC".. minetest.formspec_escape(title)
 | 
			
		||||
				local title = award.name			
 | 
			
		||||
				if def and def.title then
 | 
			
		||||
					title = def.title
 | 
			
		||||
				end			
 | 
			
		||||
				if award.got then
 | 
			
		||||
					formspec = formspec .. minetest.formspec_escape(title)
 | 
			
		||||
				else
 | 
			
		||||
					formspec = formspec .. "#ACACAC".. minetest.formspec_escape(title)
 | 
			
		||||
				end
 | 
			
		||||
			end
 | 
			
		||||
		end		
 | 
			
		||||
		formspec = formspec .. ";"..sid.."]"
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								init.lua
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								init.lua
									
									
									
									
									
								
							@@ -126,7 +126,7 @@ awards.register_achievement("award_death1",{
 | 
			
		||||
-- Burned to death
 | 
			
		||||
awards.register_achievement("award_burn",{
 | 
			
		||||
	title = S("You're a witch!"),
 | 
			
		||||
	description = S("Burn to death in a fire"),
 | 
			
		||||
	description = S("Burn to death in a fire")
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
-- 1 sentence
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										12
									
								
								readme.md
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								readme.md
									
									
									
									
									
								
							@@ -17,9 +17,10 @@ The API
 | 
			
		||||
	* sound [optional]
 | 
			
		||||
	* image [optional]
 | 
			
		||||
	* trigger [optional] [table]
 | 
			
		||||
		* type - "dig" or "place"
 | 
			
		||||
		* type - "dig", "place", "death", "chat" or "join"
 | 
			
		||||
		* (for dig/place type) node - the nodes name
 | 
			
		||||
		* (for all types) target - how many to dig / place
 | 
			
		||||
	* secret [optional] - if true, then player needs to unlock to find out what it is.
 | 
			
		||||
* awards.give_achievement(name,award)
 | 
			
		||||
	* -- gives an award to a player
 | 
			
		||||
* awards.register_onDig(func(player,data))
 | 
			
		||||
@@ -28,6 +29,10 @@ The API
 | 
			
		||||
	* -- return award name or null
 | 
			
		||||
* awards.register_onDeath(func(player,data))
 | 
			
		||||
	* -- return award name or null
 | 
			
		||||
* awards.register_onChat(func(player,data))
 | 
			
		||||
	* -- return award name or null
 | 
			
		||||
* awards.register_onJoin(func(player,data))
 | 
			
		||||
	* -- return award name or null
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Player Data
 | 
			
		||||
@@ -41,4 +46,7 @@ A list of data referenced/hashed by the player's name.
 | 
			
		||||
			* itemname [int]
 | 
			
		||||
	* place [table] - place counter
 | 
			
		||||
		* modname [table]
 | 
			
		||||
			* itemname [int]
 | 
			
		||||
			* itemname [int]
 | 
			
		||||
	* deaths
 | 
			
		||||
	* chats
 | 
			
		||||
	* joins
 | 
			
		||||
		Reference in New Issue
	
	Block a user