Prevent multiple instances of the same script

Post » Fri Jun 28, 2013 5:43 am

Hello!

I'm trying to set up four activators to teleport the player to four different locations, i could use a menu for this, but for astetic reasons i wanna use four seperate objects. They are each a orb with tied in animations and effects. As it stands now the player can activate all four at the same time, i'd like him or her to only be able to activate one at a time. How do i go about this? Papyrus is starting to click for me, but this is a bit advanced for me. Maybe something with global states or something?

Here is the script as it stands now, i haven't added the actual teleportation yet, content to just get this working for now. (Don't have the cells ready either)

Scriptname qqqSPIREActivateOrb extends ObjectReference  {Activates the linked travel orb (qqqSPIREOrbActivator)}ObjectReference Property TeleOrb  Auto  EVENT onActivate (objectReference triggerRef)        TeleOrb.PlayGamebryoAnimation("AnimIdle01")        TeleOrb.PlayAnimation("open")        ;Debug.MessageBox("Script Activated")    Utility.Wait(10.0)        Teleorb.PlayGamebryoAnimation("AnimIdle02")        Teleorb.PlayAnimation("close")        ;Debug.MessageBox("Timer Ended")            Utility.Wait(10.0)        ;Debug.MessageBox("Script Ended")        endEVENT
User avatar
Jessie
 
Posts: 3343
Joined: Sat Oct 14, 2006 2:54 am

Post » Fri Jun 28, 2013 6:56 am

Global variables should work. http://www.creationkit.com/Global

Scriptname qqqSPIREActivateOrb extends ObjectReference  {Activates the linked travel orb (qqqSPIREOrbActivator)};ObjectReference Property TeleOrb  Auto;You don't need a property for the object the script it is attached to.  This is automatically filled in the "self" variable if neededGlobalVariable Property TeleGlobal Auto ;initially 0EVENT onActivate (objectReference triggerRef)    if !TeleGlobal.GetValue() ;check to make sure it's still 0        TeleGlobal.SetValue(1.0) ;lock it        PlayGamebryoAnimation("AnimIdle01")        PlayAnimation("open")        ;Debug.MessageBox("Script Activated")        Utility.Wait(10.0)        PlayGamebryoAnimation("AnimIdle02")        PlayAnimation("close")        Utility.Wait(10.0)        ;teleport your player        TeleGlobal.SetValue(0.0) ;unlock it        ;Debug.MessageBox("Script Ended")      endIfendEVENT

Edit: This should be fairly safe, as long as the player can't activate both orbs within < 0.001 sec of each other as the functions are very fast. You could make it slightly more complicated but 100% thread safe by setting up a quest. Ex:

Spoiler
Scriptname qqqSPIREActivateOrb extends ObjectReference  YourQuestScriptName Property kQuest AutoEVENT onActivate (objectReference kTriggerRef)    kQuest.Start()    kQuest.Teleport(kTriggerRef, 1)endEVENT
Scriptname YourQuestScriptName extends Quest  bool bLockFunction Teleport(ObjectReference akRef, int aiLoc)    if !bLock        bLock = true        akRef.PlayGamebryoAnimation("AnimIdle01")        ;all of your animation stuff        ;teleport to location depending on aiLoc value        bLock = false ;might not even be needed as the quest is shutting down since it's not needed anymore        Stop()    endIfendFunction
User avatar
sarah
 
Posts: 3430
Joined: Wed Jul 05, 2006 1:53 pm

Post » Fri Jun 28, 2013 11:49 am

Ah, thank you very much :smile: I'm not so clear on how to effectively use a quest for this, but i'm sure i'll figure it out down the line. Thanks again!

Edit: Just saw your spoiler with the quest info aswell, thanks again very much!

User avatar
Ezekiel Macallister
 
Posts: 3493
Joined: Fri Jun 22, 2007 12:08 pm

Post » Fri Jun 28, 2013 4:57 am

Hmm, it does not work for some reason. Do you also have to physically make the global variable under Misc - Global? Cause i tried it that way aswell, but the scripts will still fire as they please. Copy pasted your script directly from here and also tried to write it in myself.

Edit: Now it works ofcourse :) For anyone finding this topic, yes you have to physically make the global variable under Misc - Global and fill it in like a proper property.

User avatar
Ebony Lawson
 
Posts: 3504
Joined: Fri Feb 16, 2007 11:00 am


Return to V - Skyrim