ResManGetAliasFor(string, int)

From NWN Lexicon
Jump to: navigation, search
Nwnee logo.jpg Note: This article documents Neverwinter Nights: Enhanced Edition new content or changes/updates/fixes to 1.69 functions. These are all listed under the category and patches pages.

Returns the resource location of sResRef.nResType, as seen by the running module.

string ResManGetAliasFor(
    string sResRef,
    int nResType


blueprint resref to query location
blueprint RESTYPE constant for the blueprint resref


Returns the resource location of sResRef.nResType, as seen by the running module.

Returns "" if the resource does not exist in the search space.

Note for dedicated servers: Checks on the module/server side, not the client.


This is an immensely useful function to check for the presence of a blueprint resref for CreateObject, a particular item part for CopyItemAndModify, creature body parts for SetCreatureBodyPart or any form of JSON creation of items/creatures/placeables in combination with Get2DAString calls.

Note you cannot read metadata from the resource (eg; the textures in use by a model) for instance for SetTextureOverride.


This function was added in 1.85.8193.31 of NWN:EE.


// Helper  function see below.
string IntToPaddedString(int nX, int nLength = 4, int nSigned = FALSE);
// See if the given Human, Male, Phenotype 0 head model exists, since there is no 2da file to determine valid heads
// We then set our head to that appearance
void main()
    // Does the given head ID exist?
    int nHead = 10;
    // Full name in this example is "pmh0_head010"
    if(ResManGetAliasFor("pmh0_head" + IntToPaddedString(nHead, 3), RESTYPE_MDL) != "")
        SetCreatureBodyPart(CREATURE_PART_HEAD, nHead, OBJECT_SELF);
// Converts the given integer to string as IntToString and then pads the left side until
// it's nLength characters long. If sign is specified, the first character is reserved
// for it, and it is always present.
// Strings longer than the given length are truncated to their nLength right characters.
// Examples:
//  IntToPaddedString(-15, 4, FALSE) = "0015"
//  IntToPaddedString(-15, 4, TRUE)  = "-015"
string IntToPaddedString(int nX, int nLength = 4, int nSigned = FALSE)
        nLength--; // To allow for sign
    string sResult = IntToString(nX);
    // Trunctate to nLength rightmost characters
    if(GetStringLength(sResult) > nLength)
        sResult = GetStringRight(sResult, nLength);
    // Pad the left side with zero
    while(GetStringLength(sResult) < nLength)
        sResult = "0" + sResult;
        if(nX >= 0)
            sResult = "+" + sResult;
            sResult = "-" + sResult;
    return sResult;

See Also

functions: TemplateToJson() ResManFindPrefix()