Update item help
[minetest_easyvend.git] / init.lua
blob3f1d00ef4d98619386447331039bc125884f9e94
1 --[[
2 Easy Vending Machines [easyvend]
3 Copyright (C) 2012 Bad_Command, 2016 Wuzzy
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 easyvend = {}
21 easyvend.VERSION = {}
22 easyvend.VERSION.MAJOR = 0
23 easyvend.VERSION.MINOR = 2
24 easyvend.VERSION.PATCH = 0
25 easyvend.VERSION.STRING = easyvend.VERSION.MAJOR .. "." .. easyvend.VERSION.MINOR .. "." .. easyvend.VERSION.PATCH
27 -- Set item which is used as payment for vending and depositing machines
28 easyvend.currency = minetest.setting_get("easyvend_currency")
29 if easyvend.currency == nil or minetest.registered_items[easyvend.currency] == nil then
30 -- Default currency
31 easyvend.currency = "default:gold_ingot"
32 end
33 easyvend.currency_desc = minetest.registered_items[easyvend.currency].description
34 if easyvend.currency_desc == nil or easyvend.currency_desc == "" then
35 easyvend.currency_desc = easyvend.currency
36 end
38 dofile(minetest.get_modpath("easyvend") .. "/easyvend.lua")
40 local sounds
41 local soundsplus = {
42 place = { name = "easyvend_disable", gain = 1 },
43 dug = { name = "easyvend_disable", gain = 1 }, }
44 if minetest.get_modpath("default") ~= nil then
45 sounds = default.node_sound_wood_defaults(soundsplus)
46 else
47 sounds = soundsplus
48 end
50 local machine_template = {
51 paramtype2 = "facedir",
52 groups = {choppy=2,oddly_breakable_by_hand=2},
54 after_place_node = easyvend.after_place_node,
55 can_dig = easyvend.can_dig,
56 on_receive_fields = easyvend.on_receive_fields,
57 sounds = sounds,
59 allow_metadata_inventory_put = easyvend.allow_metadata_inventory_put,
60 allow_metadata_inventory_take = easyvend.allow_metadata_inventory_take,
61 allow_metadata_inventory_move = easyvend.allow_metadata_inventory_move,
62 on_punch = easyvend.machine_check,
65 if minetest.get_modpath("screwdriver") ~= nil then
66 machine_template.on_rotate = screwdriver.rotate_simple
67 end
69 local vendor_on = table.copy(machine_template)
70 vendor_on.description = "Vending Machine"
71 vendor_on.tile_images ={"easyvend_vendor_bottom.png", "easyvend_vendor_bottom.png", "easyvend_vendor_side.png",
72 "easyvend_vendor_side.png", "easyvend_vendor_side.png", "easyvend_vendor_front_on.png"}
73 vendor_on.groups.not_in_creative_inventory = 1
74 vendor_on.groups.not_in_doc = 1
75 vendor_on.drop = "easyvend:vendor"
77 local vendor_off = table.copy(machine_template)
78 vendor_off.description = vendor_on.description
79 vendor_off.tile_images = table.copy(vendor_on.tile_images)
80 vendor_off.tile_images[6] = "easyvend_vendor_front_off.png"
82 local depositor_on = table.copy(machine_template)
83 depositor_on.description = "Depositing Machine"
84 depositor_on.tile_images ={"easyvend_depositor_bottom.png", "easyvend_depositor_bottom.png", "easyvend_depositor_side.png",
85 "easyvend_depositor_side.png", "easyvend_depositor_side.png", "easyvend_depositor_front_on.png"}
86 depositor_on.groups.not_in_creative_inventory = 1
87 depositor_on.groups.not_in_doc = 1
88 depositor_on.drop = "easyvend:depositor"
90 local depositor_off = table.copy(machine_template)
91 depositor_off.description = depositor_on.description
92 depositor_off.tile_images = table.copy(depositor_on.tile_images)
93 depositor_off.tile_images[6] = "easyvend_depositor_front_off.png"
95 minetest.register_node("easyvend:vendor", vendor_off)
96 minetest.register_node("easyvend:vendor_on", vendor_on)
97 minetest.register_node("easyvend:depositor", depositor_off)
98 minetest.register_node("easyvend:depositor_on", depositor_on)
100 if minetest.get_modpath("default") ~= nil then
101 minetest.register_craft({
102 output = 'easyvend:vendor',
103 recipe = {
104 {'group:wood', 'group:wood', 'group:wood'},
105 {'group:wood', 'default:steel_ingot', 'group:wood'},
106 {'group:wood', 'default:steel_ingot', 'group:wood'},
110 minetest.register_craft({
111 output = 'easyvend:depositor',
112 recipe = {
113 {'group:wood', 'default:steel_ingot', 'group:wood'},
114 {'group:wood', 'default:steel_ingot', 'group:wood'},
115 {'group:wood', 'group:wood', 'group:wood'},
120 if minetest.get_modpath("doc_items") ~= nil then
121 doc.add_entry_alias("nodes", "easyvend:vendor", "easyvend:vendor_on")
122 doc.add_entry_alias("nodes", "easyvend:depositor", "easyvend:depositor_on")
123 doc.sub.items.set_items_longdesc({
124 ["easyvend:vendor"] = 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),
125 ["easyvend:depositor"] = 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),
127 doc.sub.items.set_items_usagehelp({
128 ["easyvend:vendor"] = "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.",
130 ["easyvend:depositor"] = "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.",