Trosski Posted August 24, 2018 Share Posted August 24, 2018 So, I have a creature that is enabled by interacting with an activator ref using the DefaultEnableDisableRef script scriptName defaultEnableDisableLinkedRef extends ObjectReference{- This script enables or disables linked ref based on which type user defines in properties.- Can be done OnTriggerEnter, or OnActivate, whichever happens first- This script only fires once then disables itself (default), or can be told to go to a done state (usually for activators) with the ShouldDisable bool.} int property TriggerType auto{0 (default) - enables linked ref1 - disables linked ref} bool Property PlayerOnly = TRUE auto{Does this only trigger for the player? (DEFAULT = TRUE)} bool Property Fade = FALSE auto{Fade in/out when enabled/disabled? (DEFAULT = FALSE)} bool Property ShouldDisable = TRUE auto{Should I disable once triggered/activated? (DEFAULT = TRUE)} float Property Delay = 0.0 auto{Delay before Enable/Disable (DEFAULT = 0.0)} ObjectReference myLinkedRef auto State Waiting Event onTriggerEnter(ObjectReference triggerRef) if (triggerRef == Game.GetPlayer()) || (!PlayerOnly)myLinkedRef = GetLinkedRef() as ObjectReference utility.Wait(Delay) if (TriggerType == 0)myLinkedRef.enable(Fade)elseif (TriggerType == 1)myLinkedRef.disable(Fade)endif if (ShouldDisable == TRUE)self.disable()elseGoToState("Done")endif endif endEvent Event onActivate(ObjectReference triggerRef) if (triggerRef == Game.GetPlayer()) || (!PlayerOnly)myLinkedRef = GetLinkedRef() as ObjectReference utility.Wait(Delay) if (TriggerType == 0)myLinkedRef.enable(Fade)elseif (TriggerType == 1)myLinkedRef.disable(Fade)endif if (ShouldDisable == TRUE)self.disable()elseGoToState("Done")endif endif endEvent endState State Done;Do NothingendState The creature then walks to an idle marker inside a trigger box, and waits for the player to enter the trigger.Once inside the trigger, I have an onEnterTrigger script that adds a summon spell to the player, and disables the creature. Scriptname PaxtonOnEnter extends ObjectReference Conditional{script to test if one or more actors are in a trigger} import gameimport debug ActorBase property TriggerActor1 auto{actor that trigger is looking for - all non-empty trigger actors need to be in trigger in order for IsTriggerReady to be true Update OnInit when adding new trigger properties!} ActorBase property TriggerActor2 auto{ref that trigger is looking for - all non-empty trigger actors need to be in trigger in order for stage to be set Update OnInit when adding new trigger properties!} ReferenceAlias property TriggerAlias1 auto{ref ALIAS that trigger is looking for - all non-empty triggerRefs need to be in trigger in order for stage to be set Update OnInit when adding new trigger properties!} Spell property MaggieSpell auto ObjectReference myLinkedRef bool Property Fade = FALSE auto{Fade in/out when enabled/disabled? (DEFAULT = FALSE)} ; etc. - add more as neededbool property disableWhenDone = false auto{ disable myself after I've been triggered. Defaults to false } ;total targets currently in the triggerint targetCountCurrent ;how many targets are we looking for? When targetCountCurrent reaches this, we triggerint targetCountTotal Event OnInit(); count my non-empty trigger propertiesif TriggerActor1targetCountTotal = targetCountTotal + 1endifif TriggerActor2targetCountTotal = targetCountTotal + 1endifif TriggerAlias1targetCountTotal = targetCountTotal + 1endifendEvent auto STATE waiting EVENT onTriggerEnter(objectReference triggerRef)if CheckTriggerRef(triggerRef)myLinkedRef = GetLinkedRef() as ObjectReference; increase ref countmodTargetCount(1); if all target refs are in the trigger, doneif bAllTargetsInTriggerGame.GetPlayer().AddSpell(MaggieSpell)myLinkedRef.Disable(Fade)TriggerMe()endifendifendEVENT EVENT OnTriggerLeave(objectReference triggerRef)if CheckTriggerRef(triggerRef); decrease ref countmodTargetCount(-1)endifendEvent endSTATE STATE hasBeenTriggered; this is an empty state.endSTATE function modTargetCount(int modValue)targetCountCurrent = targetCountCurrent + modValue; failsafe - don't go below 0if targetCountCurrent < 0targetCountCurrent = 0endif; update bAllTargetsInTriggerif targetCountCurrent >= targetCountTotalbAllTargetsInTrigger = trueelsebAllTargetsInTrigger = falseendifendFunction int function GetCurrentTargetCount()return targetCountCurrentendFunction int function GetTotalTargetCount()return targetCountTotalendFunction bool function IsTriggerReady()return ( GetCurrentTargetCount() >= GetTotalTargetCount() )endfunction bool function CheckTriggerRef(objectReference triggerRef); debug.trace(self + "CheckTriggerRef for " + triggerRef)bool bSuccess = false if triggerRefActor triggerActor = triggerRef as Actor if triggerActor; we have an actor, check if it matches any of our trigger actorsActorBase triggerActorBase = triggerActor.GetActorBase(); debug.trace(self + "CheckTriggerRef for " + triggerRef + ": actorbase=" + triggerActorBase)if triggerActorBase == TriggerActor1 || triggerActorBase == TriggerActor2; debug.trace(self + "CheckTriggerRef for " + triggerRef + ": MATCHED")bSuccess = trueelse; debug.trace(self + "CheckTriggerRef for " + triggerRef + ": failed to match " + TriggerActor1 + ", " + TriggerActor2)endifendif; if we haven't already found something, check aliasesif !bSuccessif (TriggerAlias1 && triggerRef == TriggerAlias1.GetRef())bSuccess = trueendifendifendif return bSuccessendFunction ; what happens when all my targets are in the trigger?; override on subclass to change behaviorfunction TriggerMe()if disableWhenDonegotoState("hasBeenTriggered")Disable()endifendFunction bool Property bAllTargetsInTrigger = false Auto conditional{true when all targets are in trigger} All of it works correctly, but I have been asked to make the creature appear and disappear with a summoning portal effect, and I can't figure out how to make that happen. Is there a a trigger function that can be added to the scripts to cause the portal effect to fire, or do I need to go in a whole different direction with a different kind of script? Link to comment Share on other sites More sharing options...
Recommended Posts