mirror of
				https://gitea.your-land.de/Sokomine/yl_speak_up.git
				synced 2025-10-30 03:53:05 +01:00 
			
		
		
		
	show dialog for on_failure of actions; improved formspecs
This commit is contained in:
		
							parent
							
								
									73aaa15c44
								
							
						
					
					
						commit
						4085e87f29
					
				| @ -909,17 +909,17 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, | ||||
| 		yl_speak_up.speak_to[pname][ tmp_data_cache ] = data | ||||
| 	end | ||||
| 
 | ||||
| 	local save_button = "button[5.0,9.8;1,0.7;save_element;Save]" | ||||
| 	local save_button = "button[5.0,11.8;1,0.7;save_element;Save]" | ||||
| 	local formspec = | ||||
| 		"formspec_version[3]".. | ||||
| 		"size[20,11]".. | ||||
| 		"size[20,13]".. | ||||
| 		"label[5,0.5;Edit "..element_desc.." \""..minetest.formspec_escape(x_id).."\"]".. | ||||
| 		"label[0.2,1.5;"..what_do_you_want_txt.."]".. | ||||
| 		"label[0.2,2.0;Something regarding...]".. | ||||
| 		"dropdown[4.0,1.8;14.0,0.6;select_what;".. | ||||
| 			table.concat(check_what, ",")..";".. | ||||
| 			tostring(data.what)..";]".. | ||||
| 		"button[3.0,9.8;1,0.7;back;Abort]" | ||||
| 		"button[3.0,11.8;1,0.7;back;Abort]" | ||||
| 
 | ||||
| 	if(id_prefix ~= "a_") then | ||||
| 		formspec = formspec.. | ||||
| @ -1111,7 +1111,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, | ||||
| 				"label[0.2,5.5;This will switch to dialog "..tostring(data.on_failure)..":]".. | ||||
| 				"hypertext[1.2,6.0;19.6,2.5;d_text;<normal>".. | ||||
| 				minetest.formspec_escape(dialog.n_dialogs[ data.on_failure ].d_text or "?").. | ||||
| 				"\n</normal>".."]" | ||||
| 				"\n</normal>]" | ||||
| 		end | ||||
| 		formspec = formspec.. | ||||
| 			"label[0.2,3.3;If the *previous* effect failed,]".. | ||||
| @ -1123,23 +1123,24 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, | ||||
| 
 | ||||
| 	-- "send a chat message to all players" -- 6 | ||||
| 	elseif(data.what and id_prefix == "r_" and data.what == 6) then | ||||
| 		local text = "$NPC_NAME$ (owned by $OWNER_NAME$) announces: $PLAYER_NAME$ ".. | ||||
| 		local default_text = "$NPC_NAME$ (owned by $OWNER_NAME$) announces: $PLAYER_NAME$ ".. | ||||
| 			"- example; please enter the text -" | ||||
| 		if(data and data.chat_msg_text) then | ||||
| 			text = data.chat_msg_text | ||||
| 		if(not(data)) then | ||||
| 			data = {} | ||||
| 		end | ||||
| 		formspec = formspec.. | ||||
| 			"label[0.2,3.3;Send the following chat message to *all* players:]".. | ||||
| 			"label[0.2,4.1;Message:]".. | ||||
| 			"field[2.0,3.8;16.0,0.6;chat_msg_text;;".. | ||||
| 				minetest.formspec_escape(tostring(text)).."]".. | ||||
| 				minetest.formspec_escape( | ||||
| 					data.chat_msg_text | ||||
| 					or default_text).."]".. | ||||
| 			"label[0.2,5.3;Note: Your chat message needs to contain the following placeholders,".. | ||||
| 				" which will be replaced automaticly like in dialog texts:".. | ||||
| 				"\n$NPC_NAME$, $PLAYER_NAME$ and $OWNER_NAME$.]" | ||||
| 
 | ||||
