forked from Sokomine/yl_speak_up
		
	allow to set owner if player has npc_master priv; allow to edit own npc with npc_talk_owner priv
This commit is contained in:
		
							parent
							
								
									3b90b1bb5d
								
							
						
					
					
						commit
						20f3b3c831
					
				| @ -1,12 +1,12 @@ | ||||
| -- TODO: just for the apple quest...needs to be deleted later on | ||||
| yl_sokomine = {} | ||||
| yl_sokomine["q_apple_explorer"] = {} | ||||
| -- if player has npc_talk_owner priv AND is owner of this particular npc (second one: TODO): | ||||
| -- if player has npc_talk_owner priv AND is owner of this particular npc: | ||||
| --   chat option: "I am your owner. I have new orders for you. | ||||
| --   -> enters edit mode | ||||
| -- when edit_mode has been enabled, the following chat options are added to the options: | ||||
| --   chat option: "Add new answer/option to this dialog." | ||||
| --   -> adds a new option TODO | ||||
| --   -> adds a new aswer/option | ||||
| --   chat option: "That was all. I'm finished with giving you new orders. Remember them!" | ||||
| --   -> ends edit mode | ||||
| -- | ||||
| @ -26,7 +26,7 @@ yl_sokomine["q_apple_explorer"] = {} | ||||
| --        [Store]  [Delete this option] [Back to dialog xyz] [GOTO target diaglog] | ||||
| -- | ||||
| -- TODO: check if security is ok (minetest.formspec_escape etc) | ||||
| -- TODO: actually process changed entries | ||||
| -- TODO: actually store changed entries | ||||
| -- TODO: allow owner to mute/unmute npc (would be bad if players can already see what is going | ||||
| --       to happen while the owner creates a long quest) | ||||
| 
 | ||||
| @ -41,6 +41,12 @@ yl_speak_up.edit_mode = {} | ||||
| -- (this gives the players a chance to back off in case of unwanted changes) | ||||
| yl_speak_up.npc_was_changed = {} | ||||
| 
 | ||||
| -- self (the npc as such) is rarely passed on to any functions; in order to be able to check if | ||||
| -- the player really owns the npc, we need to have that data available; | ||||
| -- format: yl_speak_up.npc_owner[ npc_id ] = owner_name | ||||
| yl_speak_up.npc_owner = {} | ||||
| 
 | ||||
| 
 | ||||
| function yl_speak_up.init_mob_table() | ||||
|     return false | ||||
| end | ||||
| @ -228,6 +234,8 @@ local function fields_to_dialog(pname, fields) | ||||
|     dialog.n_description = fields.n_description | ||||
|     dialog.n_npc = fields.n_npc | ||||
| 
 | ||||
|     dialog.npc_owner = fields.npc_owner | ||||
| 
 | ||||
|     return dialog | ||||
| end | ||||
| 
 | ||||
| @ -571,7 +579,7 @@ local function get_fs_setdialog(clicker, n_id, d_id) | ||||
|         "label[0.2,0.35;", | ||||
|         dialog.n_id, | ||||
|         "]", | ||||
|         "field[1,0.1;4,0.5;n_npc;;", | ||||
|         "field[1.3,0.1;3.7,0.5;n_npc;;", | ||||
|         dialog.n_npc, | ||||
|         "]", | ||||
|         "field[5.2,0.1;8,0.5;n_description;;", | ||||
| @ -582,8 +590,13 @@ local function get_fs_setdialog(clicker, n_id, d_id) | ||||
|         ";", | ||||
|         count, | ||||
|         "]", | ||||
|         "label[0.2,1;Sort]", | ||||
|         "field[1.0,0.75;4,0.5;d_sort;;", | ||||
| 	-- allow to change the owner of the npc | ||||
|         "label[0.2,1;Owner]", | ||||
|         "field[1.3,0.75;3.7,0.5;npc_owner;;", | ||||
| 	(yl_speak_up.npc_owner[ n_id ] or "- nobody -"), | ||||
|         "]", | ||||
|         "label[10.9,1;Sort]", | ||||
|         "field[11.7,0.75;1.5,0.5;d_sort;;", | ||||
|         d_sort, | ||||
|         "]", | ||||
|         "textarea[0.2,1.6;13,6;d_text;;", | ||||
| @ -595,6 +608,7 @@ local function get_fs_setdialog(clicker, n_id, d_id) | ||||
|         "button[10.2,7.7;3,0.75;button_save;Save]", | ||||
|         -- tooltips | ||||
| 
 | ||||
