From 47126e00b6f9d0ddfca8d9d02580021b2a24518c Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 13 May 2018 23:31:39 +0200 Subject: [PATCH 01/10] Fix error message when using unknown item --- easyvend.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/easyvend.lua b/easyvend.lua index 0537088..199fd60 100644 --- a/easyvend.lua +++ b/easyvend.lua @@ -430,6 +430,12 @@ easyvend.on_receive_fields_config = function(pos, formname, fields, sender) easyvend.sound_error(sender:get_player_name()) easyvend.set_formspec(pos, sender) return + elseif ( not itemstack:is_known() ) then + meta:set_string("status", "Awaiting configuration by owner.") + meta:set_string("message", "Unknown item specified.") + easyvend.sound_error(sender:get_player_name()) + easyvend.set_formspec(pos, sender) + return elseif ( number == nil or number < 1 or number > maxnumber ) then if maxnumber > 1 then meta:set_string("message", string.format("Invalid item count; must be between 1 and %d!", maxnumber)) From 2f3966be6aaf73197fedb71424e86c1c5a609e21 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 13 May 2018 23:59:12 +0200 Subject: [PATCH 02/10] Update documentation --- README.md | 34 ++++++++++++++++++++++++++++------ easyvend.lua | 3 +-- init.lua | 17 +++++++++++++++-- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index fb1811f..e7902ed 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,33 @@ # Easy Vending Machines [`easyvend`] Version: 0.4.3 -Adds vending and depositing machines which allow to buy and sell items from other players. +Adds vending and depositing machines which allow to buy and sell items from +other players. -Help is included as help entry for Item Documentation [`doc_items`]. -## Converting machines from `vendor` mod (experimental) +## How to use +Help is also included as help entry for Item Documentation [`doc_items`]. + +### Summary +Vending machines TAKE currency (gold ingots by default) and GIVE items +of the owner's choice. +Depositing machines GIVE currency and TAKE items of the owner's choice. + +To operatre your own machine, place a locked chest above or below and fill +it with items to exchange. If the green status LED (the upper one) lights +up, the machine is operational. You can stack these locked chests for +extended storage. + +### Currency item +The currency is fixed during a game; all machines use the same currency. +But it can be changed via the setting `easyvend_currency`. + + + + + +## Appendix +### Converting machines from `vendor` mod (experimental) This mod is able to automatically transform the vending and depositing machines from Bad\_Command\_'s Vending machines [`vendor`] mod on loading and turn them into the new machines from `easyvend`. This is useful if @@ -15,7 +37,7 @@ you want to switch a world from `vendor` to `easyvend`. before doing this. This feature is also incomplete; items are currently **not** transformed in the process. -### Conversion process +#### Conversion process To transform all nodes from the `vendor` mod, disable the `vendor` mod (if it is not already disabled), enable the setting `easyvend_convert_vendor` and start or restart the game. @@ -25,7 +47,7 @@ Now all nodes from the `vendor` mod will be replaced with `easyvend` ones. If you run a server, you should inform players of this change because a few machines might need a reconfiguration. -### Details +#### Details The machine configuration will be kept in the process and the machines will stay in operation provided their configuration is valid. The mod tries to keep as many machines in operation as possible. Machines with very high values @@ -33,7 +55,7 @@ keep as many machines in operation as possible. Machines with very high values be reconfigured by their owners. Most machines which worked before will likely stay in operation afterwards. -## Credits and licenses +### Credits and licenses - Code - License: [LGPL 2.1](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html) - Source: Forked from mod “Vending Machines” [vendor] by Bad\_Command\_. diff --git a/easyvend.lua b/easyvend.lua index 199fd60..4ec34a5 100644 --- a/easyvend.lua +++ b/easyvend.lua @@ -396,8 +396,7 @@ easyvend.on_receive_fields_config = function(pos, formname, fields, sender) --[[ Convenience function: When appending “s” or “S” to the number, it is multiplied - by the maximum stack size. - TODO: Expose this in user documentation ]] + by the maximum stack size. ]] local number_stack_max = itemstack:get_stack_max() local ss = string.sub(number, #number, #number) if ss == "s" or ss == "S" then diff --git a/init.lua b/init.lua index 424c807..ee825d2 100644 --- a/init.lua +++ b/init.lua @@ -88,7 +88,14 @@ vendor_on.drop = "easyvend:vendor" local vendor_off = table.copy(machine_template) vendor_off.description = vendor_on.description vendor_off._doc_items_longdesc = string.format("A vending machine allows its owner to offer a certain item in exchange for money (%s). The users can pay with money and will some items in return.", easyvend.currency_desc) -vendor_off._doc_items_usagehelp = "For customers: The vending machine has to be ready to be used, which is the case if the green LED lights up. Point the vending machine to see its owner and what it has to offer and at which price (item count first). Rightclick it to open the buying menu. You can pay with the number of items shown at “Price” and you will get the item at “Offered item” in return. Click on “Buy” to buy this offer once, repeat this as often as you like.\nFor owners: First, place a locked chest and fill it with the item you want to sell, make sure you leave some inventory slots empty for the price. Place the vending machine above or below the locked chest. Any locked chest connected in a unbroken vertical line of locked chests, vending machines and depositing machines will be accessed as storage. Rightclick the machine. Set the offered item by moving an item from your invenory into the slot. The price item can not be changed. Now set the number of items per sale and their price and click on “Confirm” to confirm. Check the message and status for any errors. If the status is “Ready.”, the machine works properly. All other status messages are errors. The earnings of the vending machine can be retrieved from the locked chest." +vendor_off._doc_items_usagehelp = [[For customers: +First check if the vending machine is ready (upper green LED lights up), otherwise it is of no use. Point it to see its owner and offer. Rightclick to open the buying menu. You can pay with the number of items shown at “Price” and you will get the item at “Offered item” in return. Click on “Buy” to buy this offer once. + +For owners: +First, place a locked chest and fill it with the item you want to sell, make sure you leave some inventory slots empty for the price. Place the vending machine above or below the locked chest. Any locked chest connected in a unbroken vertical line of locked chests, vending/depositing machines will be accessed as storage. Rightclick the machine. Set the offered item by moving an item from your invenory into the slot. The price item can not be changed. Now set the number of items per sale and their price and click on “Confirm” to confirm. If the upper green status LED lights up, you're done, if not, check the message. +The earnings will go into the locked chest. +Hint: If you enter an “s” after the item number to multiply it with the maximum stack size.]] + vendor_off.tiles = table.copy(vendor_on.tiles) vendor_off.tiles[6] = "easyvend_vendor_front_off.png" @@ -103,7 +110,13 @@ depositor_on.drop = "easyvend:depositor" local depositor_off = table.copy(machine_template) depositor_off.description = depositor_on.description depositor_off._doc_items_longdesc = string.format("A depositing machine allows its owner to offer money (%s) in exchange for a certain item. The users can supply the depositing machine with the requested item and will get money in return.", easyvend.currency_desc) -depositor_off._doc_items_usagehelp = "For users: The depositing machine has to be ready to be used, which is the case if the green LED lights up. Point the depositing machine to see its owner and what item it asks for and at which payment (item count first). Rightclick it to open the selling menu. You can give the number of items shown at “Requested item” and you will get the items at “Payment” in return. Click on “Sell” to exchange items, repeat this as often as you like.\nFor owners: First, place a locked chest and supply it with the payment item, make sure you leave some inventory slots empty for the items you want to retrieve. Place the depositing machine above or below the locked chest. Any chest connected in a unbroken vertical stack of locked chests, vending machines and depositing machines will be accessed as storage. Rightclick the machine. Set the requested item by moving an item from your invenory into the slot. The payment item can not be changed. Now set the number of requested items and how much you pay for them and click on “Confirm” to confirm. Check the message and status for any errors. If the status is “Ready.”, the machine works properly, all other status messages are errors. The deposited items can be retrieved from the locked chest." +depositor_off._doc_items_usagehelp = [[For users: +To use a machine, check if its ready (the upper green LED lights up), otherwise, it cannot be used. Point the depositing machine to see its owner and the offer. Rightclick for the selling menu. You can give the number of items shown at “Requested item” and you will get the items at “Payment” in return. Click on “Sell” to exchange items, repeat this as often as you like. + +For owners: +First, place a locked chest and supply it with the payment item, make sure you leave some inventory slots empty for the items you want to retrieve. Place the machine above or below the chest. Any chest connected in a unbroken vertical stack of locked chests, vending/depositing machines machines will be accessed. +Rightclick the machine. Set the requested item by moving an item from your invenory into the slot. The payment item can not be changed. Now set the number of requested items and your payment and click on “Confirm” to confirm. (Hint: Append the letter “s” to the number to multiply by the stack size). If the upper green LED lights up, everything works fine, otherwise, check the message. The deposited items will end up in the chest. +Hint: If you enter an “s” after the item number to multiply it with the maximum stack size.]] depositor_off.tiles = table.copy(depositor_on.tiles) depositor_off.tiles[6] = "easyvend_depositor_front_off.png" From f2f6a0b2e4ea1b8926f3461ce4de30adb0dc65d5 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 14 May 2018 00:35:09 +0200 Subject: [PATCH 03/10] More msg improvements --- easyvend.lua | 2 +- init.lua | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/easyvend.lua b/easyvend.lua index 4ec34a5..1511ea6 100644 --- a/easyvend.lua +++ b/easyvend.lua @@ -896,7 +896,7 @@ easyvend.after_place_node = function(pos, placer) end meta:set_string("infotext", d) meta:set_string("status", "Awaiting configuration by owner.") - meta:set_string("message", "Welcome! Please prepare the machine.") + meta:set_string("message", "Please select an item and amount, then confirm.") meta:set_int("number", 1) meta:set_int("cost", 1) meta:set_int("stock", -1) diff --git a/init.lua b/init.lua index ee825d2..652f700 100644 --- a/init.lua +++ b/init.lua @@ -89,12 +89,13 @@ local vendor_off = table.copy(machine_template) vendor_off.description = vendor_on.description vendor_off._doc_items_longdesc = string.format("A vending machine allows its owner to offer a certain item in exchange for money (%s). The users can pay with money and will some items in return.", easyvend.currency_desc) vendor_off._doc_items_usagehelp = [[For customers: -First check if the vending machine is ready (upper green LED lights up), otherwise it is of no use. Point it to see its owner and offer. Rightclick to open the buying menu. You can pay with the number of items shown at “Price” and you will get the item at “Offered item” in return. Click on “Buy” to buy this offer once. +Only if the upper green status LED lights up, the machine is ready for use. Point to see its owner and offer. Rightclick to open the buying menu. You can pay with the number of items shown at “Price” and you will get the item at “Offered item” in return. Click on “Buy” to buy this offer once. For owners: -First, place a locked chest and fill it with the item you want to sell, make sure you leave some inventory slots empty for the price. Place the vending machine above or below the locked chest. Any locked chest connected in a unbroken vertical line of locked chests, vending/depositing machines will be accessed as storage. Rightclick the machine. Set the offered item by moving an item from your invenory into the slot. The price item can not be changed. Now set the number of items per sale and their price and click on “Confirm” to confirm. If the upper green status LED lights up, you're done, if not, check the message. +First, place a locked chest and fill it with the item you want to sell, make sure you leave some inventory slots empty for the price. Place the vending machine above or below the locked chest. Any locked chest connected in a unbroken vertical line of locked chests and vending/depositing machines will be accessed as storage. +Rightclick the machine. Set the offered item by moving an item from your invenory into the slot. The price item can not be changed. Now set the number of items per sale and their price and click on “Confirm” to confirm. If the upper green status LED lights up, you're done, if not, check the message. The earnings will go into the locked chest. -Hint: If you enter an “s” after the item number to multiply it with the maximum stack size.]] +Hint: If you enter an “s” after the item number, it will be multiplied with the maximum stack size.]] vendor_off.tiles = table.copy(vendor_on.tiles) vendor_off.tiles[6] = "easyvend_vendor_front_off.png" @@ -111,12 +112,12 @@ local depositor_off = table.copy(machine_template) depositor_off.description = depositor_on.description depositor_off._doc_items_longdesc = string.format("A depositing machine allows its owner to offer money (%s) in exchange for a certain item. The users can supply the depositing machine with the requested item and will get money in return.", easyvend.currency_desc) depositor_off._doc_items_usagehelp = [[For users: -To use a machine, check if its ready (the upper green LED lights up), otherwise, it cannot be used. Point the depositing machine to see its owner and the offer. Rightclick for the selling menu. You can give the number of items shown at “Requested item” and you will get the items at “Payment” in return. Click on “Sell” to exchange items, repeat this as often as you like. +To use a machine, check if its ready (the upper green LED lights up). Point the depositing machine to see its owner and the offer. Rightclick for the selling menu. You can give the number of items shown at “Requested item” and you will get the items at “Payment” in return. Click on “Sell” to exchange items, repeat this as often as you like. For owners: -First, place a locked chest and supply it with the payment item, make sure you leave some inventory slots empty for the items you want to retrieve. Place the machine above or below the chest. Any chest connected in a unbroken vertical stack of locked chests, vending/depositing machines machines will be accessed. -Rightclick the machine. Set the requested item by moving an item from your invenory into the slot. The payment item can not be changed. Now set the number of requested items and your payment and click on “Confirm” to confirm. (Hint: Append the letter “s” to the number to multiply by the stack size). If the upper green LED lights up, everything works fine, otherwise, check the message. The deposited items will end up in the chest. -Hint: If you enter an “s” after the item number to multiply it with the maximum stack size.]] +First, place a locked chest and supply it with the payment item, make sure you leave some inventory slots empty for the items you want to retrieve. Place the machine above or below the chest. Any chest connected in a unbroken vertical stack of locked chests and vending/depositing machines will be accessed. +Rightclick the machine. Set the requested item by moving an item from your inventory into the slot. The payment item can not be changed. Now set the number of requested items and your payment and click on “Confirm” to confirm. If the upper green LED lights up, everything works fine, otherwise, check the message. The deposited items will end up in the chest. +Hint: If you enter an “s” after the item number, it will be multiplied with the maximum stack size.]] depositor_off.tiles = table.copy(depositor_on.tiles) depositor_off.tiles[6] = "easyvend_depositor_front_off.png" From 680cabdfcdc5f9f1f24cb5185305cd7baae43c2b Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 14 May 2018 00:42:24 +0200 Subject: [PATCH 04/10] Remove help button from machines --- easyvend.lua | 6 ------ 1 file changed, 6 deletions(-) diff --git a/easyvend.lua b/easyvend.lua index 1511ea6..e345715 100644 --- a/easyvend.lua +++ b/easyvend.lua @@ -138,12 +138,6 @@ easyvend.set_formspec = function(pos, player) .."label[0,-0.15;"..numbertext.."]" .."label[0,1.2;"..costtext.."]" .."list[current_player;main;0,3.5;8,4;]" - if minetest.get_modpath("doc") and minetest.get_modpath("doc_items") then - if (doc.VERSION.MAJOR >= 1) or (doc.VERSION.MAJOR == 0 and doc.VERSION.MINOR >= 8) then - formspec = formspec .. "image_button[7.25,2;0.75,0.75;doc_button_icon_lores.png;doc;]" .. - "tooltip[doc;Help]" - end - end if configmode then local wear = "false" From b76b059f1c14d123a4c518870f35fba0c2d7f1e8 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 14 May 2018 01:29:32 +0200 Subject: [PATCH 05/10] Add API docs --- API.md | 25 +++++++++++++++++++++++++ README.md | 4 ++++ 2 files changed, 29 insertions(+) create mode 100644 API.md diff --git a/API.md b/API.md new file mode 100644 index 0000000..e1addc4 --- /dev/null +++ b/API.md @@ -0,0 +1,25 @@ +# Easyvend API +Use this API if you want to make an comntainer compatible with vending and +depositing machines. + +The API only has one function: + +## `easyvend.register_chest = function(node_name, inv_list, meta_owner)` +Registers a node (called “chest”) for use with Easyvend. After calling this function, +the node will be recognized as storage for vending and depositing machines. + +Easyvend makes the following assumptions about the chest: +* It has an inventory +* The inventory does not restrict the types of items you can put and take +* The chest is owned by a player +* The owner is specified in metadata + +### Parameters +* `node_name`: Name of the chest node +* `inv_list`: Name of the inventory list for exchanging items +* `meta_owner`: Identifier of the metadata variable storing the owner name + +### Example +``` +easyvend.register_chest("example:superchest", "main", "owner") +``` diff --git a/README.md b/README.md index e7902ed..8464215 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,10 @@ But it can be changed via the setting `easyvend_currency`. ## Appendix +### Developer information +If you want to a container node compatible with vending/depositing machines, +use the Easyvend API, see the file `API.md`. + ### Converting machines from `vendor` mod (experimental) This mod is able to automatically transform the vending and depositing machines from Bad\_Command\_'s Vending machines [`vendor`] mod on loading From 379a4e591144a2bdd60484e1e29873a9f19bac99 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 14 May 2018 02:17:31 +0200 Subject: [PATCH 06/10] Make default dependency officially optional --- API.md | 18 +++++++++++++++--- README.md | 10 ++++++++-- depends.txt | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/API.md b/API.md index e1addc4..39b1969 100644 --- a/API.md +++ b/API.md @@ -1,8 +1,12 @@ # Easyvend API -Use this API if you want to make an comntainer compatible with vending and +Use this API if you want to make an container compatible with vending and depositing machines. -The API only has one function: +## How it works + +* Add `easyvend` as optional dependency +* Check for existance of `easyvend` mod in code +* Call `easyvend.register_chest` for all containers you want to be compatible ## `easyvend.register_chest = function(node_name, inv_list, meta_owner)` Registers a node (called “chest”) for use with Easyvend. After calling this function, @@ -20,6 +24,14 @@ Easyvend makes the following assumptions about the chest: * `meta_owner`: Identifier of the metadata variable storing the owner name ### Example + +Register the node `example:superchest` as container: + ``` -easyvend.register_chest("example:superchest", "main", "owner") +if minetest.get_modpath("easyvend") then + easyvend.register_chest("example:superchest", "main", "owner") +end ``` + +The `if` check is a common trick to check for the existance of the `easyvend` +and allows you to make the dependency optional. diff --git a/README.md b/README.md index 8464215..c1824c0 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,14 @@ Version: 0.4.3 Adds vending and depositing machines which allow to buy and sell items from other players. +## Requirements +Runs natively in Minetest Game. + +May also run in other games if they have the `default` mod and locked chest +(`default:chest_locked`). + +Locked chests from other mods are not supported, but mods can choose +to add support for Easyvend on their own (see developer information below). ## How to use Help is also included as help entry for Item Documentation [`doc_items`]. @@ -24,8 +32,6 @@ But it can be changed via the setting `easyvend_currency`. - - ## Appendix ### Developer information If you want to a container node compatible with vending/depositing machines, diff --git a/depends.txt b/depends.txt index c800511..e9558c0 100644 --- a/depends.txt +++ b/depends.txt @@ -1,4 +1,4 @@ -default +default? screwdriver? doc? doc_items? From 49e529a96e6e6c016269f9ca0a9f6d801eaa05d2 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 14 May 2018 22:04:45 +0200 Subject: [PATCH 07/10] Add select_item support --- README.md | 9 ++++++-- depends.txt | 1 + easyvend.lua | 59 +++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c1824c0..16ef8d9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Version: 0.4.3 Adds vending and depositing machines which allow to buy and sell items from -other players. +other players, using a currency item. ## Requirements Runs natively in Minetest Game. @@ -13,6 +13,11 @@ May also run in other games if they have the `default` mod and locked chest Locked chests from other mods are not supported, but mods can choose to add support for Easyvend on their own (see developer information below). +You can optionally add the `select_item` mod. This adds a button to select +an item from a list of items. +This feature is very useful for depositing machines because you can select +any item, not just those you have already in your inventory. + ## How to use Help is also included as help entry for Item Documentation [`doc_items`]. @@ -27,7 +32,7 @@ up, the machine is operational. You can stack these locked chests for extended storage. ### Currency item -The currency is fixed during a game; all machines use the same currency. +The currency of all machines is gold ingots by default. But it can be changed via the setting `easyvend_currency`. diff --git a/depends.txt b/depends.txt index e9558c0..d05cd83 100644 --- a/depends.txt +++ b/depends.txt @@ -1,5 +1,6 @@ default? screwdriver? +select_item? doc? doc_items? awards? diff --git a/easyvend.lua b/easyvend.lua index e345715..45c5143 100644 --- a/easyvend.lua +++ b/easyvend.lua @@ -13,12 +13,46 @@ local maxcost = cost_stack_max * slots_max local joketimer_start = 3 +local active_item_selection = {} + -- Allow for other mods to register custom chests easyvend.register_chest = function(node_name, inv_list, meta_owner) registered_chests[node_name] = { inv_list = inv_list, meta_owner = meta_owner } traversable_node_types[node_name] = true end +if minetest.get_modpath("select_item") then + -- When player selects item via "select item" dialog, switch the + -- machine's selected item and update the formspec. + select_item.register_on_select_item(function(playername, itemstring) + local player = minetest.get_player_by_name(playername) + if not player then + return + end + local pos = active_item_selection[playername] + if pos then + local node = minetest.get_node(pos) + if not easyvend.is_machine(node.name) then + return + end + local meta = minetest.get_meta(pos) + local owner = meta:get_string("owner") + if playername == owner then + local inv = meta:get_inventory() + local stack = ItemStack(itemstring) + if stack == nil then + inv:set_stack( "item", 1, nil ) + else + inv:set_stack( "item", 1, stack) + meta:set_string("itemname", itemstring) + easyvend.set_formspec(pos, player) + end + end + end + active_item_selection[playername] = nil + end) +end + -- Partly a wrapper around contains_item, but does special treatment if the item -- is a tool. Basically checks whether the items exist in the supplied inventory -- list. If check_wear is true, only counts items without wear. @@ -76,6 +110,10 @@ easyvend.buysell = function(nodename) return buysell end +easyvend.is_machine = function(nodename) + return ( nodename == "easyvend:depositor_on" or nodename == "easyvend:vendor_on" or nodename == "easyvend:depositor" or nodename == "easyvend:vendor" ) +end + easyvend.is_active = function(nodename) if ( nodename == "easyvend:depositor_on" or nodename == "easyvend:vendor_on" ) then return true @@ -153,6 +191,9 @@ easyvend.set_formspec = function(pos, player) .."tooltip[cost;"..itemcounttooltip.."]" .."button[6,2.8;2,0.5;save;Confirm]" .."tooltip[save;Confirm configuration and activate machine (only for owner)]" + if minetest.get_modpath("select_item") then + formspec = formspec .. "button[0,2.8;2,0.5;select_item;Select item]" + end local weartext, weartooltip if buysell == "buy" then weartext = "Buy worn tools" @@ -948,7 +989,7 @@ easyvend.on_receive_fields = function(pos, formname, fields, sender) end end elseif fields.config or fields.save or fields.usermode then - if sender:get_player_name() == owner then + if sendername == owner then easyvend.on_receive_fields_config(pos, formname, fields, sender) else meta:set_string("message", "Only the owner may change the configuration.") @@ -956,6 +997,18 @@ easyvend.on_receive_fields = function(pos, formname, fields, sender) easyvend.set_formspec(pos, sender) return end + elseif fields.select_item then + if minetest.get_modpath("select_item") then + if sendername == owner then + active_item_selection[sendername] = pos + select_item.show_dialog(sendername, select_item.filters.creative) + else + meta:set_string("message", "Only the owner may change the configuration.") + easyvend.sound_error(sendername) + easyvend.set_formspec(pos, sender) + return + end + end elseif fields.wear ~= nil then if sender:get_player_name() == owner then if fields.wear == "true" then @@ -1179,7 +1232,7 @@ easyvend.find_chest = function(owner, pos, dy, itemname, check_wear, amount, rem else return nil, internal end - elseif (node.name ~= "easyvend:vendor" and node.name~="easyvend:depositor" and node.name~="easyvend:vendor_on" and node.name~="easyvend:depositor_on") then + elseif not easyvend.is_machine(node.name) then return nil, internal end @@ -1194,7 +1247,7 @@ easyvend.allow_metadata_inventory_put = function(pos, listname, index, stack, pl local name = player:get_player_name() if name == owner then local inv = meta:get_inventory() - if stack==nil then + if stack == nil then inv:set_stack( "item", 1, nil ) else inv:set_stack( "item", 1, stack:get_name() ) From 1997fcde9aaae94ee798711228dd86f7053f36e1 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 15 May 2018 01:37:53 +0200 Subject: [PATCH 08/10] Fix typos --- API.md | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/API.md b/API.md index 39b1969..4e827a4 100644 --- a/API.md +++ b/API.md @@ -5,7 +5,7 @@ depositing machines. ## How it works * Add `easyvend` as optional dependency -* Check for existance of `easyvend` mod in code +* Check for existence of `easyvend` mod in code * Call `easyvend.register_chest` for all containers you want to be compatible ## `easyvend.register_chest = function(node_name, inv_list, meta_owner)` @@ -33,5 +33,5 @@ if minetest.get_modpath("easyvend") then end ``` -The `if` check is a common trick to check for the existance of the `easyvend` +The `if` check is a common trick to check for the existence of the `easyvend` and allows you to make the dependency optional. diff --git a/README.md b/README.md index 16ef8d9..ce41f88 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Vending machines TAKE currency (gold ingots by default) and GIVE items of the owner's choice. Depositing machines GIVE currency and TAKE items of the owner's choice. -To operatre your own machine, place a locked chest above or below and fill +To operate your own machine, place a locked chest above or below and fill it with items to exchange. If the green status LED (the upper one) lights up, the machine is operational. You can stack these locked chests for extended storage. From fa14d271910088f863150023db8190d006853339 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 15 May 2018 02:57:51 +0200 Subject: [PATCH 09/10] Rewrite msgs for tools --- easyvend.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/easyvend.lua b/easyvend.lua index 45c5143..a5edf19 100644 --- a/easyvend.lua +++ b/easyvend.lua @@ -229,9 +229,9 @@ easyvend.set_formspec = function(pos, player) end else if buysell == "sell" then - weartext = "Warning: Might sell worn tools." + weartext = "Note: Might sell worn tools." else - weartext = "Worn tools are bought, too." + weartext = "Accepts worn tools." end end if weartext ~= nil then From 9aca0379b7fa80dafd542b50028893b3d8cfdf4b Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 17 May 2018 15:18:19 +0200 Subject: [PATCH 10/10] Update select_item handling --- easyvend.lua | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/easyvend.lua b/easyvend.lua index a5edf19..a26848b 100644 --- a/easyvend.lua +++ b/easyvend.lua @@ -24,32 +24,34 @@ end if minetest.get_modpath("select_item") then -- When player selects item via "select item" dialog, switch the -- machine's selected item and update the formspec. - select_item.register_on_select_item(function(playername, itemstring) - local player = minetest.get_player_by_name(playername) - if not player then - return - end - local pos = active_item_selection[playername] - if pos then - local node = minetest.get_node(pos) - if not easyvend.is_machine(node.name) then + select_item.register_on_select_item(function(playername, dialogname, itemstring) + if dialogname == "easyvend:trade_item" then + local player = minetest.get_player_by_name(playername) + if not player then return end - local meta = minetest.get_meta(pos) - local owner = meta:get_string("owner") - if playername == owner then - local inv = meta:get_inventory() - local stack = ItemStack(itemstring) - if stack == nil then - inv:set_stack( "item", 1, nil ) - else - inv:set_stack( "item", 1, stack) - meta:set_string("itemname", itemstring) - easyvend.set_formspec(pos, player) + local pos = active_item_selection[playername] + if pos then + local node = minetest.get_node(pos) + if not easyvend.is_machine(node.name) then + return + end + local meta = minetest.get_meta(pos) + local owner = meta:get_string("owner") + if playername == owner then + local inv = meta:get_inventory() + local stack = ItemStack(itemstring) + if stack == nil then + inv:set_stack( "item", 1, nil ) + else + inv:set_stack( "item", 1, stack) + meta:set_string("itemname", itemstring) + easyvend.set_formspec(pos, player) + end end end + active_item_selection[playername] = nil end - active_item_selection[playername] = nil end) end @@ -1001,7 +1003,7 @@ easyvend.on_receive_fields = function(pos, formname, fields, sender) if minetest.get_modpath("select_item") then if sendername == owner then active_item_selection[sendername] = pos - select_item.show_dialog(sendername, select_item.filters.creative) + select_item.show_dialog(sendername, "easyvend:trade_item", select_item.filters.creative) else meta:set_string("message", "Only the owner may change the configuration.") easyvend.sound_error(sendername)