| 	-- "Normal trade - one item(stack) for another item(stack).", -- 3 | ||||
| 	elseif(data.what and id_prefix == "a_" and data.what == 3) then | ||||
| 		local pname = player:get_player_name() | ||||
| 		local dialog = yl_speak_up.speak_to[pname].dialog | ||||
| 		local d_id = yl_speak_up.speak_to[pname].d_id | ||||
| 		local o_id = yl_speak_up.speak_to[pname].o_id | ||||
| @ -1153,7 +1154,6 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, | ||||
| 				 "item_image[5.15,4.35;0.7,0.7;"..tostring(data.pay).."]" | ||||
| 		end | ||||
| 		yl_speak_up.speak_to[pname].trade_id = data.trade_id | ||||
| 		local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs) | ||||
| 		formspec = formspec.. | ||||
| 			"label[8,2.6;Your invnetory:]".. | ||||
| 			"list[current_player;main;8,3;8,4;]".. | ||||
| @ -1165,57 +1165,38 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, | ||||
| 			"label[4.0,3.8;"..minetest.formspec_escape(dialog.n_npc or "?").." sells:]".. | ||||
| 			-- show the second slot of said inventory | ||||
| 			"list[detached:yl_speak_up_player_"..pname..";setup;5,4.2;1,1;1]".. | ||||
| 			"label[0.2,5.8;The player shall trade with the NPC at least once.\n".. | ||||
| 				"If he doesn't, go to dialog:]".. | ||||
| 			"dropdown[4.3,6.0;2.8,0.6;select_on_action_failure;".. | ||||
| 				"- current one -,".. | ||||
| 				table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]".. | ||||
| 			bg_img | ||||
| 			bg_img.. | ||||
| 			yl_speak_up.set_on_action_failure_dialog(pname, data, | ||||
| 				"The player shall trade at least once.") | ||||
| 
 | ||||
| 	-- "The NPC gives something to the player (i.e. a quest item).", -- 4 | ||||
| 	-- (only for actions) | ||||
| 	elseif(data.what and id_prefix == "a_" and data.what == 4) then | ||||
| 		local pname = player:get_player_name() | ||||
| 		local dialog = yl_speak_up.speak_to[pname].dialog | ||||
| 		local item_quest_id = "- none set -" | ||||
| 		if(data and data.item_quest_id) then | ||||
| 			item_quest_id = data.item_quest_id | ||||
| 		end | ||||
| 		local item_desc = "- no item set -" | ||||
| 		if(data and data.item_desc) then | ||||
| 			item_desc = data.item_desc | ||||
| 		end | ||||
| 		local nr = 1 | ||||
| 		if(data and data.action_failure_dialog) then | ||||
| 			nr = data.action_failure_dialog + 1 | ||||
| 		end | ||||
| 		local stack_name = "" | ||||
| 		if(data and data.item_node_name) then | ||||
| 			stack_name = data.item_node_name | ||||
| 		if(not(data)) then | ||||
| 			data = {} | ||||
| 		end | ||||
| 		local bg_img = "" | ||||
| 		if(data and data.item_string) then | ||||
| 			bg_img = "item_image[2.15,3.65;0.7,0.7;"..tostring(data.item_string).."]" | ||||
| 		end | ||||
| 		local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs) | ||||
| 		formspec = formspec.. | ||||
| 			"label[8,2.6;Your invnetory:]".. | ||||
| 			"label[8,2.6;Your inventory:]".. | ||||
| 			"list[current_player;main;8,3;8,4;]".. | ||||
| 			"label[1,3.1;"..minetest.formspec_escape(dialog.n_npc or "?").." gives:]".. | ||||
| 			"list[detached:yl_speak_up_player_"..pname..";npc_gives;2,3.5;1,1;]".. | ||||
| 			"label[3.2,4.0;"..minetest.formspec_escape(stack_name).."]".. | ||||
| 			"label[1,4.9;The player shall take this offered item.\n".. | ||||
| 				"If he doesn't, go to dialog:]".. | ||||
| 			"dropdown[5.0,5.1;2.8,0.6;select_on_action_failure;".. | ||||
| 				"- current one -,".. | ||||
| 				table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]".. | ||||
| 			"label[3.2,4.0;".. | ||||
| 					minetest.formspec_escape( | ||||
| 						data.item_node_name | ||||
| 						or "- no item set -").."]".. | ||||
| 			"label[0.2,6.1;Set a description to turn the item into a special\n".. | ||||
| 				"quest item. Set a special ID (short text) so that\n".. | ||||
| 				"the player cannot create a fake item. Click on \n".. | ||||
| 				"\"Save\" to apply the changes.]".. | ||||
| 			"label[0.2,8.3;Special ID to set:]".. | ||||
| 			"field[3.2,8.0;14.5,0.6;action_item_quest_id;;".. | ||||
| 				minetest.formspec_escape(tostring(item_quest_id)).."]".. | ||||
| 					minetest.formspec_escape( | ||||
| 						data.item_quest_id | ||||
| 						or "- none set -").."]".. | ||||
| 			"tooltip[action_item_quest_id;".. | ||||
| 				"Set this to a text that helps *you* to remember what this\n".. | ||||
| 				"special quest item is for (i.e. \"quest_deliver_augusts_".. | ||||
| @ -1224,89 +1205,73 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, | ||||
| 				"name of the player who got this item from the NPC.]".. | ||||
| 			"label[0.2,9.0;Description to set:]".. | ||||
| 			"field[3.2,8.7;14.5,0.6;action_item_desc;;".. | ||||
| 				minetest.formspec_escape(tostring(item_desc)).."]".. | ||||
| 					minetest.formspec_escape( | ||||
| 						data.item_desc | ||||
| 						or "- no item set -").."]".. | ||||
| 			"tooltip[action_item_desc;".. | ||||
| 				"Set this to a text that helps the *player* to remember what\n".. | ||||
| 				"this special quest item is for (i.e. \"Letter from August to\n".. | ||||
| 				"Frederike\" for a piece of paper).\n".. | ||||
| 				"This description is shown in the inventory on mouseover.]".. | ||||
| 			bg_img | ||||
| 			bg_img.. | ||||
| 			yl_speak_up.set_on_action_failure_dialog(pname, data, | ||||
| 				"The player shall take this offered item.") | ||||
| 
 | ||||
