Compare commits
9 Commits
49e529a96e
...
c7f0feb86d
Author | SHA1 | Date |
---|---|---|
Juraj Vajda | c7f0feb86d | |
Juraj Vajda | 000d66769b | |
Wuzzy | 9aca0379b7 | |
Wuzzy | fa14d27191 | |
Wuzzy | 1997fcde9a | |
Juraj Vajda | 592ea7996f | |
Juraj Vajda | efe49d481c | |
Juraj Vajda | db5512ba18 | |
Juraj Vajda | d32b48b241 |
4
API.md
4
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.
|
||||
|
|
|
@ -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.
|
||||
|
|
52
easyvend.lua
52
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
|
||||
|
||||
|
@ -229,9 +231,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
|
||||
|
@ -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)
|
||||
|
@ -1281,7 +1283,7 @@ minetest.register_abm({
|
|||
-- Transform the world and items to use the easyvend nodes/items
|
||||
|
||||
-- For safety reasons, only do this when player requested so
|
||||
if minetest.setting_getbool("easyvend_convert_vendor") == true then
|
||||
if minetest.settings:get_bool("easyvend_convert_vendor") == true then
|
||||
-- Replace vendor nodes
|
||||
minetest.register_lbm({
|
||||
name = "easyvend:replace_vendor",
|
||||
|
|
2
init.lua
2
init.lua
|
@ -25,7 +25,7 @@ easyvend.VERSION.PATCH = 3
|
|||
easyvend.VERSION.STRING = easyvend.VERSION.MAJOR .. "." .. easyvend.VERSION.MINOR .. "." .. easyvend.VERSION.PATCH
|
||||
|
||||
-- Set item which is used as payment for vending and depositing machines
|
||||
easyvend.currency = minetest.setting_get("easyvend_currency")
|
||||
easyvend.currency = minetest.settings:get("easyvend_currency")
|
||||
if easyvend.currency == nil or minetest.registered_items[easyvend.currency] == nil then
|
||||
-- Default currency
|
||||
easyvend.currency = "default:gold_ingot"
|
||||
|
|
Loading…
Reference in New Issue