Not sure why you have ‘ if(GetLocalInt(GetModule(),"ImpPortalGone")== TRUE) return; ‘ in your script. But I’m going to assume its because you are creating a single player module. If not then you will have to change this part to include all party members in the area and not just the one player.
object oPC = GetNearestCreature(CREATURE_TYPE_pLAYER_cHAR,PLAYER_CHAR_IS_PC,OBJECT_SELF, 1); SpeakString("The imp appears to have been defeated... for now, at least.",TALKVOLUME_SHOUT); SetLocalInt(oPC, "KilledPortalImp",10); AddJournalQuestEntry("StrangeMagic",35,oPC,TRUE,FALSE,FALSE);
Place this on your OnDeath script.
Void main() { object oPortal = GetObjectByTag("ImpPortal"); location lPortal = GetLocation(oPortal); if(GetLocalInt(GetModule(),"ImpPortalGone")== TRUE) return;// not sure why this is here... if(GetLocalInt(oPortal, "PortalCount")<=4) // this will make sure the bottom part happens when the imp dies 4 times. { //Visual effect happens first then the imp appears, just made more sense to me, but you can change that if you want.
ApplyEffectAtLocation(DURATION_TYPE_INSTANT,EffectVisualEffect(VFX_FN_SUMMON_UNDEAD),lPortal); DelayCommand(0.5, CreateObject(OBJECT_TYPE_CREATURE,"portal_imp",lPortal)); SetLocalInt(oPortal,"PortalCount", GetLocalInt(oPortal,"PortalCount") +1); // every time the imp dies the count is increased by 1 } else { // adds visual effect while destroying portal
DelayCommand(0.5,ApplyEffectAtLocation(DURATION_TYPE_INSTANT,EffectVisualEffect(VFX_FN_SUMMON_UNDEAD),lPortal)); DelayCommand(0.5,DestroyObject(oImp));// destroys portal object oPC = GetNearestCreature(CREATURE_TYPE_pLAYER_cHAR,PLAYER_CHAR_IS_PC,OBJECT_SELF, 1); SpeakString("The imp appears to have been defeated... for now, at least.",TALKVOLUME_SHOUT); SetLocalInt(oPC, "KilledPortalImp",10); AddJournalQuestEntry("StrangeMagic",35,oPC,TRUE,FALSE,FALSE); } }
If you notice the count is done to the portal not on the imp. Makes it easier to keep track of. Doing it this way makes it so that every thing is done in one script instead of two which makes it easier to trouble shoot and change.