SetTlkOverride(int, string)

From NWN Lexicon
Revision as of 19:06, 12 March 2021 by Jasperre (talk | contribs) (Created page with "{{DISPLAYTITLE:SetTlkOverride(int, string)}}__NOTOC__ Overrides a given string reference so something else is shown. <nwscript> void SetTlkOverride( int nStrRef, strin...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Overrides a given string reference so something else is shown.

void SetTlkOverride(
    int nStrRef,
    string sValue=""
);

Parameters

nStrRef
String reference to replace
sValue
String to use, if blank it resets it to default (default: "")


Description

Overrides a given strref to always return sValue instead of what is in the TLK file.

Setting sValue to "" will delete the override

You can use GetStringByStrRef to get what is currently reported by that nStrRef ID. It returns the overriden string if it has already been altered.


Remarks

This is amazing for replacing hardcoded TLK lines; in game feedback, formatting of messages if you've altered rules. You could even replace specific messages in specific circumstances - see example. If the game requests a <CUSTOM0> or similar in the original string this may include additional formatting (eg colouring for EffectDamage messages).

Experimentation may be needed to know when to time this (if you want it to alter depending on the event) or if it loads fast enough for character creation GUI changes. Provide feedback and this article will be updated once these are tested.

A sample of lines you might want to override are available here and what TLK files are here.

Since a blank string will delete the override, use a space or a blank string in color codes to blank it entirely - however the game still uses a new line character so a blank line will appear in the chat log.

// Space 
string sSpace = " ";
// Blank character - but has colour code values so is valid for override
string sBlank = "<c123></c>";

Some events directly precede the feedback message - such as OnFailedToOpen in the example below - but this might not always be the case. If you only want some temporary feedback changes like this see the example for a single door that feeds back a better message than "This door is locked.".

Version

To follow - NWN:EE.


Example

// Sample OnFailedToOpen we replace the message just for this door by resetting it afterwards
void main()
{
    SetTlkOverride(8296, "This is locked and has no keyhole. Maybe a mechanism nearby will open it.");
 
    // Reset to default for all other doors. Must be longer than 0.0 (so the engine can send that string before we reset it) so we use 0.1.
    DelayCommand(0.1, SetTlkOverride(8296));
}

See Also

functions:

GetStringByStrRef