Skip to main content

Shop System

These functions and properties are members of Shop instances. Create a Shop instance using the Shop function.

The general procedure to display an interactive shop is as follows:

  1. Load a shop's data using the Shop function
  2. Check the RestockRequired property. If it returns true, you should:
    • Call RemoveDefaultStock() to erase the previous stock,
    • Add fresh items using AddItem(),
    • Finally, call MarkRestocked().
  3. Call Show() to display to the player
  4. Call Save() to save the shop

You do not need to call Show() per se. It is fine to load, modify and save a shop if you only wish to modify stock (such as when adding a unique item from someplace else).

caution

If you Save() the shop before you Show() it, the player's changes will not be committed to save data, since they will modify it after you saved it. This may or may not be what you want.

Shop
key
  • key (string) - the unique internal name of this shop
  • (Shop) - a new Shop instance
Creates and returns a new Shop instance. If a Shop with the same key was ever saved before, that data will be loaded. Otherwise, an empty shop template is returned.
shop.
Key
  • string - read-only
The internal name that uniquely identifies this shop. This is the same string you passed to the Shop function.
shop.
Title
  • string - read/write
The text describing the shop, that is displayed at the top of the shop screen.
shop.
RestockInterval
  • number - read/write
The number of in-world hours between restocks. If this number of hours elapse on the in-game clock since RestockLastTime, RestockRequired will be flipped to true.
shop.
RestockRequired
  • boolean - read-only
Indicates whether you should take action to restock the shop. The game sets this to true when RestockInterval elapses, or when a new shop is created. To set it back to false, call MarkRestocked().
shop.
RestockLastTime
  • number - read-only
The timestamp in world hours at which the shop was last marked as restocked. Use the global function GetTimeHourTotal() to compare against.
shop:
Save
Saves the state of this shop. Any future calls to Shop() with this shop's key will return the data as it was at the moment this function was called.
shop:
Show
Opens the shop for the player. The running script will be paused until the player exits the shop screen.
shop:
RemoveDefaultStock
Removes items that are not unique items from the shop's stock.
shop:
RemoveAll
Removes all items from the shop's stock, including unique items.
shop:
AddItem
item
quantity
  • item (Item) - the item template to stock
  • quantity (number) - copies in stock. -1 means unlimited stock.
Adds an item to the shop's stock. This stack will be considered part of the shop's normal stock.
shop:
AddUniqueItem
item
quantity
  • item (Item) - the item template to stock
  • quantity (number) - copies in stock. -1 means unlimited stock.
Adds an item to the shop's stock. This stack will not be removed when calling RemoveDefaultStock(), and thus could be used to for example add a new quest-related item to a shop, without risking it getting removed when the shop restocks.
shop:
MarkRestocked
Updates the RestockLastTime to the current time, and clears the RestockRequired flag.