Maybe something like this (I’m out on thin ice now since I’m still not that good with “while-loops”, sorry sensei @kevL_s , I know you’ve tried to teach me) but I think if you give your guardians the tags “guardian1”, “guardian2” etc. then this version of the script might work and they will be destroyed just before the conversation starts. Again, this is untested:
//Deleted faulty script
EDIT: Hmmm, no, it won’t work since the while loop will stop if there is a, for instance, “guardian3” who is already dead, but “guardian4” is alive. Now, how to get around that problem…
EDIT2: Darn it! I thought I could maybe have been clever by some way go over all objects with the tag “guardian” at the beginning of their string by perhaps using GetSubString or something, but my mind draws a blank. I’ll search among the forums and see if there’s an example where this is already done.
EDIT3: Ok, so here’s a new attempt. I looked at some of Lance’s code for sitting on chairs. Think I understood it and copied a bit and rewrote it slightly using the GetStringLeft function which I’ve never personally used in my own scripts before. Now, if all your guardians have the tag “guardian1” or “guardian3” or whatever (guardian plus a number) then everyone of them, I think and hope, should be erased before the conversation starts. I hope this works (but I don’t quite know what I’m doing now):
//::///////////////////////////////////////////////
//:: Default On Damaged
//:: NW_C2_DEFAULT6
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
If already fighting then ignore, else determine
combat round
*/
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: Oct 16, 2001
//:://////////////////////////////////////////////
#include "hench_i0_ai"
#include "ginc_behavior"
#include "ginc_group"
#include "ginc_ipspeaker"
#include "x0_i0_assoc" // SetAssociateState()
/*
OnDamaged script for the boss.
Stops combat when the boss drops below 10 hitpoints. Starts a dialog.
*/
void PrepForDestruction(object oTarget)
{
SetPlotFlag(oTarget,FALSE);
SetImmortal(oTarget,FALSE);
AssignCommand(oTarget,SetIsDestroyable(TRUE,FALSE,FALSE));
}
void main()
{
object oDamager = GetLastDamager();
object oWeaponUsed = GetLastWeaponUsed(oDamager);
object oWeapon = GetObjectByTag("tagofweapon");
int iHp = GetCurrentHitPoints(OBJECT_SELF);
if (iHp < 10 && !GetLocalInt(OBJECT_SELF,"healedonetime"))
{
AssignCommand(OBJECT_SELF, ClearAllActions(TRUE));
int nCurrentHP;
int nHP;
int nHealPercent = 100;
effect eFX;
effect eVisual = EffectNWN2SpecialEffectFile("sp_cure_critical");
SetLocalInt(OBJECT_SELF,"healedonetime",TRUE);
object oPC = GetFirstPC();
FloatingTextStringOnCreature("The boss has healed up.", oPC, FALSE);
nCurrentHP = GetCurrentHitPoints( OBJECT_SELF );
nHP = FloatToInt( IntToFloat(GetMaxHitPoints(OBJECT_SELF)) * IntToFloat(nHealPercent) / 100 ) - nCurrentHP;
eFX = EffectHeal( nHP );
ApplyEffectToObject( DURATION_TYPE_PERMANENT,eFX,OBJECT_SELF );
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVisual, OBJECT_SELF);
return;
}
else if (iHp < 10 && GetLocalInt(OBJECT_SELF,"insidetrigger") && oWeaponUsed == oWeapon)
{
GroupChangeToStandardFaction("group_badguys", STANDARD_FACTION_COMMONER);
ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_COMMONER);
AssignCommand(OBJECT_SELF, ClearAllActions(TRUE));
GroupClearAllActions("group_badguys", TRUE);
object oPC = GetFirstPC(FALSE);
int i = 1;
object oGuardian = GetNearestObject(OBJECT_TYPE_CREATURE, oPC, i);
while(oGuardian != OBJECT_INVALID)
{
if(GetStringLeft(GetTag(oGuardian), 8) == "guardian")
{
PrepForDestruction(oGuardian);
DestroyObject(oGuardian);
}
i++;
oGuardian = GetNearestObject(OBJECT_TYPE_CREATURE, oPC, i);
}
ClearPartyActions(oPC, TRUE);
SetAssociateState(NW_ASC_MODE_STAND_GROUND,TRUE,GetObjectByTag("tagofcompanion"));
SetAssociateState(NW_ASC_MODE_STAND_GROUND,TRUE,GetObjectByTag("tagofcompanion2"));
SetAssociateState(NW_ASC_MODE_STAND_GROUND,TRUE,GetObjectByTag("tagofcompanion3"));
SetAssociateState(NW_ASC_MODE_STAND_GROUND,TRUE,GetObjectByTag("tagofcompanion4"));
CreateIPSpeaker("tagofthisboss", "bossconversation", GetLocation(oPC), 1.f);
return;
}
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));
}
}
EDIT4: Did some testing on my own and my script didn’t quite work with erasing the guardians. I’ve edited the script above now. I think it should work now.