allow to use $ in quest items

This commit is contained in:
Sokomine 2021-06-27 18:54:54 +02:00
parent 5edb0da5a7
commit 885c19831e
2 changed files with 24 additions and 17 deletions

View File

@ -57,11 +57,18 @@ yl_speak_up.action_inv_changed = function(inv, listname, index, stack, player, h
return
end
-- "The NPC gives something to the player (i.e. a quest item).", -- 4
if( how == "put" and data.what == 4) then
-- "The player is expected to give something to the NPC (i.e. a quest item).", -- 5
if(how == "put" and (data.what == 4 or data.what == 5)) then
data.item_node_name = stack:get_name().." "..stack:get_count()
local meta = stack:get_meta()
if(meta and meta:get_string("description")) then
data.item_desc = meta:get_string("description")
-- try to reconstruct $PLAYER_NAME$ (may not always work)
local item_was_for = meta:get_string("yl_speak_up:quest_item_for")
local new_desc = meta:get_string("description")
if(item_was_for and item_was_for ~= "") then
new_desc = string.gsub(new_desc, item_was_for, "$PLAYER_NAME$")
end
data.item_desc = new_desc
end
if(meta and meta:get_string("yl_speak_up:quest_id")) then
data.item_quest_id = meta:get_string("yl_speak_up:quest_id")
@ -69,16 +76,6 @@ yl_speak_up.action_inv_changed = function(inv, listname, index, stack, player, h
elseif(how == "take" and data.what == 4) then
data.item_desc = "- no item set -"
data.item_node_name = ""
-- "The player is expected to give something to the NPC (i.e. a quest item).", -- 5
elseif(how == "put" and data.what == 5) then
data.item_node_name = stack:get_name().." "..stack:get_count()
local meta = stack:get_meta()
if(meta and meta:get_string("description")) then
data.item_desc = meta:get_string("description")
end
if(meta and meta:get_string("yl_speak_up:quest_id")) then
data.item_quest_id = meta:get_string("yl_speak_up:quest_id")
end
elseif(how == "take" and data.what == 5) then
data.item_desc = "- no item set -"
data.item_node_name = ""
@ -292,7 +289,9 @@ yl_speak_up.action_quest_item_prepare = function(player)
local meta = new_stack:get_meta()
-- if given: set the item stack description
if(a.a_item_desc and a.a_item_desc ~= "") then
meta:set_string("description", a.a_item_desc)
local dialog = yl_speak_up.speak_to[pname].dialog
-- replace $PLAYER_NAME$ etc. in quest item description
meta:set_string("description", yl_speak_up.replace_vars_in_text(a.a_item_desc, dialog, pname))
end
if(a.a_item_quest_id and a.a_item_quest_id ~= "") then
-- which player got this quest item?

View File

@ -576,7 +576,13 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
-- for displaying as a background image
data.item_string = v[ "a_value" ]
if(data.what == 5) then
data.item_desc = meta:get_string("description")
-- try to reconstruct $PLAYER_NAME$ (may not always work)
local item_was_for = meta:get_string("yl_speak_up:quest_item_for")
local new_desc = meta:get_string("description")
if(item_was_for and item_was_for ~= "") then
new_desc = string.gsub(new_desc, item_was_for, "$PLAYER_NAME$")
end
data.item_desc = new_desc
end
-- set new description if there is one set (optional)
if(data.item_desc
@ -1286,10 +1292,11 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
minetest.formspec_escape(
data.item_node_name
or "- no item set -").."]"..
"label[0.2,6.1;Set a description to turn the item into a special\n"..
"label[0.2,5.6;Set a description to turn the item into a special\n"..
"quest item. Set a special ID (short text) so that\n"..
"the player cannot create a fake item. Click on \n"..
"\"Save\" to apply the changes.]"..
"\"Save\" to apply the changes.\n"..
"You can use placeholders like $PLAYER_NAME$ etc.]"..
"label[0.2,8.3;Special ID to set:]"..
"field[3.2,8.0;14.5,0.6;action_item_quest_id;;"..
minetest.formspec_escape(
@ -1337,7 +1344,8 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
or "- no item set -").."]"..
"label[0.2,6.1;If you want a special ID and description, create\n"..
"those via the \"NPC gives something to the player\"\n"..
"menu option first and insert that item here.]"..
"menu option first and insert that item here. Don't\n"..
"use other placeholders than $PLAYER_NAME$ for this!]"..
"label[0.2,8.3;Expected special ID:]"..
"label[4.0,8.3;"..
minetest.formspec_escape(