Help with custom "polymorph" spell

Hi! First of all I don’t really know what I’m doing.

I’m trying to make a custom “polymorph” spell using SetCreatureAppearanceType instead of a polymorph effect cause the latter changes the appearance only as far as I understand. So I took warlock’s Word of Changing script and I’m trying my best to change it somehow into SetCreatureAppearanceType using int nAppearanceType but nothing seems to work. I was able to somehow change the duration time and add it properly to spells.2da… but that’s it.

I’m not a scripter so my knowledge is pretty minimal to say it lightly. It’s for roleplaying reasons only, I’m trying my best to give my drow wizard an illusion spell to pass as a sun elf but… well nothing works.

Here’s my script (I’m really sorry, I know it’s a total mess), would you be so king and help me with it? I would be grateful for any help.

#include "x2_inc_spellhook"
#include "nwn2_inc_metmag"

void main()
{


    if (!X2PreSpellCastCode())
    {
        // If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell
        return;
    }


    //Declare major variables
    int nSpell = GetSpellId();
	    int nCasterLvl = GetTotalLevels(OBJECT_SELF, 1) * 20; //GetCasterLevel(OBJECT_SELF);
	if(nCasterLvl < 3)
	{
		nCasterLvl = 20;
	}
    object oTarget = GetSpellTargetObject();
    effect eVis = EffectVisualEffect(VFX_HIT_SPELL_DISPLACEMENT);
    effect ePoly;
    int nAppearanceType;
    int nMetaMagic = GetMetaMagicFeat();
    //Enter Metamagic conditions
	float fDuration = TurnsToSeconds(nCasterLvl * 90);
    fDuration = ApplyMetamagicDurationMods( fDuration );

    //Determine Polymorph subradial type 
    {
        nAppearanceType = Elf,Sun;
    }


    ePoly = EffectPolymorph(nAppearanceType);
    ePoly = EffectLinkEffects(ePoly, eVis);
    //Fire cast spell at event for the specified target
    SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, nSpell, FALSE));

    //Apply the VFX impact and effects
    //ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVis, GetLocation(oTarget));
    DelayCommand(0.4, AssignCommand(oTarget, ClearAllActions())); // prevents an exploit
    DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, ePoly, oTarget, fDuration));
}
// 'rhianna_poly'
/*
    Spellscript that changes target's appearance-type to SunElf for 10 min per
    casterlevel.
*/

#include "x2_inc_spellhook"
#include "nwn2_inc_metmag"

//
void main()
{
    if (!X2PreSpellCastCode())
        return;


    object oTarget = GetSpellTargetObject();
    if (GetIsObjectValid(oTarget) && GetObjectType(oTarget) == OBJECT_TYPE_CREATURE)
    {
        object oCaster = OBJECT_SELF;
        int iSpellId = GetSpellId();

        SignalEvent(oTarget, EventSpellCastAt(oCaster, iSpellId, FALSE));

        effect eHit = EffectVisualEffect(VFX_HIT_SPELL_DISPLACEMENT);
        ApplyEffectToObject(DURATION_TYPE_INSTANT, eHit, oTarget);


        int iType = GetAppearanceType(oTarget);

        SetCreatureAppearanceType(oTarget, 565); // SunElf id in Appearance.2da


        float fDur = TurnsToSeconds(GetCasterLevel(oCaster) * 10); // 10 min per casterlevel
              fDur = ApplyMetamagicDurationMods(fDur);

        AssignCommand(oTarget, DelayCommand(fDur, SetCreatureAppearanceType(oTarget, iType)));
    }
}

I tested this briefly on a few of my party by replacing Light’s impactscript.

results were kinda random. Some creatures made the change okay, others disappeared
into the floor or were offset from their capes by a couple meters … Actually
he left his sword and shield behind (stationary, mid-air) but could wander around
as a cape with a helmet on the floor … it’s hard to describe.

i didn’t have a Drow to test