Getting Spell Names from SpellID (SOLVED)

Has anyone had any success in either easily getting a spell name from a spell ID or made a script that relates these?
reason - I am messing around with the brew potion and craft wand bits in the “x2_inc_craft” and I found a place to rename the crafted potion or wand to have a new name. In the vanilla system, they are called “magic potion” and “magic wand”. However, I am seeing if anyone has a script that returns the Spell Name from the SpellID before I devote a section of my quarantine to doing it myself.
For example, I create a switch(nID) and then have each “SPELL_” as a case returning the string with the appropriate name.

this has been convenient for me (nwn2 but i think it’s the same in 1)

string GetSpellName(int iSpellId)
    int iStrref = StringToInt(Get2DAString("spells", "Name", iSpellId));
    return GetStringByStrRef(iStrref);
1 Like

Unless there is a version of that amongst the new spells for EE, GetSpellName() is not a built-in script for NwN 1. Don’t panic though. Looking in the downloadable version of the Lexicon (only covers up to 1.69) reveals this -

//Function to get the name of a spell

string GetSpellName(int nSpell)
    //Look up the StrRef as a string in spells.2da

    string sStrRef = Get2DAString("spells", "Name", nSpell);

    //Convert to an integer

    int nStrRef = StringToInt(sStrRef);

    //Look up the name in the dialog.tlk file

    string sName = GetStringByStrRef(nStrRef);

    //return the spell's name

    return sName;

//Example of using the function above

void main()
    //The spell that triggered this OnSpellCastAt event

    int nSpell = GetLastSpell();
    string sName = GetSpellName(nSpell);

    //I'm so funny

    SpeakString("Don't you dare cast " + sName + " at me!!!");
    ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDeath(), GetLastSpellCaster());


1 Like

it’s not in 2 either. I wrote it … looks identical to GetSpellName() tho – it is ofc the routine of stock functions that’s important: get strref from 2da, then the string from the talktable

This is exactly what I was looking for! I wasn’t sure how to pull the 2DA string. Thank you!

This is exactly what I was looking for. Thanks!

1 Like