Raocoin.lua

From Moondust Wiki
Revision as of 14:20, 3 November 2014 by Hoeloe (talk | contribs) (Created page with "[https://dl.dropboxusercontent.com/u/30847069/ShopLibrary.zip Download Latest Version] The Raocoin library allows for dragon coins to be saved between levels, and used for sh...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Download Latest Version

The Raocoin library allows for dragon coins to be saved between levels, and used for shop systems.

Installation

Place the file raocoin.lua and the folder named raocoin into the LuaScriptsLib folder.


How to use

To enable the Raocoin library for a specific set of levels, add this line to lunaworld.lua:

   local raocoin = loadAPI("raocoin");

This will load the Raocoin API, and begin counting and storing dragon coins.


Creating a shop requires a little more Lua code. The example in the download uses the Triggers.lua library to activate shop items, but this is not necessary.


Example

   local raocoin = loadAPI("raocoin");
   
   raocoin.items[0] = raocoin.shopItem(-199900, -199836, -200448, -200160, 3, "BonusContent", function() triggerEvent("AccessContent") end);

This will create a new shop item, which will display its price when the player is within the box defined by the first 4 values. It will cost 3 dragon coins, save the purchase under the variable name "BonusContent" (which allows purchases to remain after the game is shut down), and will execute Lua code which triggers a SMBX event called "AccessContent" when bought.


Documentation

Values

These are variables you can access

imageID number Contains the resource ID of the Raocoin GUI item. Changing this value will not immediately result in the image changing unless it is refreshed by calling setImagePath.
GUIPosition table(number) The position of the Raocoin GUI item. Changing this value will not result in the image changing position. Use it as a reference only. Contains fields x and y.
items table(shopItem) Contains a list of current shop items. Initially empty. Add values to this to create shops.

Structures

shopItem l r u b price savename acts
number

The left side of the price display collision box.

number

The right side of the price display collision box.

number

The top side of the price display collision box.

number

The bottom side of the price display collision box.

number

The price of the item.

string

The global user variable to save the purchase under.

function

The actions to perform when the item is purchased, or the level is loaded after previously buying the item.


External Use Functions

These are functions you will need to use the library

currentRaocoins
Returns the current number of dragon coins the player possesses. number
setImagePath path
Changes the file path of the raocoin GUI image. This should rarely be used. nil string

The file path, beginning at the level folder, in which to find the file raocoin.bmp.

getImagePath
Returns the path of the raocoin GUI image. By default, this is ../../../LuaScriptsLib/raocoin/. string
shopItem left right top bottom price varname actions
Creates a new shop item, which displays its price when the player is in the defined rectangle, saves the purchase into global user variables under varname, and performs actions when purchased or a purchase is loaded from the user variables. shopItem number

The left side of the price display collision box.

number

The right side of the price display collision box.

number

The top side of the price display collision box.

number

The bottom side of the price display collision box.

number

The price in dragon coins of the item.

string

The variable name to save this purchase under global user variables. This should be unique, to avoid clashing with variables saved by other levels.

function

The actions to execute when the item is bought, or when the level is loaded and the item has been bought previously.

buyItem item
Checks if the player can afford the specified item, and if so, buys it, deducts the necessary dragon coins, and saves the purchase. nil shopItem

The item to purchase.

canAfford item
Checks if the player can afford the specified item. boolean shopItem

The item to check.


Internal Use Functions

These are functions that the library uses to function, but are not necessary for the user

onInitAPI
Registers the API events. nil
init
Initialises the library. nil
update
Updates the library each frame. nil