GetM2DARowIdFromRowIndex
From Dragon Age Toolset Wiki
Revision as of 23:35, 4 March 2014 by Sunjammer (Talk | contribs) (Completing parameters, correcting category)
Returns ID for the given 2DA table and row index.
- Parameters:
- n2DA
- The 2DA to access
- nRowIndex
- Index in the 2DA for which we want to know the ID
- s2DA
- (optional) if n2da is -1 and this is a valid resource, it will retrieve the 2da based on the name instead of the index. Note that this should be avoided when possible.
- Returns:
- The ID for the row specified by the parameters.
- Source:
- script.ldf
Description
Returns the value of the ID column for the given 2DA table and row index.
Examples
// The crafting recipes M2DA contains 78 rows with ID from 0 to 91. There are gaps in the sequence // and we cannot predict where they appear. Looping over every row to find out would be inefficient, // however we can use the GetM2DARows function to tell us how many actual rows there are and then // use GetM2DARowIdFromRowIndex to convert the row number into the entry's ID number. const int TABLE_CRAFTING_RECIPES = 144; object CreateRandomCraftedItemOnObject(object oTarget) { // get the total number of rows in the crafting recipes M2DA (this works across all fragments) int nRows = GetM2DARows(TABLE_CRAFTING_RECIPES); // the Random function gives a number between 0 and nRows - 1 however as the first row is // invalid and the last row is a lyrium potion we actually want a number between 1 adn nRows int nRandomRow = Random(nRows) + 1; // in order to use the other GetM2DAResource we need the entry's ID number int nId = GetM2DARowIdFromRowIndex(TABLE_CRAFTING_RECIPES, nRandomRow); // read the crafted item's resource from the ItemCreated colum using entry's ID number resource rItem = GetM2DAResource(TABLE_CRAFTING_RECIPES, "ItemCreated", nId); // create the crafted item on the target object return CreateItemOnObject(rItem, oTarget); }