We like for loops for the added utility of continue; - it allows for much neater flow control with fewer brackets. Also possible with while, but not as handy. Comes down to personal taste I suppose.
'>
As for the actual content of this loop, it'd be better done recursively, so that there's only one delay running at a time, as CID is suggesting.
By way of example:
void ForceJump (object oTarget, location lTarget, int bClearCombat=TRUE, int bForceCommandable=FALSE) {
if (!GetIsObjectValid(oTarget) || GetObjectType(oTarget) != OBJECT_TYPE_CREATURE)
return;
if (!GetIsObjectValid(GetArea(oTarget))) {
DelayCommand(5.0, ForceJump(oTarget, lTarget, bClearCombat, bForceCommandable));
return;
}
if (GetIsDead(oTarget)) {
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectResurrection(), oTarget);
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectHeal(GetMaxHitPoints(oTarget)), oTarget);
effect eBad = GetFirstEffect(oTarget);
while (GetIsEffectValid(eBad)) {
if (GetEffectIsNegative(eBad))
RemoveEffect(oTarget, eBad);
eBad = GetNextEffect(oTarget);
}
if (GetIsPC(oTarget))
AssignCommand(oTarget, ExecuteScript("fky_deathprocess", oTarget));
DelayCommand(0.1, ForceJump(oTarget, lTarget, bClearCombat, bForceCommandable));
} else if (!GetCommandable(oTarget)) {
if (bForceCommandable) {
AssignCommand(oTarget, SetCommandable(TRUE));
if (bForceCommandable >= 5)
WriteTimestampedLogEntry("FORCEJUMP : " + GetPCPlayerName(oTarget) + " : " +
GetName(oTarget) + " : more than 5 attempts to force commandable jumping to " +
GetResRef(GetAreaFromLocation(lTarget)));
}
DelayCommand(1.0, ForceJump(oTarget, lTarget, bClearCombat, ++bForceCommandable));
} else {
AssignCommand(oTarget, ClearAllActions(bClearCombat));
AssignCommand(oTarget, ActionJumpToLocation(lTarget));
AssignCommand(oTarget, ActionDoCommand(SetCommandable(TRUE)));
AssignCommand(oTarget, SetCommandable(FALSE));
}
}
Or, if you have a set number or period in mind, you can configure that as well, and just have a counter tick down to zero, terminating the loop when < 0.
Funky
Modifié par FunkySwerve, 06 juin 2011 - 03:29 .