forked from Sokomine/yl_speak_up
added give_item and take_item (editable with npc_master)
This commit is contained in:
parent
71873b7a52
commit
e47680fd7d
@ -45,10 +45,14 @@ local check_what = {
|
||||
"NPC crafts something", -- 4
|
||||
"go to other dialog if the previous effect failed", -- 5
|
||||
"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
|
||||
}
|
||||
|
||||
-- how to store these as r_type in the precondition:
|
||||
local values_what = {"", "state", "block", "craft", "on_failure", "chat_all"}
|
||||
local values_what = {"", "state", "block", "craft", "on_failure", "chat_all",
|
||||
-- the following require the npc_master priv:
|
||||
"give_item", "take_item"}
|
||||
|
||||
-- unlike in the preconditions, the "I cannot punch it" option is
|
||||
-- not offered here - because the player (and later the NPC) needs
|
||||
|
@ -233,8 +233,11 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
|
||||
local data = yl_speak_up.speak_to[pname][ tmp_data_cache ]
|
||||
if(((fields.inv_stack_name and fields.inv_stack_name ~= "")
|
||||
or (fields.store_item_name and fields.store_item_name ~= ""))
|
||||
and id_prefix == "p_"
|
||||
and data and data.what and data.what >= 5 and data.what <= 6) then
|
||||
and data and data.what
|
||||
and ((id_prefix == "p_" and data.what >= 5 and data.what <= 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
|
||||
or (id_prefix == "r_" and data.what >= 7 and data.what <= 8))) then
|
||||
local wanted = ""
|
||||
local wanted_name = ""
|
||||
if(not(fields.store_item_name)) then
|
||||
@ -439,6 +442,29 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
|
||||
v[ "p_itemstack" ] = data.inv_stack_name
|
||||
end
|
||||
|
||||
-- "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
|
||||
elseif(data.what and id_prefix == "r_" and (data.what == 7 or data.what == 8)) then
|
||||
if(not(data.inv_stack_name) or data.inv_stack_name == "") then
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = "yl_speak_up:"..formspec_input_to,
|
||||
formspec = "size[8,2]"..
|
||||
"label[0.2,0.5;Error: Please provide the name of the "..
|
||||
"\nitem you want to give or take!]"..
|
||||
"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" ] = data.inv_stack_name
|
||||
|
||||
-- "NPC crafts something", -- 4
|
||||
-- (only for effects; not for preconditions)
|
||||
elseif(data.what and id_prefix == "r_" and data.what == 4) then
|
||||
@ -1178,6 +1204,30 @@ 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;]"
|
||||
|
||||
-- "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
|
||||
elseif(data.what and id_prefix == "r_" and (data.what == 7 or data.what == 8)) then
|
||||
local text = "The following item shall be created out of thin air and added to the "..
|
||||
"player's inventory:"
|
||||
if(data.what == 8) then
|
||||
text = "The following item shall be removed from the player's inventory and "..
|
||||
"be destroyed:"
|
||||
end
|
||||
formspec = formspec..
|
||||
"label[0.2,3.0;"..text.."]"..
|
||||
"label[0.2,3.5;Note: You can *save* this effect only if you have the "..
|
||||
"\"npc_master\" priv!]"..
|
||||
"label[0.2,4.2;Name of the item(stack):]"..
|
||||
"field[4.0,4.0;16.0,0.6;inv_stack_name;;"..(data.inv_stack_name or "").."]"..
|
||||
"tooltip[inv_stack_name;Enter name of the block and amount.\n"..
|
||||
"Example: \"default:apple 3\" for three apples,\n"..
|
||||
" \"farming:bread\" for a bread.]"..
|
||||
"label[0.2,5.7;Or put the item in here\nand click on \"Store\":]"..
|
||||
"button[5.5,5.5;1.5,0.9;store_item_name;Store]"..
|
||||
"list[detached:yl_speak_up_player_"..pname..";npc_wants;4.0,5.5;1,1;]"..
|
||||
"label[8,4.9;Your inventory:]"..
|
||||
"list[current_player;main;8,5.3;8,4;]"
|
||||
|
||||
-- "NPC crafts something", -- 4
|
||||
-- (craft - only for effects - not for preconditions)
|
||||
elseif(data.what and id_prefix == "r_" and data.what == 4) then
|
||||
|
Loading…
Reference in New Issue
Block a user