forked from your-land-mirror/yl_speak_up
		
	cleanup of privs; used yl_speak_up.npc_privs_priv instead of npc_master for npc priv maintenance; npc_master REMAINS necessary for executing lua code!
This commit is contained in:
		
							parent
							
								
									675af7b256
								
							
						
					
					
						commit
						9e09712781
					
				| @ -418,7 +418,8 @@ and usually set to 5. | ||||
| 
 | ||||
| There are several ways of giving items to the NPC: trade, using an action where the | ||||
| NPC wants a more or less special item, or an effect/result where the NPC just removes | ||||
| the item from the player's inventory and thrashes it (requires `npc_master` priv). | ||||
| the item from the player's inventory and thrashes it (requires `npc_talk_admin` priv | ||||
| - or whichever priv you set in config.lua as `yl_speak_up.npc_privs_priv`). | ||||
| Using an action might work in many situations. There may be situations where it | ||||
| would be far more convenient for the player to just give the items to the NPC and let | ||||
| it deal with it. | ||||
| @ -518,7 +519,7 @@ and | ||||
| You can also react to or limit normal property changes this way. | ||||
| 
 | ||||
| Properties starting with "server" can only be changed by players who have | ||||
| the npc_master priv. | ||||
| the `npc_talk_admin` priv. | ||||
| 
 | ||||
| Example for a property: mood of the NPC (raises when treated well, gets | ||||
| lowered when treated badly). | ||||
|  | ||||
							
								
								
									
										10
									
								
								config.lua
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								config.lua
									
									
									
									
									
								
							| @ -149,6 +149,16 @@ yl_speak_up.player_vars_min_save_time = 60 | ||||
| -- created. This option exists to avoid them. Any small value will do. | ||||
| yl_speak_up.max_allowed_recursion_depth = 5 | ||||
| 
 | ||||
| -- * set the name of the priv that allows to add, edit and change preconditions, actions and | ||||
| --   effects listed in yl_speak_up.npc_priv_names in npc_privs.lua | ||||
| -- * this also allows the player to use the "/npc_talk privs" command to assign these privs | ||||
| --   to NPC | ||||
| -- * it does *NOT* include the "precon_exec_lua" and "effect_exec_lua" priv - just | ||||
| --   "effect_give_item", "effect_take_item" and "effect_move_player" | ||||
| -- * default: "npc_talk_admin" (but can also be set to "npc_master" or "privs" if you want) | ||||
| yl_speak_up.npc_privs_priv = "npc_talk_admin" | ||||
| 
 | ||||
| 
 | ||||
| -- Texts | ||||
| 
 | ||||
| yl_speak_up.message_button_option_exit = "Farewell!" | ||||
|  | ||||
| @ -54,13 +54,13 @@ | ||||
| -- 	r_value		chat message sent to all players | ||||
| -- | ||||
| -- | ||||
| -- give item to player ("give_item"): requires npc_master priv | ||||
| -- give item to player ("give_item"): requires yl_speak_up.npc_privs_priv priv | ||||
| -- 	r_value		the itemstack that shall be added to the player's inventory | ||||
| -- | ||||
| -- take item from player's inventory ("take_item"): requires npc_master priv | ||||
| -- take item from player's inventory ("take_item"): requires yl_speak_up.npc_privs_priv priv | ||||
| -- 	r_value		the itemstack that will be removed from the player's inventory | ||||
| -- | ||||
| -- move the player to a position ("move"): requires npc_master priv | ||||
| -- move the player to a position ("move"): requires yl_speak_up.npc_privs_priv priv | ||||
| -- 	r_value		the position where the player shall be moved to | ||||
| -- | ||||
| -- execute lua code ("function"): requires npc_master priv | ||||
| @ -87,9 +87,12 @@ local check_what = { | ||||
| 	"NPC crafts something", -- 6 | ||||
| 	"go to other dialog if the previous effect failed", -- 7 | ||||
| 	"send a chat message to all players", -- 8 | ||||
| 	"give item (created out of thin air) to player (requires npc_master priv)", -- 9 | ||||
| 	"take item from player and destroy it (requires npc_master priv)", -- 10 | ||||
| 	"move the player to a given position (requires npc_master priv)", -- 11 | ||||
| 	"give item (created out of thin air) to player (requires ".. | ||||
| 		tostring(yl_speak_up.npc_privs_priv).." priv)", -- 9 | ||||
| 	"take item from player and destroy it (requires ".. | ||||
| 		tostring(yl_speak_up.npc_privs_priv).." priv)", -- 10 | ||||
| 	"move the player to a given position (requires ".. | ||||
| 		tostring(yl_speak_up.npc_privs_priv).." priv)", -- 11 | ||||
| 	"execute Lua code (requires npc_master priv)", -- 12 | ||||
| } | ||||
| 
 | ||||