| 
 | ||||
| 	-- "The player is expected to give something to the NPC (i.e. a quest item).", -- 5 | ||||
| 	-- (only for actions) | ||||
| 	elseif(data.what and id_prefix == "a_" and data.what == 5) then | ||||
| 		local pname = player:get_player_name() | ||||
| 		local dialog = yl_speak_up.speak_to[pname].dialog | ||||
| 		local item_quest_id = "- none set -" | ||||
| 		if(data and data.item_quest_id) then | ||||
| 			item_quest_id = data.item_quest_id | ||||
| 		end | ||||
| 		local item_desc = "- no item set -" | ||||
| 		if(data and data.item_desc) then | ||||
| 			item_desc = data.item_desc | ||||
| 		end | ||||
| 		local nr = 1 | ||||
| 		if(data and data.action_failure_dialog) then | ||||
| 			nr = data.action_failure_dialog + 1 | ||||
| 		end | ||||
| 		local stack_name = "" | ||||
| 		if(data and data.item_node_name) then | ||||
| 			stack_name = data.item_node_name | ||||
| 		if(not(data)) then | ||||
| 			data = {} | ||||
| 		end | ||||
| 		local bg_img = "" | ||||
| 		if(data and data.item_string) then | ||||
| 			bg_img = "item_image[2.15,3.65;0.7,0.7;"..tostring(data.item_string).."]" | ||||
| 		end | ||||
| 		local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs) | ||||
| 		formspec = formspec.. | ||||
| 			"label[8,2.6;Your invnetory:]".. | ||||
| 			"label[8,2.6;Your inventory:]".. | ||||
| 			"list[current_player;main;8,3;8,4;]".. | ||||
| 			"label[1,3.1;"..minetest.formspec_escape(dialog.n_npc or "?").." wants:]".. | ||||
| 			"list[detached:yl_speak_up_player_"..pname..";npc_wants;2,3.5;1,1;]".. | ||||
| 			"label[3.2,4.0;"..minetest.formspec_escape(stack_name).."]".. | ||||
| 			"label[1,4.9;The player shall give the NPC this item.\n".. | ||||
| 				"If he doesn't, go to dialog:]".. | ||||
| 			"dropdown[5.0,5.1;2.8,0.6;select_on_action_failure;".. | ||||
| 				"- current one -,".. | ||||
| 				table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]".. | ||||
| 			"label[3.2,4.0;".. | ||||
| 				minetest.formspec_escape( | ||||
| 					data.item_node_name | ||||
| 					or "- no item set -").."]".. | ||||
| 			"label[0.2,6.1;If you want a special ID and description, create\n".. | ||||
| 				"those via the \"NPC gives something to the player\"\n".. | ||||
| 				"menu option first and insert that item here.]".. | ||||
| 			"label[0.2,8.3;Expected special ID:]".. | ||||
| 			"label[4.0,8.3;".. | ||||
| 				minetest.formspec_escape(tostring(item_quest_id)).."]".. | ||||
| 				minetest.formspec_escape( | ||||
| 					data.item_quest_id | ||||
| 					or "- none set -").."]".. | ||||
| 			"label[0.2,9.0;Expected description:]".. | ||||
| 			"label[4.0,9.0;".. | ||||
| 				minetest.formspec_escape(tostring(item_desc)).."]".. | ||||
| 			bg_img | ||||
| 				minetest.formspec_escape( | ||||
| 					 data.item_desc | ||||
| 					 or "- none set -").."]".. | ||||
| 			bg_img.. | ||||
| 			yl_speak_up.set_on_action_failure_dialog(pname, data, | ||||
| 				"The player shall give the NPC this item.") | ||||
| 
 | ||||
