mirror of
https://gitea.your-land.de/Sokomine/yl_speak_up.git
synced 2025-06-20 06:08:03 +02:00
only undammaged items are acceptable for trading; the npc only takes undammaged items and those without metadata for his inventory
This commit is contained in:
parent
53496c7369
commit
8f80fd5ade
10
README.md
10
README.md
@ -87,3 +87,13 @@ yl_speak_up.replace_vars_in_text = function(text, dialog, pname)
|
||||
end
|
||||
|
||||
The replacements will not be applied in edit mode.
|
||||
|
||||
|
||||
Trading (simple)
|
||||
================
|
||||
The NPC can trade item(stacks) with other players.
|
||||
Only undammaged items can be traded.
|
||||
Items that contain metadata (i.e. written books, petz, ..) cannot be traded.
|
||||
Dammaged items and items containing metadata cannot be given to the NPC.
|
||||
The trade can be added through the edit options menu when talking to the NPC
|
||||
as owner.
|
||||
|
@ -88,6 +88,31 @@ yl_speak_up.load_npc_inventory = function(n_id)
|
||||
if(not(yl_speak_up.may_edit_npc(player, n_id))) then
|
||||
return 0
|
||||
end
|
||||
if(stack:get_wear() > 0) then
|
||||
minetest.chat_send_player(player:get_player_name(),
|
||||
"Your NPC accepts only undammaged items. "..
|
||||
"Trading dammaged items would be unfair.")
|
||||
return 0
|
||||
end
|
||||
-- items with metadata cannot be traded
|
||||
local meta = stack:get_meta()
|
||||
for k, v in pairs(meta:to_table()) do
|
||||
if(k ~= "fields") then
|
||||
minetest.chat_send_player(player:get_player_name(),
|
||||
"Your NPC cannot sell items that contain "..
|
||||
"additional (meta-) data.")
|
||||
return 0
|
||||
else
|
||||
for k2, v2 in pairs(v) do
|
||||
if(k2) then
|
||||
minetest.chat_send_player(player:get_player_name(),
|
||||
"Your NPC cannot sell items that contain "..
|
||||
"additional (meta-) data.")
|
||||
return 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return stack:get_count()
|
||||
end,
|
||||
-- Called when a player wants to put something into the inventory.
|
||||
|
@ -43,6 +43,13 @@ yl_speak_up.can_trade_simple = function(player, count)
|
||||
-- trade not possible
|
||||
return 0
|
||||
end
|
||||
|
||||
-- used items cannot be sold as there is no fair way to indicate how
|
||||
-- much they are used
|
||||
if( trade_inv:get_stack("pay", 1):get_wear() > 0) then
|
||||
return 0
|
||||
end
|
||||
|
||||
-- all ok; all items that are to be sold can be taken
|
||||
return ItemStack(trade.npc_gives):get_count()
|
||||
end
|
||||
@ -172,6 +179,10 @@ yl_speak_up.get_fs_trade_simple = function(player, player_gives, npc_gives)
|
||||
if(not(npc_inv:contains_item("npc_main", trade.npc_gives))) then
|
||||
trade_possible_msg = "Sorry. "..minetest.formspec_escape(trade.npc_name)..
|
||||
" ran out of stock.\nPlease come back later."
|
||||
-- only new/undammaged tools, weapons and armor are accepted
|
||||
elseif(trade_inv:get_stack("pay", 1):get_wear() > 0) then
|
||||
trade_possible_msg = "Sorry. "..minetest.formspec_escape(trade.npc_name)..
|
||||
" accepts only undammaged items.]"
|
||||
else
|
||||
-- put a *copy* of the item(stack) that is to be sold in the sale slot
|
||||
trade_inv:add_item("buy", trade.npc_gives)
|
||||
|
Loading…
Reference in New Issue
Block a user