Canceling a delayed AssignCommand
#1
Posté 15 novembre 2011 - 01:04
Since ClearAllActions() only cancels non-delayed standard actions, how can one cancel a delayed AssignCommand, knowing that the command is a standard function(not an Action* one)? Would it make sense to pass the delayed command as an argument to ActionDoCommand(), so that it can be cancelled anytime with ClearAllActions()?
Hopefully this not unclear, thanks for reading.
Kato
#2
Posté 15 novembre 2011 - 01:30
Funky
#3
Posté 15 novembre 2011 - 01:55
Just to make sure I understand: You mean that nothing will happen when the delayed command is executed if a given condition is not met? I guess that the delayed call itself staying in memory up to the delai expiration is not something to worry about, then?FunkySwerve wrote...
Pass a check along with the commands, which returns the delayed function if a condition is met. It can be as simple as a variable set on an object, which you can set at any point, 'cancelling' the actions.
Modifié par Kato_Yang, 15 novembre 2011 - 01:59 .
#4
Posté 15 novembre 2011 - 05:46
Funky
#5
Posté 15 novembre 2011 - 05:56
Kato
#6
Posté 15 novembre 2011 - 09:31
make the DelayCommand( time, execute script);
This way the delay is in motion until the command execution still, but the condition code will
be the deciding factor on "IF (condition) THEN {execute this code}"
#7
Posté 15 novembre 2011 - 01:44
Example presumes there are two triggers, when PC enters trigger A he have to get to the trigger B within 60seconds otherwise guards will find him and send to jail
code for trigger A:
void DoSomething(object oPC)
{
if(GetLocalInt(OBJECT_SELF,"DoSomething_"+ObjectToString(oPC)))
{
//cancel the teleport, PC made it in time
return;
}
//actual code to do something, like teleport to prison
AssignCommand(oPC, ClearAllActions());
AssignCommand(oPC, ActionJumpToObject(GetObjectByTag("JAIL")));
}
void main()
{
object oPC = GetEnteringObject();
DelayCommand(60.0, DoSomething(oPC));
}
code for trigger B
void main()
{
object oPC = GetEnteringObject();
object triggerA = GetObjectByTag("TRIGGER_A");
//cancel delay on trigger A from trigger B
SetLocalInt(triggerA,"DoSomething_"+ObjectToString(oPC),-1);
}
Modifié par ShaDoOoW, 15 novembre 2011 - 01:44 .
#8
Posté 15 novembre 2011 - 05:03
Kato
Modifié par Kato_Yang, 15 novembre 2011 - 05:14 .
#9
Posté 15 novembre 2011 - 05:59
#10
Posté 16 novembre 2011 - 12:56
For example if I wanted in certain cases to halt an effect from its scheduled expiring, and have it expire later, I could alter such a script.
The unaltered script:
Effect eEffect = (Whatever);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, oObject, 99.0);
Could be rewritten to:
Effect eEffect = (Whatever);
ApplyEffectToObject(DURATION_TYPE_PERMANENT, eEffect, oObject);
DelayCommand(99.0, CustomCommandRemoveEffect(oObject, eEffect));
This altered way can allow for the effect's duration to be extended so that it is removed later provided certain custom criteria are met. And since the effect is being cycled through delay, you don't need to search the character for it; you already have it and can simply remove it any time the delayed command is executed with RemoveEffect().
#11
Posté 16 novembre 2011 - 01:32
Kato
#12
Posté 16 novembre 2011 - 03:41
Except that if the character logs out he have the effect indefinitely, but it does work and the issue I pointed out could be handled in OnClientEnter event like remove everything with id of -1 and permanent duration.WhiZard wrote...
Note: this can also be extended to thing you wouldn't normally think could be interrupted.
For example if I wanted in certain cases to halt an effect from its scheduled expiring, and have it expire later, I could alter such a script.
The unaltered script:
Effect eEffect = (Whatever);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, oObject, 99.0);
Could be rewritten to:
Effect eEffect = (Whatever);
ApplyEffectToObject(DURATION_TYPE_PERMANENT, eEffect, oObject);
DelayCommand(99.0, CustomCommandRemoveEffect(oObject, eEffect));
This altered way can allow for the effect's duration to be extended so that it is removed later provided certain custom criteria are met. And since the effect is being cycled through delay, you don't need to search the character for it; you already have it and can simply remove it any time the delayed command is executed with RemoveEffect().
Modifié par ShaDoOoW, 16 novembre 2011 - 03:42 .
#13
Posté 16 novembre 2011 - 05:37
Funky
#14
Posté 16 novembre 2011 - 06:28
ShaDoOoW wrote...
Except that if the character logs out he have the effect indefinitely...
Thanks for mentioning this, ShadoOow
Kato





Retour en haut






