Jump to content

If a script runs twice concurrently...


Recommended Posts

I have the following:

Scriptname dz_outfits_combat_effect_script Extends ActiveMagicEffect
Spell Property dz_outfits_ability_spell  Auto
Actor this_npc
Bool in_combat
Event OnEffectStart(Actor Target, Actor Caster)

this_npc = Target

debug.notification("Combat started for "+this_npc.GetBaseObject().GetName())

in_combat = True

dz_outfits_ability_spell.cast(this_npc,this_npc)

Endevent


Event OnEffectFinish(Actor Target, Actor Caster)

this_npc == Target

debug.notification("Combat stopped for "+this_npc.GetBaseObject().GetName())

in_combat = False

utility.wait(10)

If in_combat == False

  dz_outfits_ability_spell.cast(this_npc,this_npc)

EndIf

Endevent

This effect is attached to an ability that has the condition GetCombatState == 1, which when satisfied causes OnEffectStart() to kick in,

 

the intent of the script is that if combat stops but starts again within 10 seconds then the variable in_combat stays wil be True again and the If condition in the OnEffectFinish() will fail, but my suspicion is that when the getcombatstate condition is satisfied again, then a new instance of the script runs which doesn't know about the previous setting of the in_combat variable, is this correct?

 

 

diziet

 

edit: I forgot to mention that mutliple actors may have this effect on them at anyone time.

Link to comment
Share on other sites

Each instance of a magic effect has its own instance of the script and local variables are not shared between them.

 

You can have one or more functions on a maintenance script (perhaps a quest script) that is triggered by the magic effect starting and ending. Use the single maintenance script to maintain the status variable across multiple combat sessions that all start less than 10 seconds apart from the previous session ending.

Link to comment
Share on other sites

Yes this is correct. When the effect starts again script variables reset because it's a new Active Magic Effect instance. Instead you could use GetCombatState in your OnEffectFinish event.

 

Event OnEffectFinish(Actor Target, Actor Caster)

debug.notification("Combat stopped for "+this_npc.GetBaseObject().GetName())

utility.wait(10)
Target.GetCombatState() ;must run function first to prevent bug

If Target.GetCombatState() != 1
  dz_outfits_ability_spell.cast(Target,Target)
EndIf

Endevent
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...