forked from ChimneySwift/fancy_vend
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctions.lua
More file actions
106 lines (93 loc) · 3.03 KB
/
functions.lua
File metadata and controls
106 lines (93 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function fancy_vend.send_message(pos, channel, msg)
if channel and channel ~= "" then
digilines.receptor_send(pos, digilines.rules.default, channel, msg)
end
end
function fancy_vend.set_vendor_settings(pos, SettingsDef)
local meta = core.get_meta(pos)
meta:set_string("settings", core.serialize(SettingsDef))
end
function fancy_vend.reset_vendor_settings(pos)
local settings_default = {
input_item = "", -- Don't change this unless you plan on setting this up to add this item to the inventories
output_item = "", -- Don't change this unless you plan on setting this up to add this item to the inventories
input_item_qty = 1,
output_item_qty = 1,
admin_vendor = false,
depositor = false,
currency_eject = false,
accept_output_only = false,
split_incoming_stacks = false,
inactive_force = false,
accept_worn_input = true,
accept_worn_output = true,
digiline_channel = "",
co_sellers = "",
banned_buyers = "",
auto_sort = false,
}
fancy_vend.set_vendor_settings(pos, settings_default)
return settings_default
end
function fancy_vend.get_vendor_settings(pos)
local meta = core.get_meta(pos)
local settings = core.deserialize(meta:get_string("settings"))
if not settings then
return fancy_vend.reset_vendor_settings(pos)
else
-- If settings added by newer versions of fancy_vend are nil then send defaults
if settings.auto_sort == nil then
settings.auto_sort = false
end
-- Sanitatize number values (backwards compat)
settings.input_item_qty = (
type(settings.input_item_qty) == "number" and
math.abs(settings.input_item_qty) or 1
)
settings.output_item_qty = (
type(settings.output_item_qty) == "number" and
math.abs(settings.output_item_qty) or 1
)
return settings
end
end
function fancy_vend.can_buy_from_vendor(pos, player)
local player_name = player:get_player_name()
local settings = fancy_vend.get_vendor_settings(pos)
local banned_buyers = string.split((settings.banned_buyers or ""), "[, ]+", false, nil, true)
for _, name in pairs(banned_buyers) do
if name == player_name then
return false
end
end
return true
end
function fancy_vend.can_modify_vendor(pos, player)
local meta = core.get_meta(pos)
local is_owner = false
if meta:get_string("owner") == player:get_player_name() or
core.check_player_privs(player, {protection_bypass = true}) then
is_owner = true
end
return is_owner
end
function fancy_vend.can_dig_vendor(pos, player)
local inv = core.get_meta(pos):get_inventory()
return inv:is_empty("main") and fancy_vend.can_modify_vendor(pos, player)
end
function fancy_vend.can_access_vendor_inv(player, pos)
local player_name = player:get_player_name()
local meta = core.get_meta(pos)
if core.check_player_privs(player, {protection_bypass = true}) or
meta:get_string("owner") == player_name then
return true
end
local settings = fancy_vend.get_vendor_settings(pos)
local co_sellers = string.split((settings.co_sellers or ""), "[, ]+", false, nil, true)
for _, name in pairs(co_sellers) do
if name == player_name then
return true
end
end
return false
end