how can I set a variable with a timer and don't mix up a sec

Post » Tue Nov 20, 2012 11:07 am

Hello,

I would like to set myVar or glbVar to 0 after 5 mins without interfering following script. The script belongs to a Magic Effect/Spell which the player can cast every time.

Event OnEffectFinish(Actor akTarget, Actor akCaster)   myVar = glbVar.getValue()   if myVar == 1	  ;do something	  myVar = 0   else	  ;do something	  myVar = 1   endIfglbVar.SetValue(myVar)endEvent

If I cast once, the second part of the if statement will be executed and the variables are set to 1. With the second cast the variables are set to 0 while the first part is running.

How can I solve this? If the variable is set to 1, that after 5 mins the variable will be set to 0. But if the player casts one more time before the 5 min are over, the variable is set to 0 anyway, so the first timer must be stopped somehow.

I hope I was clearly enough, English is not my mother language.

Thanks for any help
User avatar
Frank Firefly
 
Posts: 3429
Joined: Sun Aug 19, 2007 9:34 am

Post » Mon Nov 19, 2012 8:43 pm

Try with just one var.

GlobalVariable Property kGLOB Auto Event OnEffectFinish(Actor akTarget, Actor akCaster)	kGLOB.SetValue((!kGLOB.GetValue() As Bool) As Int) ; Toggle kGLOB	If kGLOB.GetValue()		; Do 'True' stuff	Else		; Do 'False' stuff	EndIfendEvent

I'd need to see the other script with the timing stuff...
User avatar
Anna Watts
 
Posts: 3476
Joined: Sat Jun 17, 2006 8:31 pm

Post » Tue Nov 20, 2012 1:22 am

Unfortunately you need to be more precise. What do you want among the following?
* A magic effect that stays on the target and do something after five mins?
* A spell that do something immediately but only if you didn't cast it since five mins? Then what should happen if the player cast it again before? Should it reset the timer or not?

Optionally:
* What is the duration of the magic effect?
* What is your mother tongue? There are probably other skilled modders among your compatriots and one could be passing by, do not be afraid to ask.
User avatar
Iain Lamb
 
Posts: 3453
Joined: Sat May 19, 2007 4:47 am

Post » Tue Nov 20, 2012 7:22 am

Hello,

thanks JustinOther for the cleaning tip.
Thanks Perdev for your effort. I thought it was enough to show my country under the avatar picture, I am German.

The Magic Effect is not important and the duration inclines to zero. With every cast the script switches between true and false and does stuff immediately. If the user does not cast the spell within 5 mins the cast after must be false.

If I set a Utility.Wait in the false part I must me able to stop that in the true part before it stacks the timer with every cast, this would be fine, but I don't know how. Maybe with another script or keyword, I'm pretty clueless.


In the script are objects moved around and get dis-/enabled, the whole thing is working but the 5 min "reset"

Thanks for any help
User avatar
Zoe Ratcliffe
 
Posts: 3370
Joined: Mon Feb 19, 2007 12:45 am

Post » Mon Nov 19, 2012 10:10 pm

Since magic effects are automatically purged of any event registered on expiration, I am not surprised to discover that latent calls are also aborted. Something that you were actually relying on but only for effects replaced by another one, you were expecting the active effect to stick until the end of the wait.

Anyway do not use wait, I suggest you add another global viarbale and store the value of GetCurrentRealTime(). Anytime the spell is cast, check whether the difference between those two is greater than 5*60. :)
Now I would need to check but there coud be race conditions to deal with if the effect was applied with a few frames between two casts, but I guess it will be safe if only the player can cast it.
User avatar
Avril Churchill
 
Posts: 3455
Joined: Wed Aug 09, 2006 10:00 am

Post » Mon Nov 19, 2012 9:28 pm

one way might be to do as Perdev says but use an quest script with an function

bool property firstcast=false auto

Function spellfunction

if firstcast==true
RegisterForUpdate( 300)
firstcast=false
endif
endfunction

Call it from the spell.
then after five minutes

Event OnUpdate()
;dostuff
firstcast=false
endevent
User avatar
Khamaji Taylor
 
Posts: 3437
Joined: Sun Jul 29, 2007 6:15 am


Return to V - Skyrim