| 	-- "The player has to manually enter a password or passphrase or some other text.", -- 6 | ||||
| 	-- (only for actions) | ||||
| 	elseif(data.what and id_prefix == "a_" and data.what == 6) then | ||||
| 		local question = "Your answer:" | ||||
| 		if(data and data.quest_question) then | ||||
| 			question = data.quest_question | ||||
| 		if(not(data)) then | ||||
| 			data = {} | ||||
| 		end | ||||
| 		local answer = "- Insert the correct answer here -" | ||||
| 		if(data and data.quest_answer) then | ||||
| 			answer = data.quest_answer | ||||
| 		end | ||||
| 		local nr = 1 | ||||
| 		if(data and data.action_failure_dialog) then | ||||
| 			nr = data.action_failure_dialog + 1 | ||||
| 		end | ||||
| 		local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs) | ||||
| 		formspec = formspec.. | ||||
| 			"label[0.2,3.3;What to ask the player and which answer to expect:]".. | ||||
| 			"label[0.2,4.0;Question to show:]".. | ||||
| 			"field[4.0,3.8;10.0,0.6;quest_question;;"..tostring(question).."]".. | ||||
| 			"field[4.0,3.8;10.0,0.6;quest_question;;".. | ||||
| 				minetest.formspec_escape( | ||||
| 					data.quest_question | ||||
| 					or "Your answer:").."]".. | ||||
| 			"label[0.2,5.0;Expected answer:]".. | ||||
| 			"field[4.0,4.8;10.0,0.6;quest_answer;;"..tostring(answer).."]".. | ||||
| 			"label[0.2,6.0;If the player gives the wrong answer, go to dialog:]".. | ||||
| 			"dropdown[8.0,5.7;2.8,0.6;select_on_action_failure;".. | ||||
| 				"- current one -,".. | ||||
| 				table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]".. | ||||
| 			"field[4.0,4.8;10.0,0.6;quest_answer;;".. | ||||
| 				minetest.formspec_escape( | ||||
| 					data.quest_answer | ||||
| 					or "- Insert the correct answer here -").."]".. | ||||
| 			"tooltip[quest_question;".. | ||||
| 				"This is just a short text that will be shown to remind\n".. | ||||
| 				"the player what he is asked for. Most of the question\n".. | ||||
| @ -1320,29 +1285,24 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, | ||||
| 				"a diffrent target dialog (i.e. with text \"No, that answer\n".. | ||||
| 				"was wrong, but please try again!\"). In such a case the\n".. | ||||
| 				"effects/results of the current dialog option are *not*\n".. | ||||
| 				"executed.]" | ||||
| 				"executed.]".. | ||||
| 			yl_speak_up.set_on_action_failure_dialog(pname, data, | ||||
| 				"The player shall enter the correct answer.") | ||||
| 
 | ||||
