I fixed my stop combat function. It no longer skips creatures nor does it SetIsTemporaryFriend more than once on a creature. With these fixes it does exactly what i wanted: to stop combat, but with a limited duration on the faction change. Only creatures within 10 meters are affected. You can also limit the function to only stopping combat for one specific enemy of a given PC.
***EDIT*** removed MULTIPLAYER constant so that this functions for other people than myself
http://pastebin.com/pytSBPmE
void StopCombat(object oPC1, object oEnemy, int nRounds, int bAll = FALSE)
{
float fTime = RoundsToSeconds(nRounds);
int x = 1; // iterations of combatant loop
int y = 0; // iterations of pc loop
int z; // iterations of associate type
int max = x+50; // maximum combatants of each character to neutralize
object oPC = GetFirstFactionMember(oPC1); // get first member of party
object oNPC; // associates of oPC
object oCombatant; // additional enemies of oPC or oNPC
while (GetIsObjectValid(oPC))
{
// targeted enemy of PC
SetCommandable(TRUE, oPC);
SetCommandable(TRUE, oEnemy);
AssignCommand(oPC, ClearAllActions(TRUE));
AssignCommand(oEnemy, ClearAllActions(TRUE));
SetIsTemporaryFriend(oPC, oEnemy, TRUE, fTime);
SetLocalInt(oEnemy, "STOPPED_COMBAT", TRUE);
DelayCommand(1.0, DeleteLocalInt(oEnemy, "STOPPED_COMBAT"));
if (bAll)
{
// next loop through all remaining enemies of oPC
x = 1;
oCombatant = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, TRUE, oPC, x);
while (GetIsObjectValid(oCombatant) && x < max)
{
if (!GetLocalInt(oCombatant, "STOPPED_COMBAT") && GetDistanceBetween(oPC, oCombatant) <= 20.0)
{
SetLocalInt(oCombatant, "STOPPED_COMBAT", TRUE);
DelayCommand(1.0, DeleteLocalInt(oCombatant, "STOPPED_COMBAT"));
SetCommandable(TRUE, oCombatant);
if(GetIsInCombat(oCombatant))
AssignCommand(oCombatant, ClearAllActions(TRUE));
SetIsTemporaryFriend(oPC, oCombatant, TRUE, fTime);
}
oCombatant = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, TRUE, oPC, ++x);
}
}
// loop through all Associates of oPC
for (z = 1; z <= 5; z ++)
{
int w = 1;
oNPC = GetAssociate(z, oPC, w);
while (GetIsObjectValid(oNPC))
{
// first enemy of NPC
SetCommandable(TRUE, oNPC);
AssignCommand(oNPC, ClearAllActions(TRUE));
AssignCommand(oEnemy, ClearAllActions(TRUE));
SetIsTemporaryFriend(oEnemy, oNPC, TRUE, fTime);
SetIsTemporaryFriend(oNPC, oEnemy, TRUE, fTime);
if(bAll)
{ // next loop through all remaining enemies of NPC
x = 1;
oCombatant = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, TRUE, oNPC, x);
while (GetIsObjectValid(oCombatant) && x < max)
{
if (!GetLocalInt(oCombatant, "STOPPED_COMBAT") && GetDistanceBetween(oPC, oCombatant) <= 20.0)
{
SetLocalInt(oCombatant, "STOPPED_COMBAT", TRUE);
DelayCommand(1.0, DeleteLocalInt(oCombatant, "STOPPED_COMBAT"));
SetCommandable(TRUE, oCombatant);
if(GetIsInCombat(oCombatant))
AssignCommand(oCombatant, ClearAllActions(TRUE));
SetIsTemporaryFriend(oCombatant, oNPC, TRUE, fTime);
SetIsTemporaryFriend(oNPC, oCombatant, TRUE, fTime);
}
oCombatant = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, TRUE, oPC, ++x);
}
}
oNPC = GetAssociate(z, oPC, ++w);
}
}
// Get Next PC Party Member
oPC = GetNextFactionMember(oPC1);
} // loop through PC party members
}
Modifié par henesua, 29 juillet 2011 - 05:47 .