se puede elegir la cantidad de objetos a vender

fancyshop
GNU Hacker 3 years ago
parent bfe60227d4
commit 3f23448468

@ -21,6 +21,8 @@
local S = core.get_translator(core.get_current_modname())
local shopcraft = core.settings:get_bool("emeraldbank.shop_craft") or true
local stock_h = 3
local stock_w = 5
@ -36,6 +38,7 @@ emeraldbank.player_inv =
function emeraldbank.get_shop_fs(pos, clicker)
local meta = core.get_meta(pos)
local count = meta:get_int("count")
local price = meta:get_int("price")
local shop_item = meta:get_string("shop_item")
local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
@ -48,6 +51,7 @@ function emeraldbank.get_shop_fs(pos, clicker)
"label[0,0;"..S("Your stock:").."]"..
"list["..list_name..";stock;0,0.5;"..stock_w..","..stock_h..";]"..
mcl_formspec.get_itemslot_bg(0,0.5,stock_w,stock_h)..
"field[6.5,2;2,1;count;"..S("Count")..";"..count.."]"..
"field[6.5,3;2,1;price;"..S("Price")..";"..price.."]"..
"label[6,0;"..S("In exchange, you give:").."]"..
"item_image[6.5,0.5;1,1;"..shop_item.."]"..
@ -59,6 +63,7 @@ function emeraldbank.get_shop_fs(pos, clicker)
"label[3.7,0;"..S("Owner gives:").."]"..
"item_image[4,1;1,1;"..shop_item.."]"..
mcl_formspec.get_itemslot_bg(4,1,1,1)..
"label[5,1.5;"..S("x @1", count).."]"..
"label[4,2;"..S("Price: @1", price).."]"..
"button[3.5,3;2,1;exchange;"..S("Exchange").."]"..
emeraldbank.player_inv
@ -160,6 +165,8 @@ core.register_on_player_receive_fields(function(sender, formname, fields)
local name = sender:get_player_name()
local playermeta = sender:get_meta()
local player_pos = sender:get_pos()
local old_count = meta:get_int("count")
local new_count = tonumber(fields.count)
local old_price = meta:get_int("price")
local new_price = tonumber(fields.price)
local shop_item = meta:get_string("shop_item")
@ -167,6 +174,12 @@ core.register_on_player_receive_fields(function(sender, formname, fields)
local pinv = sender:get_inventory()
local bankemeralds = playermeta:get_int("emeraldbank:emerald")
if fields.count and string.find(fields.count, "^[0-9]+$") then
if new_count >= 1 and new_count <= 64 and new_count ~= meta:get_int("count") then
meta:set_int("count", new_count)
end
end
if fields.price and string.find(fields.price, "^[0-9]+$") then
if new_price >= 1 and new_price <= 10000 and new_price ~= meta:get_int("price") then
meta:set_int("price", new_price)
@ -181,7 +194,6 @@ core.register_on_player_receive_fields(function(sender, formname, fields)
else
local stocklist = minv:get_list("stock")
local can_exchange = true
if bankemeralds < old_price then
@ -189,14 +201,14 @@ core.register_on_player_receive_fields(function(sender, formname, fields)
core.chat_send_player(name, S("Not enough Emeralds in your account") )
end
if not minv:contains_item("stock", shop_item) then
if not minv:contains_item("stock", shop_item.." "..old_count, true) then
can_exchange = false
core.chat_send_player(name, S("Out of Stock!") )
end
if can_exchange then
minv:remove_item("stock", shop_item)
core.add_item(player_pos, shop_item)
minv:remove_item("stock", shop_item.." "..old_count)
core.add_item(player_pos, shop_item.." "..old_count)
emeraldbank.add_emeralds(sender, -old_price)
meta:set_int("stonks", meta:get_int("stonks")+old_price)
core.chat_send_player(name, S("Exchanged!"))
@ -209,3 +221,15 @@ core.register_on_player_receive_fields(function(sender, formname, fields)
end
end)
if shopcraft then
core.register_craft({
output = "emeraldbank:shop 3",
recipe = {
{"mcl_core:emerald", "mcl_core:emerald", "mcl_core:emerald"},
{"mcl_core:emerald", "mcl_core:tree", "mcl_core:emerald"},
{"mcl_core:emerald", "mcl_core:emerald", "mcl_core:emerald"},
}
})
end

Loading…
Cancel
Save