summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2020-03-06 23:35:24 +0100
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2020-03-06 23:35:24 +0100
commitdfa5c06cec0e95f47c74fd00951244a1aefe5c17 (patch)
tree71f656e3a7440d3a8f84ad259f1595c45dfafa69
parent83060e9e85be790f64fcf51def1f024699a46d2d (diff)
downloadsmartshop-dfa5c06cec0e95f47c74fd00951244a1aefe5c17.tar.gz
smartshop-dfa5c06cec0e95f47c74fd00951244a1aefe5c17.tar.bz2
smartshop-dfa5c06cec0e95f47c74fd00951244a1aefe5c17.zip
Preserve metadata on sale
This allows sale of items such as crated digtrons. However, BEWARE OF SCAMS: the metadata might not match up with the object advertised by the seller.
-rw-r--r--init.lua25
1 files changed, 14 insertions, 11 deletions
diff --git a/init.lua b/init.lua
index 813ba6a..746a28a 100644
--- a/init.lua
+++ b/init.lua
@@ -144,18 +144,18 @@ smartshop.receive_fields=function(player,pressed)
local inv=meta:get_inventory()
local pinv=player:get_inventory()
if pressed["buy" .. n] then
- local name=inv:get_stack("give" .. n,1):get_name()
- local stack=name .." ".. inv:get_stack("give" .. n,1):get_count()
- local pay=inv:get_stack("pay" .. n,1):get_name() .." ".. inv:get_stack("pay" .. n,1):get_count()
+ local stack=inv:get_stack("give" .. n,1)
+ local name=stack:get_name()
+ local pay=inv:get_stack("pay" .. n,1)
if name~="" then
if type==1 and inv:room_for_item("main", pay)==false then minetest.chat_send_player(pname, "Error: The owner's stock is full, can't receive, exchange aborted.") return end
if meta:get_int("ghost") ~=1 then
-- transition shops to ghost inventory.
for i=1,4 do
if inv:room_for_item("main", "pay"..i) and inv:room_for_item("main", "give"..i) then
- meta:set_int("ghost", 1)
- inv:add_item("main", inv:get_stack("pay"..i,1))
- inv:add_item("main", inv:get_stack("give"..i,1))
+ meta:set_int("ghost", 1)
+ inv:add_item("main", inv:get_stack("pay"..i,1))
+ inv:add_item("main", inv:get_stack("give"..i,1))
end
end
end
@@ -169,11 +169,14 @@ smartshop.receive_fields=function(player,pressed)
end
if not pinv:contains_item("main", pay) then minetest.chat_send_player(pname, "Error: You don't have enough in your inventory to buy this, exchange aborted.") return end
if not pinv:room_for_item("main", stack) then minetest.chat_send_player(pname, "Error: Your inventory is full, exchange aborted.") return end
- pinv:remove_item("main", pay)
- pinv:add_item("main", stack)
- if type==1 then
- inv:remove_item("main", stack)
- inv:add_item("main", pay)
+ if type == 0 then
+ pinv:remove_item("main", pay)
+ pinv:add_item("main", stack)
+ else
+ local item = inv:remove_item("main", stack)
+ pinv:add_item("main", item)
+ item = pinv:remove_item("main",pay)
+ inv:add_item("main", item)
if not inv:contains_item("main", stack) and (not meta:get_int("alerted") or meta:get_int("alerted") == 0) then
meta:set_int("alerted",1) -- Do not alert twice
smartshop.send_mail(meta:get_string("owner"), pos, name)