| 	-- "Call custom functions that are supposed to be overridden by the server.", -- 7 | ||||
| 	-- (only for actions) | ||||
| 	elseif(data.what and id_prefix == "a_" and data.what == 7) then | ||||
| 		local custom_param = "- Insert a text that is passed on to your function here -" | ||||
| 		if(data and data.custom_param) then | ||||
| 			custom_param = data.custom_param | ||||
| 		if(not(data)) then | ||||
| 			data = {} | ||||
| 		end | ||||
| 		local nr = 1 | ||||
| 		if(data and data.action_failure_dialog) then | ||||
| 			nr = data.action_failure_dialog + 1 | ||||
| 		end | ||||
| 		local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs) | ||||
| 		formspec = formspec.. | ||||
| 			"label[0.2,3.3;Note: Calling a custom function will require direct support ".. | ||||
| 				"from the server.]".. | ||||
| 			"label[0.2,4.0;Parameter for custom function:]".. | ||||
| 			"field[6.0,3.7;10.0,0.6;custom_param;;"..tostring(custom_param).."]".. | ||||
| 			"label[0.2,5.0;If the player fails at it, go to dialog:]".. | ||||
| 			"dropdown[6.0,4.7;2.8,0.6;select_on_action_failure;".. | ||||
| 				"- current one -,".. | ||||
| 				table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]".. | ||||
| 			"field[6.0,3.7;10.0,0.6;custom_param;;".. | ||||
| 				minetest.formspec_escape( | ||||
| 					data.custom_param | ||||
| 					or "- Insert a text that is passed on to your function here -").."]".. | ||||
| 			"tooltip[custom_param;".. | ||||
| 				"The custom parameter may help whoever implements the\n".. | ||||
| 				"custom function to more easily see what it belongs to.\n".. | ||||
| @ -1352,7 +1312,33 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, | ||||
| 				"a diffrent target dialog (i.e. with text \"No, that answer\n".. | ||||
| 				"was wrong, but please try again!\"). In such a case the\n".. | ||||
| 				"effects/results of the current dialog option are *not*\n".. | ||||
| 				"executed.]" | ||||
| 				"executed.]".. | ||||
| 			yl_speak_up.set_on_action_failure_dialog(pname, data, | ||||
| 				"The player shall click on the right button.") | ||||
| 	end | ||||
| 	return formspec..save_button | ||||
| end | ||||
| 
 | ||||
| 
 | ||||
| -- helper function | ||||
| yl_speak_up.set_on_action_failure_dialog = function(pname, data, instruction) | ||||
| 	local dialog = yl_speak_up.speak_to[pname].dialog | ||||
| 	local nr = 1 | ||||
| 	if(data and data.action_failure_dialog) then | ||||
| 		nr = data.action_failure_dialog + 1 | ||||
| 	end | ||||
| 	local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs) | ||||
| 	local on_failure_dialog = | ||||
| 		"label[0.2,9.9;"..tostring(instruction).." If he doesn't, go to dialog:]".. | ||||
| 		"dropdown[11.0,9.6;2.8,0.6;select_on_action_failure;".. | ||||
| 			"- current one -,".. | ||||
| 			table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]" | ||||
| 	if(nr and nr > 1) then | ||||
| 		local failure_d_id = sorted_dialog_list[ nr - 1] | ||||
| 		on_failure_dialog = on_failure_dialog.. | ||||
| 			"hypertext[1.2,10.4.0;19.6,1.0;d_text;<normal>".. | ||||
| 			minetest.formspec_escape(dialog.n_dialogs[ failure_d_id ].d_text or "?").. | ||||
| 			"\n</normal>]" | ||||
| 	end | ||||
| 	return on_failure_dialog | ||||
| end | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user