added effect send chat message to all

This commit is contained in:
Sokomine 2021-06-10 17:46:09 +02:00
parent d2e5840886
commit 4e4948923a
2 changed files with 47 additions and 1 deletions

View File

@ -41,10 +41,11 @@ local check_what = {
"a block somewhere", -- 3
"NPC crafts soemthing", -- 4
"go to other dialog if the action (i.e. trade) failed", -- 5
"send a chat message to all players", -- 6
}
-- how to store these as r_type in the precondition:
local values_what = {"", "state", "block", "craft", "on_failure"}
local values_what = {"", "state", "block", "craft", "on_failure", "chat_all"}
-- unlike in the preconditions, the "I cannot punch it" option is
-- not offered here - because the player (and later the NPC) needs
@ -143,6 +144,8 @@ yl_speak_up.show_effect = function(r)
return "Craft \""..tostring(r.r_value).."\" from "..table.concat(r.r_craft_grid, ", ").."."
elseif(r.r_type == "on_failure") then
return "If the action (i.e. trade) failed, go to dialog \""..tostring(r.r_value).. "\"."
elseif(r.r_type == "chat_all") then
return "Send chat message: \""..tostring(r.r_value).."\""
end
-- fallback
return tostring(r.r_value)

View File

@ -101,6 +101,11 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
elseif(fields.var_cmp_value
and data and data.what and data.what == 2) then
data.var_cmp_value = fields.var_cmp_value
-- text for a chat message
elseif(fields.chat_msg_text
and data and data.what and data.what == 6 and id_prefix == "r_") then
data.chat_msg_text = fields.chat_msg_text
end
-- the save button was pressed
@ -216,6 +221,28 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
-- (only for effects; not for preconditions)
elseif(data.what and id_prefix == "r_" and data.what == 5) then
v[ "r_value" ] = data.on_failure
-- "send a chat message to all players", -- 6
-- (only for effects; not for preconditions)
elseif(data.what and id_prefix == "r_" and data.what == 6) then
data.chat_msg_text = fields.chat_msg_text
-- allow saving only if the placeholders are all present
-- (reason for requiring them: players and server owners ought to
-- be able to see who is responsible for a message)
if(not(string.find(data.chat_msg_text, "%$NPC_NAME%$"))
or not(string.find(data.chat_msg_text, "%$PLAYER_NAME%$"))
or not(string.find(data.chat_msg_text, "%$OWNER_NAME%$"))) then
yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:"..formspec_input_to,
formspec = "size[9,2.5]"..
"label[0.2,0.5;Error: Your chat message needs to contain "..
"the following\nplaceholders: $NPC_NAME$, "..
"$PLAYER_NAME$ and $OWNER_NAME$.\nThat way, other "..
"players will know who sent the message.]"..
"button[1.5,2.0;2,0.9;back_from_error_msg;Back]"})
return
end
v[ "r_value" ] = data.chat_msg_text
end
-- only save if something was actually selected
@ -578,6 +605,22 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
"dropdown[5.0,3.5;6.5,0.6;select_on_failure;"..
table.concat(sorted_dialog_list, ",")..";"..
tostring(nr)..";]"
-- "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$ "..
"- example; please enter the text -"
if(data and data.chat_msg_text) then
text = data.chat_msg_text
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)).."]"..
"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$.]"
end
return formspec..save_button