diff --git a/fs_edit_effects.lua b/fs_edit_effects.lua index 5c6ae95..cdba30d 100644 --- a/fs_edit_effects.lua +++ b/fs_edit_effects.lua @@ -30,6 +30,9 @@ -- chat_all: -- r_value chat message sent to all players -- +-- +-- give_item, take_item, move, function: requires npc_master priv +-- -- Unlike in preconditions, trade (the trade action already happened) and -- inventory actions are not supported as effects. -- @@ -47,12 +50,13 @@ local check_what = { "send a chat message to all players", -- 6 "give item (created out of thin air) to player (requires npc_master priv)", -- 7 "take item from player and destroy it (requires npc_master priv)", -- 8 + "move the player to a given position (requires npc_master priv)", -- 9 } -- how to store these as r_type in the precondition: local values_what = {"", "state", "block", "craft", "on_failure", "chat_all", -- the following require the npc_master priv: - "give_item", "take_item"} + "give_item", "take_item", "move"} -- unlike in the preconditions, the "I cannot punch it" option is -- not offered here - because the player (and later the NPC) needs diff --git a/fs_edit_general.lua b/fs_edit_general.lua index 367d389..7e8fc53 100644 --- a/fs_edit_general.lua +++ b/fs_edit_general.lua @@ -334,6 +334,28 @@ 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)", -- 9 + 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 + local text = fields["move_to_"..dim] + if(text and text ~= "") then + local val = tonumber(text) + if(not(val) or val < -32000 or val > 32000) 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: The coordinate values have ".. + "be in the range of -32000..32000.]".. + "button[1.5,1.5;2,0.9;back_from_error_msg;Back]"}) + return + else + data[ "move_to_"..dim ] = val + end + end + end + end + -- the save button was pressed if(fields.save_element and data and data.what and values_what[ data.what ]) then -- for creating the new prerequirement; normal elements: p_type, p_value, p_id @@ -465,6 +487,31 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields, end v[ "r_value" ] = data.inv_stack_name + + -- "move the player to a given position (requires npc_master priv)", -- 9 + elseif(data.what and id_prefix == "r_" and data.what == 9) 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", { + input_to = "yl_speak_up:"..formspec_input_to, + formspec = "size[9,2]".. + "label[0.2,0.5;Error: Please provide valid coordinates ".. + " x, y and z!]".. + "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]"}) + return + end + v[ "r_value" ] = minetest.pos_to_string( + {x = data.move_to_x, y = data.move_to_y, z = data.move_to_z}) + + -- "NPC crafts something", -- 4 -- (only for effects; not for preconditions) elseif(data.what and id_prefix == "r_" and data.what == 4) then @@ -1014,6 +1061,21 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs) data.action_failure_dialog = math.max(1, table.indexof(sorted_dialog_list, e[ "a_on_failure" ])) + + -- give_item/take_item + elseif(data.what and id_prefix == "r_" and data.what >= 7 and data.what <= 8) then + data.inv_stack_name = e[ "r_value" ] or "" + + -- move + elseif(data.what and id_prefix == "r_" and data.what == 9) then + if(e[ "r_value"] and type(e[ "r_value" ]) == "string") then + local pos = minetest.string_to_pos(e[ "r_value" ]) + if(pos) then + data.move_to_x = pos.x + data.move_to_y = pos.y + data.move_to_z = pos.z + end + end end -- write that data back yl_speak_up.speak_to[pname][ tmp_data_cache ] = data @@ -1228,6 +1290,19 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, "label[8,4.9;Your inventory:]".. "list[current_player;main;8,5.3;8,4;]" + -- "move the player to a given position (requires npc_master priv)", -- 9 + elseif(data.what and id_prefix == "r_" and data.what == 9) then + formspec = 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!]".. + "label[0.2,5.3;X:]".. + "label[3.7,5.3;Y:]".. + "label[7.2,5.3;Z:]".. + "field[0.7,5.0;2.0,0.6;move_to_x;;"..(data.move_to_x or "").."]".. + "field[4.2,5.0;2.0,0.6;move_to_y;;"..(data.move_to_y or "").."]".. + "field[7.7,5.0;2.0,0.6;move_to_z;;"..(data.move_to_z or "").."]" + -- "NPC crafts something", -- 4 -- (craft - only for effects - not for preconditions) elseif(data.what and id_prefix == "r_" and data.what == 4) then