Raocoin2.lua
The Raocoin2 library allows the creation of customisable currencies, which can be saved between plays. It also provides a built-in shop framework to allow these currencies to be used for various tasks.
Installation
Place the file raocoin2.lua and the folder named raocoin into the LuaScriptsLib folder.
How to use
To enable the Raocoin2 library for a specific set of levels, add this line to lunaworld.lua:
raocoin = loadSharedAPI("raocoin2");
Then, define a currency my registering either an NPC item to count, or a global memory address to reference. This example will count dragon coins, and display a UI element at the point (472, 66) (just under the score):
dragoncoins = raocoin.registerCurrency(274, true, 472, 66);
While this example will assign a reference to the existing HUD coin counter, allowing regular coins to be saved, loaded, and used as currency:
coins = raocoin.registerMemCurrency(0x00B2C5A8,FIELD_WORD,true,false);
Each of these functions returns a Currency object, which can be used to create shops and store values between plays.
Documentation
Constants
These are static values that should be treated as read-only
Classes
These are internal classes that you can create and access using the API
Currency
The Currency class stores and retains a value for the currencies that have been registered to the game. Currency objects are created using "registerCurrency" or "registerMemCurrency"
Fields
| CODE_CANTAFFORD | ErrorCode | Used by the "onBuyFail" event to pass information about the failure. |
|---|---|---|
| CODE_ALREADYBOUGHT | ErrorCode | Used by the "onBuyFail" event to pass information about the failure. |
| visible | boolean | Determines whether or not the currency will display a UI element. |
|---|---|---|
| img | LuaImageResource | Contains the image holding the currency's UI element. |
| x | number | The x-coordinate in screen space of the upper-left corner of the UI element. |
| y | number | The y-coordinate in screen space of the upper-left corner of the UI element. |
| path | string | The file path of the image contained in the "img" field. |
| id | number:read-only | The currency ID (for NPC-based currencies, this is the NPC ID. For mem-based currencies, this is the memory address). |
| type | number:read-only | The type of the currency. For NPC-based currencies, this is always -1. For mem-based currencies, this will hold the memory access type (e.g. "FIELD_WORD"). |
Functions
| Currency:refreshUI | |||||
|---|---|---|---|---|---|
| Reloads the UI image stored in "path". Call this if the image path changes. | nil | ||||
| Currency:get | |||||
| Returns the current value of this currency. | number | ||||
| Currency:set | value | ||||
| Sets the currency value, but does not save it to the disk. | nil | number
The value to set the currency to. | |||
| Currency:save | |||||
| Flushes the currency value to the disk, allowing it to be reloaded between levels and sessions. | nil | ||||
| Currency:addItem | price | actions | permanent | id | |
| Creates a new item that can be bought with this currency. | Item | number
The price of the item in this currency. |
function
The actions to execute when this item is bought, or when the level is loaded after buying it (provided "permanent" is true). |
boolean:optional
Whether the item should be a permanent purchase (buy once and keep forever, even across sessions) or a repeatable one. Defaults to true. |
number:optional
The ID of this specific item, used by the save system to ensure items' purchase state is correctly stored. Repeated IDs will share purchase state. |