|         "tooltip[npc_owner;npc_owner: The name of the owner of the NPC - who can edit dialogs of this NPC if he has the npc_talk_owner priv;#FFFFFF;#000000]", | ||||
|         "tooltip[n_npc;n_npc: The name of the NPC;#FFFFFF;#000000]", | ||||
|         "tooltip[n_description;n_description: A description for the NPC;#FFFFFF;#000000]", | ||||
|         "tooltip[d_sort;d_sort: Make this 0 on your dialog if you want it to be shown the first time a player talks to the NPC\nNegative values are ignored\n;#FFFFFF;#000000]", | ||||
| @ -1213,8 +1227,8 @@ local function get_fs_talkdialog(player, n_id, d_id) | ||||
| 
 | ||||
|         -- Offer to enter edit mode if the player has the npc_talk_owner priv AND owns the npc. | ||||
| 	-- The npc_master priv allows to edit all NPC. | ||||
| 	-- TODO: the player also has to be owner of that particular npc | ||||
|         elseif((minetest.check_player_privs(player, {npc_talk_owner=true})) | ||||
|         elseif((yl_speak_up.npc_owner[ n_id ] == pname | ||||
| 	    and minetest.check_player_privs(player, {npc_talk_owner=true})) | ||||
|             or (minetest.check_player_privs(player, {npc_master=true}))) then | ||||
|             -- chat option: "I am your owner. I have new orders for you. | ||||
|             h = h + 1 | ||||
| @ -1632,6 +1646,7 @@ minetest.register_on_player_receive_fields( | ||||
|                 if ent ~= nil then | ||||
|                     ent.yl_speak_up.npc_name = dialog.n_npc | ||||
|                     ent.yl_speak_up.npc_description = dialog.n_description | ||||
| 	            ent.owner = dialog.npc_owner | ||||
|                      | ||||
|                     local i_text = dialog.n_npc .. "\n" .. dialog.n_description .. "\n" .. yl_speak_up.infotext | ||||
|                     obj:set_properties({infotext = i_text}) | ||||
| @ -1831,12 +1846,13 @@ minetest.register_on_player_receive_fields( | ||||
| 
 | ||||
| 	-- start edit mode (requires npc_talk_owner) | ||||
| 	if fields.button_start_edit_mode then | ||||
|             if(  not(minetest.check_player_privs(player, {npc_talk_owner=true})) | ||||
| 	    -- check if this particular NPC is really owned by this player or if the player has global privs | ||||
|             if(not(yl_speak_up.npc_owner[ yl_speak_up.speak_to[pname].n_id ] == pname | ||||
| 	         and minetest.check_player_privs(player, {npc_talk_owner=true})) | ||||
|              and not(minetest.check_player_privs(player, {npc_master=true}))) then | ||||
|                 minetest.chat_send_player(pname, "Sorry. You do not have the npc_talk_owner or npc_master priv.") | ||||
|                 return | ||||
| 	    end | ||||
| 	    -- TODO: check if this particular NPC is really owned by this player | ||||
| 	    -- enter edit mode with that particular NPC | ||||
|             yl_speak_up.edit_mode[pname] = yl_speak_up.speak_to[pname].n_id | ||||
| 	    -- start a new chat - but this time in edit mode | ||||
| @ -2096,6 +2112,9 @@ function yl_speak_up.config(clicker, npc) | ||||
|     yl_speak_up.speak_to[pname].dialog = load_dialog(n_id) -- Load the dialog and see what we can do with it | ||||
|     yl_speak_up.speak_to[pname].obj = npc | ||||
| 
 | ||||
|     -- find out who owns the npc while we still have easy access to the luaentity | ||||
|     yl_speak_up.npc_owner[ n_id ] = npc:get_luaentity().owner | ||||
| 
 | ||||
|     minetest.show_formspec( | ||||
|         pname, | ||||
|         "yl_speak_up:setdialog", | ||||
| @ -2224,6 +2243,9 @@ function yl_speak_up.talk(self, clicker) | ||||
|     yl_speak_up.speak_to[pname].option_index = 1 | ||||
|     yl_speak_up.speak_to[pname].obj = self.object | ||||
| 
 | ||||
|     -- remember whom the npc belongs to (as long as we still have self.owner available for easy access) | ||||
|     yl_speak_up.npc_owner[ n_id ] = self.owner | ||||
| 
 | ||||
|     minetest.show_formspec(pname, "yl_speak_up:talk", get_fs_talkdialog(clicker, n_id)) | ||||
| end | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user