I’ve tested many times now, but for some inexplicable reason this doesn’t work. It only partly works. I don’t know what I’m doing wrong.
Ok, this will contain spoilers for a side quest in my upcoming module A Strange World III, so if you don’t want to be spoiled, you have been warned.
I have a scene where I have a wizard. This wizard is transformed (polymorphed) into a water elemental. At first when entering this area I have a script that polymorphs the wizard and then makes him script hidden. This script I found at the NWN Script Archive and modified it a bit. This works perfectly:
void main()
{
object oNPC = GetObjectByTag("element_npc");
//object oPC = GetEnteringObject();
//if(!GetIsPC(oPC)) return;
effect eVis = EffectVisualEffect (VFX_FNF_SUMMON_UNDEAD);
eVis = SetEffectSpellId(eVis, 9996);
DelayCommand(1.0, ApplyEffectAtLocation (DURATION_TYPE_INSTANT, eVis, GetLocation(oNPC)));
effect eShape = EffectPolymorph (POLYMORPH_TYPE_HUGE_WATER_ELEMENTAL);
DelayCommand(1.0, ApplyEffectToObject (DURATION_TYPE_PERMANENT, eShape, oNPC));
DelayCommand(2.0, SetScriptHidden(oNPC,TRUE));
}
Then at a certain point he is made visible again (not script hidden) and attacks the party. This works too. Then we come to the stuff that doesn’t work properly. I have a script on his OnDamage. When he gets below 15 HP, he’s immortal by the way, the polymorphed effect is supposed to disappear and then I want him to get knocked down, and lastly a conversation is to be triggered. Here’s my OnDamage script:
//:: Created By: Preston Watamaniuk
//:: Created On: Oct 16, 2001
//:://////////////////////////////////////////////
#include "hench_i0_ai"
#include "ginc_behavior"
#include "ginc_ipspeaker"
void RemoveElementalEffect()
{
object oElementalMan = OBJECT_SELF;
string sTag = GetTag(oElementalMan);
if (GetIsObjectValid(oElementalMan))
{
effect eSearch = GetFirstEffect(oElementalMan);
while (GetIsEffectValid(eSearch))
{
if (GetEffectSpellId(eSearch) == 9996) //your custom spell id
{
RemoveEffect(oElementalMan, eSearch);
eSearch = GetFirstEffect(oElementalMan); //safety (removing an iterator from the list)
}
else
eSearch = GetNextEffect(oElementalMan);
}
}
}
void main()
{
object oPC = GetFirstPC();
object oElementalMan = OBJECT_SELF;
string sTag = GetTag(oElementalMan);
//object oNPC = GetObjectByTag("assates");
int iHp = GetCurrentHitPoints(OBJECT_SELF);
if (iHp < 15 )
{
SetGlobalInt("elementaldead",1);
RemoveElementalEffect();
//AssignCommand(oElementalMan, ClearAllActions(TRUE));
effect eFX = EffectKnockdown();
DelayCommand(1.f, ApplyEffectToObject(DURATION_TYPE_PERMANENT, eFX, oElementalMan));
ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_COMMONER);
//AssignCommand(OBJECT_SELF, ClearAllActions(TRUE));
CreateIPSpeaker("kentharuil", "c_ne_pit_conv", GetLocation(oPC), 0.5f);
//AssignCommand(oPC, ClearAllActions(TRUE));
//SetCommandable(TRUE, oPC);
}
int iFocused = GetIsFocused();
// I've been damaged so no longer partially focused
if (iFocused == FOCUSED_PARTIAL)
{
SetLocalInt(OBJECT_SELF, VAR_FOCUSED, FOCUSED_STANDARD); // no longer focused
}
if (iFocused == FOCUSED_FULL)
{
// remain focused
}
else if(GetFleeToExit())
{
// We're supposed to run away, do nothing
}
else if (GetSpawnInCondition(NW_FLAG_SET_WARNINGS))
{
// don't do anything?
}
else
{
object oDamager = GetLastDamager();
if (!GetIsObjectValid(oDamager))
{
// don't do anything, we don't have a valid damager
}
else if (!GetIsFighting(OBJECT_SELF))
{
if ((GetLocalInt(OBJECT_SELF, HENCH_HEAL_SELF_STATE) == HENCH_HEAL_SELF_WAIT) &&
(GetPercentageHPLoss(OBJECT_SELF) < 30))
{
// force heal
HenchDetermineCombatRound(OBJECT_INVALID, TRUE);
}
else if (!GetIsObjectValid(GetAttemptedAttackTarget()) && !GetIsObjectValid(GetAttemptedSpellTarget()))
{
// Jug_Debug(GetName(OBJECT_SELF) + " responding to damage");
if (GetBehaviorState(NW_FLAG_BEHAVIOR_SPECIAL))
{
HenchDetermineSpecialBehavior(oDamager);
}
else
{
HenchDetermineCombatRound(oDamager);
}
}
}
}
if(GetSpawnInCondition(NW_FLAG_DAMAGED_EVENT))
{
SignalEvent(OBJECT_SELF, EventUserDefined(EVENT_DAMAGED));
}
}
What happens ingame is this: When below 15 HP he changes faction and falls down BUT he doesn’t polymorph back to his normal self and the conversation doesn’t trigger (I see now what may cause the conversation to not trigger, didn’t notice that before, I think put the wrong conversation there). Can someone see what I’m doing wrong here?
Another thing that I’m wondering about is this: When in water elemental form he doesn’t cast any spells while in combat. Even though he’s a wizard, maybe he can’t cast spells while in polymorphed form?