Modding: Difference between revisions

From APICO Wiki
Jump to navigation Jump to search
Content added Content deleted
No edit summary
No edit summary
Line 11: Line 11:
<h1>api_define_item()</h1>
<h1>api_define_item()</h1>


<div class="aw-code">{{Method|method=api_define_item|param1=mod_name|param2=definition|param3=sprite_image|desc=This allows you to define a new Item for the game and add it to the Dictionary}}{{Parameter|param=mod_name|datatype=String|desc=the name of your mod, the same as your mod folder, i.e. "sample_mod"}}{{Parameter|param=definition|datatye=Table|desc=the item definition with the following keys:|
<div class="aw-code">{{Method|method=api_define_item|param1=mod_name|param2=definition|param3=sprite_image|desc=This allows you to define a new Item for the game and add it to the Dictionary}}{{Parameter|param=mod_name|datatype=String|desc=the name of your mod, the same as your mod folder, i.e. "sample_mod"}}{{Parameter|param=definition|datatype=Table|desc=the item definition with the following keys:|
key1=id|key1_datatype=String|key1_req|key1_desc= a unique identifier for the item. This will be prepended with "mod_name_"|
key1=id|key1_datatype=String|key1_req|key1_desc= a unique identifier for the item. This will be prepended with "mod_name_"|
key2=name|key2_datatype=String|key2_req|key2_desc=a name for the item that will be shown in tooltips|
key2=name|key2_datatype=String|key2_req|key2_desc=a name for the item that will be shown in tooltips|

Revision as of 15:38, 4 August 2021

This is a WIP page that I'm using to document the game's modding API as I go

Dictionary Info here

api_log()

@method api_log(mod_name, func, message)
@parameter mod_name {String} - the name of your mod, the same as your mod folder, i.e. "sample_mod"
@parameter func {String} - the name of the method calling this log, shown in the console
@parameter message {String} - the message to show in the console
@return {Nil}

api_define_item()

@method api_define_item(mod_name, definition, sprite_image)
@parameter mod_name {String} - the name of your mod, the same as your mod folder, i.e. "sample_mod"
@parameter definition {Table} - the item definition with the following keys:

id {String} - a unique identifier for the item. This will be prepended with "mod_name_"
name {String} - a name for the item that will be shown in tooltips
category {String} - a category for the item that will be shown in tooltips
tooltip {String} - a tooltip description for the item that will be shown in tooltips
shop_buy {Decimal} - a buying price for the item if this item was to be bought
shop_sell {Decimal} - a selling price for item if this item was to be sold
shop_key {Boolean} - whether this is a key item which means it can't be sold
machines {Array} - a list of machine this item can be used in i.e. ["workbench", "sawbench"]
durability {Integer} - if this item is a tool that gets used up you can specify a total durability here
singular {Boolean} - if true then this item will not be able to be stacked
placeable {Boolean} - whether this item can be placed - if specified you must also give an "obj" key
place_grass {Boolean} - if placeable, this specifies the item can only be placed on grass only
place_water {Boolean} - if placeable, this specifies the item can be placed on shallow water
place_deep {Boolean} - if placeable, this specifies the item can be placed on deep water
obj {String} - if placeable, this specifies the object that will be created when the item is placed. If this is not a different object id, you should be making an Object instead of an Item
honeycore {Boolean} - specifies whether this item will buy/sell for Honeycore instead of Rubees

@return {String} - either your new item's id (i.e. "sample_mod_item_name") or nil if there was an error




This is needed before you can spawn the item in, add it to recipes, or use it with machines.

The sprite you use needs to be a 60x16px image within your mods resources, made up of 4 frames (normal, highlighted, undiscovered, undiscovered + highlighted). The sprite will be loaded virtually and used automatically when drawing your item.

Once you've created an item with this method you'll be able to access your sprite reference with TODO if you need it during a custom draw call. You'll also be able to directly get the definition from the dictionary with TODO

If there are any errors while trying to define an item you'll see one of the following codes logged in the Modding Console

Error: Missing Required Key (KEY)
This means one of the required keys above was missing from your definition parameter
Error: ID Already Defined
This means the id key provided is already in the Dictionary, either it's already used or you defined the item twice.
Error: Failed To Map Keys
This means one of your keys couldn't be mapped properly - possible a null value.
Error: Failed To Add Sprite
This means your sprite couldn't be added, either an incorrect format or file not found