-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16-merchant-merlin.lua
More file actions
43 lines (38 loc) · 1.02 KB
/
16-merchant-merlin.lua
File metadata and controls
43 lines (38 loc) · 1.02 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
-- Merchant Merlin
-- Codédex
inventory = {
potion = 5,
elixir = 3,
antidote = 10,
gold = 100,
silver = 250,
bronze = 500,
sword = 1,
shield = 1,
bow = 1,
arrows = 20
}
function sell_item(item, quantity)
if inventory[item] and inventory[item] >= quantity then
inventory[item] = inventory[item] - quantity
print("Sold " .. quantity .. " " .. item .. "(s). Remaining: " .. inventory[item])
else
print("Item " .. item .. " is unavailable or not enough stock.")
end
end
function restock_item(item, quantity)
if inventory[item] then
inventory[item] = inventory[item] + quantity
print("Restocked " .. quantity .. " " .. item .. "(s). Total: " .. inventory[item])
else
inventory[item] = quantity
print("Added new item " .. item .. " with quantity: " .. quantity)
end
end
-- Sell items
sell_item("potion", 2)
sell_item("elixir", 1)
sell_item("antidote", 5)
-- Restock items
restock_item("potion", 5)
restock_item("elixir", 3)