Difference between revisions of "GetM2DARowIdFromRowIndex"

From Dragon Age Toolset Wiki
Jump to: navigation, search
m (1 revision: re-import with default parameter value parameters set)
(Completing parameters, correcting category)
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{Generated with errors}}
 
 
{{dafunction
 
{{dafunction
 
|name=GetM2DARowIdFromRowIndex
 
|name=GetM2DARowIdFromRowIndex
|brief=Returns the row ID for the given row index
+
|brief=Returns ID for the given 2DA table and row index.
 
|param1type=int
 
|param1type=int
 
|param1name=n2DA
 
|param1name=n2DA
Line 13: Line 12:
 
|param3type=string
 
|param3type=string
 
|param3name=s2DA
 
|param3name=s2DA
|param3desc=
+
|param3desc=(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. 
 
|param3default=""
 
|param3default=""
 
|returntype=int
 
|returntype=int
|returndesc=
+
|returndesc=The ID for the row specified by the parameters.
 
|sourcefile=script.ldf
 
|sourcefile=script.ldf
 
|sourcemodule=
 
|sourcemodule=
Line 23: Line 22:
 
== Description ==
 
== Description ==
 
<!-- This section contains the full description from the functions comments. Do not change unless you are confident these are incomplete or incorrect. -->
 
<!-- This section contains the full description from the functions comments. Do not change unless you are confident these are incomplete or incorrect. -->
Returns the value of the ID column for the given 2DA row index
+
Returns the value of the ID column for the given 2DA table and row index.
 
+
<!--  
<!-- == Remarks == -->
+
== Remarks == -->
 
<!-- This section contains additional comments, observations and known issues. -->
 
<!-- This section contains additional comments, observations and known issues. -->
  
<!-- == Examples == -->
+
== Examples ==
 
<!-- This section contains examples transcluded from the snippet library. -->
 
<!-- This section contains examples transcluded from the snippet library. -->
 +
<dascript>
 +
// 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;
  
<!-- == See also == -->
+
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);
 +
 +
</dascript>
 +
<!--  
 +
== See also == -->
 
<!-- This section contains links to articles, functions or constant groups. -->
 
<!-- This section contains links to articles, functions or constant groups. -->
  
[[Category: Action & system functions]]
+
[[Category:Data functions]]

Revision as of 23:35, 4 March 2014

Returns ID for the given 2DA table and row index.

int GetM2DARowIdFromRowIndex(
int n2DA,
int nRowIndex,
string s2DA = ""
);
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);
}