Jump to content

How to have script timer reset or restart?


vizex1

Recommended Posts

In creation kit I created a quest. It's set to allow repeated stages. Certain actions will set it's stage to 10. Whenever this happens a script displays a message, than after a certain amount of time another message is displayed. However if the action that set the stage is repeated, it will run duplicate scripts. I want the script or timer to just restart and not duplicate the script. Can someone help me to achieve this? Thanks.

Debug.Notification("0%")
Debug.Trace("0%")
Utility.WaitGameTime(0.1)
Debug.Notification("50%")
Debug.Trace("50%")
Utility.WaitGameTime(0.1)
Debug.Notification("100%")
Debug.Trace("100%")
Edited by vizex1
Link to comment
Share on other sites

I guess you have this code in the stage script, but you should create a quest script instead, and create a function to setup a game-time timer.

 

So your quest script would be something like that:

Int Percentage = 0
Int MyTimerID = 123 ; Whatever number works, is just to keep track of the timer you want to start/cancel

Function StartMyTimer()
	Percentage = 0; Set the percentage to 0
	Debug.Notification("0%")
	Debug.Trace("0%")
	CancelTimerGameTime(MyTimerID); Cancel previous timer, if any.
	StartTimerGameTime(0.1, MyTimerID); Start a timer.
EndFunction

Event OnTimerGameTime(int aiTimerID)		
	If aiTimerID == MyTimerID; if this is my timer (not necessary since this script only has 1 timer, but its a good practice).
		Percentage += 50; sum 50 to percentage
		Debug.Notification(Percentage + "%")
		Debug.Trace(Percentage + "%")
		If Percentage < 100; if percentage is less than 100 start the timer again
			StartTimerGameTime(0.1, MyTimerID)
		EndIf
	EndIf
EndEvent

Then, in the stage fragment you need to select your quest script as kmyQuest and call the function

 

kmyQuest.StartMyTimer()

Edited by DieFeM
Link to comment
Share on other sites

I copy pasted your script in the scripts tab of the quest.

 

but I can't get kmyQuest.StartMyTimer() to work in the stage fragment. I even add kmyquest as a property that referenced the quest but it keeps saying startmytimer is not a function.

Edited by vizex1
Link to comment
Share on other sites

Would suggest OnStageSet event, any drawbacks vs kMyQuest calls? No need to have Fragments at all in simple cases, unless desired for experimental purpose. Example - DefaultQuestShutdownScript.

Btw, timers restart (update) by themselves on StartTimer, no need to stop.

Link to comment
Share on other sites

Would suggest OnStageSet event, any drawbacks vs kMyQuest calls? No need to have Fragments at all in simple cases, unless desired for experimental purpose. Example - DefaultQuestShutdownScript.

Btw, timers restart (update) by themselves on StartTimer, no need to stop.

Does it matter if I do it one way or the other? I have very little experience in scripting.

Link to comment
Share on other sites

 

Would suggest OnStageSet event, any drawbacks vs kMyQuest calls? No need to have Fragments at all in simple cases, unless desired for experimental purpose. Example - DefaultQuestShutdownScript.

Btw, timers restart (update) by themselves on StartTimer, no need to stop.

Does it matter if I do it one way or the other? I have very little experience in scripting.

 

 

hereami is absolutly right, CancelTimerGameTime before StartTimerGameTime is not necessary since starting a timer resets the previous one with the same timerID, but I used it as example, so you know how to stop a timer.

Also using OnStageSet avoids the need of using stage fragments, since you call it in the stage 10, it would be like that:

Int Percentage = 0
Int MyTimerID = 123 ; Whatever number works, is just to keep track of the timer you want to start/cancel

Function StartMyTimer()
	Percentage = 0; Set the percentage to 0
	Debug.Notification("0%")
	Debug.Trace("0%")
	StartTimerGameTime(0.1, MyTimerID); Start a timer.
EndFunction

Event OnTimerGameTime(int aiTimerID)		
	If aiTimerID == MyTimerID; if this is my timer (not necessary since this script only has 1 timer, but its a good practice).
		Percentage += 50; sum 50 to percentage
		Debug.Notification(Percentage + "%")
		Debug.Trace(Percentage + "%")
		If Percentage < 100; if percentage is less than 100 start the timer again
			StartTimerGameTime(0.1, MyTimerID)
		EndIf
	EndIf
EndEvent

Event OnStageSet(int auiStageID, int auiItemID)
	If auiStageID == 10
		StartMyTimer()
	EndIf
EndEvent

Note that you need to set a Log Entry in order for OnStageSet to work. Not sure about it, but I think that auiItemID is the Log Entry index, so if you have multiple Log Entries with different conditions in the same stage you can use auiItemID to differentiate each Log Entry:

image.png

Event OnStageSet(int auiStageID, int auiItemID)
	If auiStageID == 10
		If auiItemID == 0
			;Do My thing
		EndIf
		If auiItemID == 1
			;Do My other thing
		EndIf
	EndIf
EndEvent

But note that I'm not sure about that, I never had to use it, maybe hereami can confirm it.

Edited by DieFeM
Link to comment
Share on other sites

Does it matter if I do it one way or the other? I have very little experience in scripting.

Basically, because of that, that's a simpler alternative, and also existing game scripts have tons of examples for almost any case and useful in case of doubts and for educational purposes, but sure, can be done this or that, depends, just good to know about both and operate with them accordingly.

 

Note that you need to set a Log Entry in order for OnStageSet to work. Not sure about it, but I think that auiItemID is the Log Entry index,

All true and important, i had quite a headache with it. If there isn't at least one log entry specified, OnStageSet won't fire for some reason. ItemID processing may be ignored, i guess, unless there's more than one and required by logic.

 

https://www.creationkit.com/fallout4/index.php?title=Quest_Stage_Fragments

https://www.creationkit.com/fallout4/index.php?title=OnStageSet_-_Quest

https://www.creationkit.com/fallout4/index.php?title=StartTimerGameTime_-_ScriptObject

Link to comment
Share on other sites

  • Recently Browsing   0 members

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