LUA - Shop Tool Entity
Core Attributes
The following functions and properties are available all the time.
Functions
| Function Name | Description |
|---|---|
| interact(peon) | Interact with this shop tool entity, this function will then call the shop tool entity's interact meta-method |
| getNeededStockAmt() | Get the total number of missing stock items from reserved spaces in the shop tool entity's inventory |
| getNeededStock() | Return a table of the first missing stock item's id and how many more resources it needs to be full. |
| redrawStock() | Tell the shop tool entity to redraw all of it's children. Usually called after it's been interacted with. |
Properties
| Variable | Data Type | Description |
|---|---|---|
| pos | table | Get the world coordinates of the entity. t[1] = x, t[2] = y |
| needsStock | bool | Returns whether the shop tool entity needs restocking |
| inventory | Inventory | Returns the shop tool entity's inventory |
| uuid | int | Returns the full UUID of the entity. |
| id | int | Returns just the ID of the entity, extracted from the UUID |
| group | int | Returns just the group of the entity, extracted from the UUID |
| hasStock | bool | Returns whether or not there is at least 1 item in the shop tool entity |
| stockChanged | bool | When set to true, the shop tool entity will update it's displayed children |
Custom Attributes
The following are available only during the creation of a shop tool entity
Properties
| Variable | Data Type | Description |
|---|---|---|
| slots | int | |
| desc | string | |
| itemset | table | |
| cost | int | |
| buyable | bool | |
| texture | string | |
| role | ubyte | |
| name | string | |
| tag | string |
Functions
placeChild( childnum )
This function is called whenever the Shop Tool Entity updates it's children and doesn't already have a cached position for this specific child.
function shoptoolentity.placeChild(childnum)
local x = 10 + 8 * (childnum % 5)
local y = 10 + 8 * (childnum / 5)
return {x, y}
end
context(self)
This function is called whenever a Peon is selected and then this Shop Tool Entity is right clicked. We return a table of the actions that can be completed.
-- _restock & _transfer are both job creation functions
-- specified earlier in the shop file
function shoptoolentity:context()
local res = {}
res["Restock"] = _restock
res["More"] = {}
res["More"]["Transfer"] = _transfer
end
The example above would create the following menu
Fig(1) Example of a context menu in game
