forked from Sokomine/yl_speak_up
allow to change owner in fs_initial_config.lua
This commit is contained in:
parent
5409e1fa04
commit
062699b1da
@ -39,6 +39,15 @@ yl_speak_up.input_fs_initial_config = function(player, formname, fields)
|
|||||||
-- sensible length limit
|
-- sensible length limit
|
||||||
elseif(string.len(fields.n_npc)>40 or string.len(fields.n_description)>40) then
|
elseif(string.len(fields.n_npc)>40 or string.len(fields.n_description)>40) then
|
||||||
error_msg = "The name and description of your NPC\ncannot be longer than 40 characters."
|
error_msg = "The name and description of your NPC\ncannot be longer than 40 characters."
|
||||||
|
-- want to change the owner?
|
||||||
|
elseif(fields.n_owner and fields.n_owner ~= yl_speak_up.npc_owner[ n_id ]) then
|
||||||
|
if( not(minetest.check_player_privs(player, {npc_talk_master=true}))) then
|
||||||
|
error_msg = "You need the \"npc_talk_master\" priv\nin order to change the owner."
|
||||||
|
elseif(not(minetest.check_player_privs(fields.n_owner, {npc_talk_owner=true}))) then
|
||||||
|
error_msg = "The NPC can only be owned by players that\n"..
|
||||||
|
"have the \"npc_talk_owner\" priv. Else the\n"..
|
||||||
|
"new owner could not edit his own NPC."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if(error_msg) then
|
if(error_msg) then
|
||||||
yl_speak_up.show_fs(player, "msg", { input_to = "yl_speak_up:initial_config",
|
yl_speak_up.show_fs(player, "msg", { input_to = "yl_speak_up:initial_config",
|
||||||
@ -57,6 +66,17 @@ yl_speak_up.input_fs_initial_config = function(player, formname, fields)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- we checked earlier if the player doing this change and the
|
||||||
|
-- player getting the NPC have appropriate privs
|
||||||
|
if(fields.n_owner ~= yl_speak_up.npc_owner[ n_id ]) then
|
||||||
|
yl_speak_up.log_change(pname, n_id,
|
||||||
|
"Owner changed from "..tostring(yl_speak_up.npc_owner[ n_id ])..
|
||||||
|
" to "..tostring(fields.n_owner).." for "..
|
||||||
|
"NPC name: \""..tostring(fields.n_npc))
|
||||||
|
yl_speak_up.npc_owner[ n_id ] = fields.n_owner
|
||||||
|
end
|
||||||
|
|
||||||
-- give the NPC its first dialog
|
-- give the NPC its first dialog
|
||||||
if(not(dialog) or count==0) then
|
if(not(dialog) or count==0) then
|
||||||
local f = {}
|
local f = {}
|
||||||
@ -91,6 +111,7 @@ yl_speak_up.input_fs_initial_config = function(player, formname, fields)
|
|||||||
"NPC name: \""..tostring(fields.n_npc)..
|
"NPC name: \""..tostring(fields.n_npc)..
|
||||||
"\" Description: \""..tostring(fields.n_description).."\"")
|
"\" Description: \""..tostring(fields.n_description).."\"")
|
||||||
end
|
end
|
||||||
|
|
||||||
dialog = yl_speak_up.speak_to[pname].dialog
|
dialog = yl_speak_up.speak_to[pname].dialog
|
||||||
|
|
||||||
-- show nametag etc.
|
-- show nametag etc.
|
||||||
@ -128,14 +149,15 @@ yl_speak_up.get_fs_initial_config = function(player, n_id, d_id, is_initial_conf
|
|||||||
local tmp_name = n_id
|
local tmp_name = n_id
|
||||||
local tmp_descr = "A new NPC without description"
|
local tmp_descr = "A new NPC without description"
|
||||||
local tmp_text = "Please provide your new NPC with a name and description!"
|
local tmp_text = "Please provide your new NPC with a name and description!"
|
||||||
|
local tmp_owner = (yl_speak_up.npc_owner[ n_id ] or "- none -")
|
||||||
-- use existing name and description as presets when just editing
|
-- use existing name and description as presets when just editing
|
||||||
if(not(is_initial_config)) then
|
if(not(is_initial_config)) then
|
||||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||||
tmp_name = dialog.n_npc
|
tmp_name = (dialog.n_npc or tmp_name)
|
||||||
tmp_descr = dialog.n_description
|
tmp_descr = (dialog.n_description or tmp_descr)
|
||||||
tmp_text = "You can change the name and description of your NPC."
|
tmp_text = "You can change the name and description of your NPC."
|
||||||
end
|
end
|
||||||
local formspec = "size[10,4]"..
|
local formspec = "size[10,5]"..
|
||||||
"label[0.2,0.2;"..tmp_text.."]"..
|
"label[0.2,0.2;"..tmp_text.."]"..
|
||||||
-- name of the npc
|
-- name of the npc
|
||||||
"label[0.2,1.05;Name:]"..
|
"label[0.2,1.05;Name:]"..
|
||||||
@ -145,9 +167,14 @@ yl_speak_up.get_fs_initial_config = function(player, n_id, d_id, is_initial_conf
|
|||||||
"label[0.2,2.05;Description:]"..
|
"label[0.2,2.05;Description:]"..
|
||||||
"field[2.0,2.2;8,0.9;n_description;;"..minetest.formspec_escape(tmp_descr).."]"..
|
"field[2.0,2.2;8,0.9;n_description;;"..minetest.formspec_escape(tmp_descr).."]"..
|
||||||
"tooltip[n_description;n_description: A description for the NPC;#FFFFFF;#000000]"..
|
"tooltip[n_description;n_description: A description for the NPC;#FFFFFF;#000000]"..
|
||||||
|
-- the owner of the NPC
|
||||||
|
"label[0.2,3.05;Owner:]"..
|
||||||
|
"field[2.0,3.2;8,0.9;n_owner;;"..minetest.formspec_escape(tmp_owner).."]"..
|
||||||
|
"tooltip[n_owner;The owner of the NPC. This can only be changed\n"..
|
||||||
|
"if you have the npc_talk_master priv.;#FFFFFF;#000000]"..
|
||||||
-- save and exit buttons
|
-- save and exit buttons
|
||||||
"button_exit[3.2,3.2;2,0.9;save_initial_config;Save]"..
|
"button_exit[3.2,4.2;2,0.9;save_initial_config;Save]"..
|
||||||
"button_exit[5.4,3.2;2,0.9;exit;Exit]"
|
"button_exit[5.4,4.2;2,0.9;exit;Exit]"
|
||||||
-- show the formspec to the player
|
-- show the formspec to the player
|
||||||
return formspec
|
return formspec
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user