Go to file
Jordan Irwin 76f1874323 Fix shops from config not registering if product list is nil 2021-08-28 18:34:50 -07:00
.github/workflows Fix cloning wrong repo in workflow 2021-08-15 23:28:13 -07:00
.ldoc Increment version to 1.6.2 2021-08-26 15:15:03 -07:00
locale Fix Spanish translated string 2021-08-28 18:33:23 -07:00
textures Convert textures to indexed color 2021-08-15 16:38:07 -07:00
.gitattributes Add .gitattributes file 2021-08-15 16:26:40 -07:00
LICENSE.txt Initial commit 2021-04-26 03:49:51 -07:00
README.md Update README 2021-08-18 02:46:27 -07:00
TODO.txt Fix shops from config not registering if product list is nil 2021-08-28 18:34:50 -07:00
api.lua Fix shops from config not registering if product list is nil 2021-08-28 18:34:50 -07:00
changelog.txt Fix shops from config not registering if product list is nil 2021-08-28 18:34:50 -07:00
command.lua Add more details to chat command help 2021-08-28 13:37:07 -07:00
deposit.lua Store buyer shop deposit info in player meta to persist through... 2021-08-28 11:43:30 -07:00
formspec.lua Increase "buy" dropdown quantities to include 1-10 2021-08-28 17:01:27 -07:00
init.lua Update config file after pruning at startup 2021-08-27 17:30:11 -07:00
mod.conf Increment version to 1.6.2 2021-08-26 15:15:03 -07:00
node.lua Update for simple_models v2021-08-26 2021-08-26 15:14:14 -07:00
screenshot.png Add buyer shops 2021-05-14 13:16:48 -07:00
set_version.py LDoc: use string version so trailing 0s don't get trimmed 2021-08-23 14:10:49 -07:00
settings.lua Update docstrings 2021-08-15 23:05:22 -07:00
settingtypes.txt add setting to disable auto-refunding on formspec close 2021-06-10 14:18:14 -07:00
transaction.lua Store buyer shop deposit info in player meta to persist through... 2021-08-28 11:43:30 -07:00

README.md

Server Shops

Description:

Shops intended to be set up by Minetest server administrators.

No craft recipe is given as this for administrators, currently a shop can only be set up with the /giveme command. The two shop nodes are server_shop:shop_small & server_shop:shop_large (they function identically).

screenshot

Usage:

Registering Shops via API:

There are two types of shops, seller & buyer. A seller shop can be registered with server_shop.register_seller(id, name, products). A buyer with server_shop.register_buyer(id, name, products). id is a string identifier associated with the shop list. name is a human-readable string that will be displayed as the shop's title. products is the shop list definition. Shop lists are defined in a table of tuples in {itemname, value} format. itemname is the technical string name of an item (e.g. default:wood). value is the number representation of what the item is worth.

Example:

-- register seller
server_shop.register_seller("frank", "Frank's Shop", {{"default:wood", 2}})

-- register buyer
server_shop.register_buyer("julie", "Julie's Shop",  {
	{"default:copper_lump", 5},
	{"default:iron_lump", 6},
})

Registering Shops via Configuration:

Shops can optionally be configured in <world_path>/server_shops.json file. To register a shop, set type to "sell" or "buy". id is a string identifier for the shop. name is the string displayed in the formspec & when a player points at the node. products is an array of products sold at the shop in format "name,value".

Example:

[
  {
    "type":"sell",
    "id":"frank",
    "name":"Frank's Shop",
    "products":[["default:wood",2]]
  },
  {
    "type":"buy",
    "id":"julie",
    "name":"Julie's Shop",
    "products":
    [
      ["default:copper_lump",5],
      ["default:iron_lump",6],
    ]
  },
]

Registering Shops via Chat Command:

The server_shop chat command is available to administrators with the server privilege. This is used for administering shops & updating configuration.

Usage:

/server_shop <command> [<params>]

# Commands:

/server_shop reload
- reloads data from configuration file

/server_shop register <id> <type> <name> [product1=value,product2=value,...]
- registers a shop & updates configuration file
- parameters:
  - id: shop identifier
  - type: can be "buy" or "sell"
  - name: displayed shop name ("_" is replaced with " ")
	- product list: comma-separated list in format "item=value"

/server_shop unregister <id>
- unregisters a shop & updates configuration file
- parameters:
  - id: shop identifier

Registering Currencies:

Currencies can be registered with server_shop.register_currency:

server_shop.register_currency("currency:minegeld", 1)
server_shop.register_currency("currency:minegeld_5", 5)

When registering new currencies in server_shops.json, set type to "currencies". value is a table of item names & worth:

	{
		"type":"currencies",
		"value":
		{
			"currency:minegeld":1,
			"currency:minegeld_5":5,
		},
	},

You can also register a currency suffix to be displayed in the formspec. Simply set the string value of server_shop.currency_suffix:

server_shop.currency_suffix = "MG"

In server_shops.json, set type to "suffix" & value to the string to be displayed:

	{
		"type":"suffix",
		"value":"MG",
	},

By default, if the currency mod is installed, the minegeld notes will be registered as currency. This can be disabled by setting server_shop.use_currency_defaults to false in minetest.conf.

Setting up Shops in Game:

Server admins use the chat command /giveme server_shop:shop_small or /giveme server_shop:shop_large to receive a shop node. After placing the node, the ID can be set with the "Set ID" button & text input field (only players with the "server" privilege can set ID). Set the ID to the registered shop ID you want associated with this node ("frank" or "julie" for the examples above) & the list will be populated with the registered products & prices.

Using Seller Shops:

To make purchases, player first deposits registered currency items into the deposit slot. Select an item in the products list & press the "Buy" button. If there is adequate money deposited, player will receive the item & the cost will be deducted from the deposited amount. To retrieve any money not spent, press the "Refund" button. If the formspec is closed while there is still a deposit balance, the remaining money will be refunded back to the player. If there is not room in the player's inventory, the remaining balance will be dropped on the ground.

Using Buyer Shops:

For buyer shops, the product list shows what items can be sold to this shop & how much money a player will receive for each item. To sell to the shop, place an item in the deposit slot. The slot will only accept items that the owner will purchase. Press the "Sell" button to recieve the value of the item(s).

Licensing:

  • Code: MIT
  • Textures: CC0

Dependencies:

  • Required:
    • simple_models
    • wdata
  • Optional: