player names are tabu as NPC names

This commit is contained in:
Sokomine 2021-07-26 01:40:20 +02:00
parent 48482ce23f
commit 2ecab8554e

View File

@ -28,12 +28,20 @@ yl_speak_up.input_fs_initial_config = function(player, formname, fields)
end
local error_msg = nil
-- remove leading and tailing spaces from the potential new NPC name in order to avoid
-- confusing names where a player's name (or that of another NPC) is beginning/ending
-- with blanks
if(fields.n_npc) then
fields.n_npc = fields.n_npc:match("^%s*(.-)%s*$")
end
-- the player is trying to save the initial configuration
-- is the player allowed to initialize this npc?
if(not(yl_speak_up.may_edit_npc(player, n_id))) then
error_msg = "You are not allowed to edit this NPC."
elseif(not(fields.n_npc) or string.len(fields.n_npc) < 2) then
error_msg = "The name of your NPC needs to be\nat least two characters long."
elseif(minetest.check_player_privs(fields.n_npc, {interact=true})) then
error_msg = "You cannot name your NPC\nafter an existing player."
elseif(not(fields.n_description) or string.len(fields.n_description) < 2) then
error_msg = "Please provide a description of your NPC!"
-- sensible length limit