| @ -102,8 +105,10 @@ local values_what = {"", "state", | ||||
| 	"deal_with_offered_item", | ||||
| 	-- crafting, handling failure, send chat message to all | ||||
| 	"craft", "on_failure", "chat_all", | ||||
| 	-- the following require the yl_speak_up.npc_privs_priv priv: | ||||
| 	"give_item", "take_item", "move", | ||||
| 	-- the following require the npc_master priv: | ||||
| 	"give_item", "take_item", "move", "function", | ||||
| 	"function", | ||||
| 	} | ||||
| 
 | ||||
| -- unlike in the preconditions, the "I cannot punch it" option is | ||||
|  | ||||
| @ -88,6 +88,23 @@ yl_speak_up.delete_element_p_or_a_or_e = function( | ||||
| end | ||||
| 
 | ||||
| 
 | ||||
| -- helper function for yl_speak_up.save_element_p_or_a_or_e | ||||
| yl_speak_up.save_element_check_priv = function(player, priv_name, formspec_input_to, explanation) | ||||
| 	local priv_list = {} | ||||
| 	priv_list[priv_name] = true | ||||
| 	if(not(minetest.check_player_privs(player, priv_list))) then | ||||
| 		yl_speak_up.show_fs(player, "msg", { | ||||
| 			input_to = "yl_speak_up:"..formspec_input_to, | ||||
| 			formspec = "size[9,2]".. | ||||
| 				"label[0.2,0.5;Error: You need the \"".. | ||||
| 					tostring(priv_name).."\" priv".. | ||||
| 					tostring(explanation)..".]".. | ||||
| 				"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"}) | ||||
| 		return false | ||||
| 	end | ||||
| 	return true | ||||
| end | ||||
| 
 | ||||
| -- helper function for yl_speak_up.input_fs_edit_option_related | ||||
| yl_speak_up.save_element_p_or_a_or_e = function( | ||||
| 			player, pname, n_id, d_id, o_id, x_id, id_prefix, tmp_data_cache, | ||||
| @ -288,8 +305,8 @@ yl_speak_up.save_element_p_or_a_or_e = function( | ||||
| 			v[ id_prefix.."pos" ] = {x = data.block_pos.x, y = data.block_pos.y, z = data.block_pos.z } | ||||
| 		end | ||||
| 
 | ||||
| 	-- "give item (created out of thin air) to player (requires npc_master priv)", -- 9 | ||||
| 	-- "take item from player and destroy it (requires npc_master priv)", -- 10 | ||||
| 	-- "give item (created out of thin air) to player (requires yl_speak_up.npc_privs_priv priv)", -- 9 | ||||
| 	-- "take item from player and destroy it (requires yl_speak_up.npc_privs_priv priv)", -- 10 | ||||
| 	elseif(id_prefix == "r_" and (what_type == "give_item" or what_type == "take_item")) then | ||||
| 		if(not(data.inv_stack_name) or data.inv_stack_name == "") then | ||||
| 			yl_speak_up.show_fs(player, "msg", { | ||||
| @ -300,19 +317,15 @@ yl_speak_up.save_element_p_or_a_or_e = function( | ||||
| 					"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"}) | ||||
| 			return | ||||
| 		end | ||||
| 		if(not(minetest.check_player_privs(player, {npc_master=true}))) then | ||||
| 			yl_speak_up.show_fs(player, "msg", { | ||||
| 				input_to = "yl_speak_up:"..formspec_input_to, | ||||
| 				formspec = "size[9,2]".. | ||||
| 					"label[0.2,0.5;Error: You need the \"npc_master\" priv ".. | ||||
| 						" in order to set this effect.]".. | ||||
| 					"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"}) | ||||
| 		local priv_list = {} | ||||
| 		if(not(yl_speak_up.save_element_check_priv(player, yl_speak_up.npc_privs_priv, | ||||
| 				formspec_input_to, " in order to set this effect"))) then | ||||
| 			return | ||||
| 		end | ||||
| 		v[ "r_value" ] = data.inv_stack_name | ||||
| 
 | ||||
| 
 | ||||
| 	-- "move the player to a given position (requires npc_master priv)", -- 11 | ||||
| 	-- "move the player to a given position (requires yl_speak_up.npc_privs_priv priv)", -- 11 | ||||
| 	elseif(what_type == "move" and id_prefix == "r_") then | ||||
| 		if(not(data.move_to_x) or not(data.move_to_y) or not(data.move_to_z)) then | ||||
| 			yl_speak_up.show_fs(player, "msg", { | ||||
| @ -323,13 +336,8 @@ yl_speak_up.save_element_p_or_a_or_e = function( | ||||
| 					"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"}) | ||||
| 			return | ||||
| 		end | ||||
| 		if(not(minetest.check_player_privs(player, {npc_master=true}))) then | ||||
| 			yl_speak_up.show_fs(player, "msg", { | ||||
| 				input_to = "yl_speak_up:"..formspec_input_to, | ||||
| 				formspec = "size[9,2]".. | ||||
| 					"label[0.2,0.5;Error: You need the \"npc_master\" priv ".. | ||||
| 						" in order to set this effect.]".. | ||||
| 					"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"}) | ||||
| 		if(not(yl_speak_up.save_element_check_priv(player, yl_speak_up.npc_privs_priv, | ||||
| 				formspec_input_to, " in order to set this effect"))) then | ||||
| 			return | ||||
| 		end | ||||
| 		v[ "r_value" ] = minetest.pos_to_string( | ||||
| @ -347,13 +355,8 @@ yl_speak_up.save_element_p_or_a_or_e = function( | ||||
| 					"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"}) | ||||
| 			return | ||||
| 		end | ||||
| 		if(not(minetest.check_player_privs(player, {npc_master=true}))) then | ||||
| 			yl_speak_up.show_fs(player, "msg", { | ||||
| 				input_to = "yl_speak_up:"..formspec_input_to, | ||||
| 				formspec = "size[9,2]".. | ||||
| 					"label[0.2,0.5;Error: You need the \"npc_master\" priv ".. | ||||
| 						" in order to set this.]".. | ||||
| 					"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"}) | ||||
| 		if(not(yl_speak_up.save_element_check_priv(player, "npc_master", | ||||
| 				formspec_input_to, " in order to set this"))) then | ||||
| 			return | ||||
| 		end | ||||
| 		v[ id_prefix.."value" ] = data.lua_code | ||||
| @ -759,8 +762,8 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields, | ||||
| 	  and data and data.what | ||||
| 	  and ((id_prefix == "p_" | ||||
| 	        and (what_type == "player_inv" or what_type == "npc_inv" or what_type == "block_inv")) | ||||
| 	    -- "give item (created out of thin air) to player (requires npc_master priv)", -- 9 | ||||
| 	    -- "take item from player and destroy it (requires npc_master priv)", -- 10 | ||||
| 	    -- "give item (created out of thin air) to player (requires yl_speak_up.npc_privs_priv priv)", -- 9 | ||||
| 	    -- "take item from player and destroy it (requires yl_speak_up.npc_privs_priv priv)", -- 10 | ||||
| 	    or (id_prefix == "r_" | ||||
| 	        and (what_type == "give_item" or what_type == "take_item" | ||||
| 		  or what_type == "put_into_block_inv" or what_type == "take_from_block_inv")))) then | ||||
| @ -878,7 +881,7 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields, | ||||
| 		was_changed = true | ||||
| 	end | ||||
| 
 | ||||
| 	-- "move the player to a given position (requires npc_master priv)", -- 11 | ||||
| 	-- "move the player to a given position (requires yl_speak_up.npc_privs_priv priv)", -- 11 | ||||
| 	if(fields.move_to_x or fields.move_to_y or fields.move_to_z) then | ||||
| 		local dimension = {"x","y","z"} | ||||
| 		for i, dim in ipairs(dimension) do | ||||
| @ -1397,13 +1400,13 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, | ||||
| 		return yl_speak_up.get_fs_edit_option_effect_deal_with_offered_item( | ||||
| 				pname, dialog, formspec, data, id_prefix, save_button, e) | ||||
| 
 | ||||
| 	-- "give item (created out of thin air) to player (requires npc_master priv)", -- 9 | ||||
| 	-- "take item from player and destroy it (requires npc_master priv)", -- 10 | ||||
| 	-- "give item (created out of thin air) to player (requires yl_speak_up.npc_privs_priv priv)", -- 9 | ||||
| 	-- "take item from player and destroy it (requires yl_speak_up.npc_privs_priv priv)", -- 10 | ||||
| 	elseif(data.what and id_prefix == "r_" and (what_type == "give_item" or what_type=="take_item")) then | ||||
| 		return yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item( | ||||
| 				pname, dialog, formspec, data, id_prefix, save_button, e) | ||||
| 
 | ||||
| 	-- "move the player to a given position (requires npc_master priv)", -- 11 | ||||
| 	-- "move the player to a given position (requires yl_speak_up.npc_privs_priv priv)", -- 11 | ||||
| 	elseif(data.what and id_prefix == "r_" and what_type == "move") then | ||||
| 		return yl_speak_up.get_fs_edit_option_effect_move( | ||||
| 				pname, dialog, formspec, data, id_prefix, save_button, e) | ||||
| @ -1593,7 +1596,7 @@ yl_speak_up.get_fs_edit_option_p_and_e_property = function( | ||||
| 			"<b>Note:</b> Properties are useful for NPC that have a generic ".. | ||||
| 			"behaviour and may vary their behaviour slightly.\n".. | ||||
| 			"Properties starting with \"server\" can only be set or changed by ".. | ||||
| 			"players with the \"npc_master\" privilege.".. | ||||
| 			"players with the \"npc_talk_admin\" privilege.".. | ||||
| 			"</normal>]" | ||||
| end | ||||
| 
 | ||||
| @ -1947,8 +1950,8 @@ yl_speak_up.get_fs_edit_option_effect_deal_with_offered_item = function( | ||||
| end | ||||
| 
 | ||||
| 
 | ||||
| -- "give item (created out of thin air) to player (requires npc_master priv)", -- 9 | ||||
| -- "take item from player and destroy it (requires npc_master priv)", -- 10 | ||||
| -- "give item (created out of thin air) to player (requires yl_speak_up.npc_privs_priv priv)", -- 9 | ||||
| -- "take item from player and destroy it (requires yl_speak_up.npc_privs_priv priv)", -- 10 | ||||
| yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item = function( | ||||
| 			pname, dialog, formspec, data, id_prefix, save_button, e) | ||||
| 	if(e) then | ||||
| @ -1965,7 +1968,7 @@ yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item = function( | ||||
| 	return formspec.. | ||||
| 		"label[0.2,3.0;"..text.."]".. | ||||
| 		"label[0.2,3.5;Note: You can *save* this effect only if you have the ".. | ||||
| 			"\"npc_master\" priv!]".. | ||||
| 			"\""..tostring(yl_speak_up.npc_privs_priv).."\" priv!]".. | ||||
| 		"label[0.2,8.0;".. | ||||
| 			"And in order to be able to execute it, this NPC\n".. | ||||
| 			"needs the \""..tostring(priv_name).."\" priv.\n\t".. | ||||
| @ -1976,7 +1979,7 @@ yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item = function( | ||||
| end | ||||
| 
 | ||||
| 
 | ||||
| -- "move the player to a given position (requires npc_master priv)", -- 11 | ||||
| -- "move the player to a given position (requires yl_speak_up.npc_privs_priv priv)", -- 11 | ||||
| yl_speak_up.get_fs_edit_option_effect_move = function( | ||||
| 			pname, dialog, formspec, data, id_prefix, save_button, e) | ||||
| 	if(e) then | ||||
| @ -1992,7 +1995,7 @@ yl_speak_up.get_fs_edit_option_effect_move = function( | ||||
| 	return formspec.. | ||||
| 		"label[0.2,3.0;Move the player to this position:]".. | ||||
| 		"label[0.2,3.5;Note: You can *save* this effect only if you have the ".. | ||||
| 			"\"npc_master\" priv!\n".. | ||||
| 			"\""..tostring(yl_speak_up.npc_privs_priv).."\" priv!\n".. | ||||
| 			"And in order to be able to execute it, this NPC needs the \"".. | ||||
| 			"effect_move_player\" priv.\n\t".. | ||||
| 			"Type \"/npc_talk_privs grant "..tostring(yl_speak_up.speak_to[pname].n_id).. | ||||
|  | ||||
| @ -86,7 +86,7 @@ yl_speak_up.set_npc_property = function(pname, property_name, property_value, re | ||||
| 		return "Properties of the type \"self.\" cannot be modified." | ||||
| 	end | ||||
| 	-- properites starting with "server" can only be changed or added manually by | ||||
| 	-- players with the npc_master priv | ||||
| 	-- players with the npc_talk_admin priv | ||||
| 	if(string.sub(property_name, 1, 6) == "server") then | ||||
| 		if(not(reason) or reason ~= "manually" or not(pname) | ||||
| 		  or not(minetest.check_player_privs(pname, {npc_talk_admin=true}))) then | ||||
|  | ||||
| @ -108,7 +108,7 @@ yl_speak_up.input_talk = function(player, formname, fields) | ||||
| 	if fields.button_start_edit_mode then | ||||
| 		-- check if this particular NPC is really owned by this player or if the player has global privs | ||||
| 		if(not(yl_speak_up.may_edit_npc(player, n_id))) then | ||||
| 			minetest.chat_send_player(pname, "Sorry. You do not have the npc_talk_owner or npc_master priv.") | ||||
| 			minetest.chat_send_player(pname, "Sorry. You do not have the npc_talk_owner or npc_talk_master priv.") | ||||
| 			return | ||||
| 		end | ||||
| 		-- the staff allows to create multiple target dialogs as result; this makes no sense | ||||
| @ -662,7 +662,7 @@ yl_speak_up.get_fs_talkdialog_add_edit_buttons = function( | ||||
| 		text, text, | ||||
| 		true, nil, nil, pname_for_old_fs) | ||||
| 	-- Offer to enter edit mode if the player has the npc_talk_owner priv OR is allowed to edit the NPC. | ||||
| 	-- The npc_master priv allows to edit all NPC. | ||||
| 	-- The npc_talk_master priv allows to edit all NPC. | ||||
| 	if(not(edit_mode)) then | ||||
| 		h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, | ||||
| 			"button_start_edit_mode", | ||||
|  | ||||
| @ -38,7 +38,7 @@ minetest.register_privilege("npc_talk_master", npc_talk_master_priv_definition) | ||||
| 
 | ||||
| 
 | ||||
| local npc_talk_admin_priv_definition = { | ||||
|     description="Can do maintenance of NPCs (adding generic, adding server_ properties)", | ||||
|     description="Can do maintenance of NPCs (adding generic, adding server_ properties, managing NPC privs)", | ||||
|     give_to_singleplayer = false, | ||||
|     give_to_admin = true, | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user