Jump to content

[LE] How do I script a summon portal effect to fire when I enable an actor?


Trosski

Recommended Posts

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 ref
1 - 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()
else
GoToState("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()
else
GoToState("Done")
endif
endif
endEvent
endState
State Done
;Do Nothing
endState
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 game
import 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 needed
bool property disableWhenDone = false auto
{ disable myself after I've been triggered. Defaults to false }
;total targets currently in the trigger
int targetCountCurrent
;how many targets are we looking for? When targetCountCurrent reaches this, we trigger
int targetCountTotal
Event OnInit()
; count my non-empty trigger properties
if TriggerActor1
targetCountTotal = targetCountTotal + 1
endif
if TriggerActor2
targetCountTotal = targetCountTotal + 1
endif
if TriggerAlias1
targetCountTotal = targetCountTotal + 1
endif
endEvent
auto STATE waiting
EVENT onTriggerEnter(objectReference triggerRef)
if CheckTriggerRef(triggerRef)
myLinkedRef = GetLinkedRef() as ObjectReference
; increase ref count
modTargetCount(1)
; if all target refs are in the trigger, done
if bAllTargetsInTrigger
Game.GetPlayer().AddSpell(MaggieSpell)
myLinkedRef.Disable(Fade)
TriggerMe()
endif
endif
endEVENT
EVENT OnTriggerLeave(objectReference triggerRef)
if CheckTriggerRef(triggerRef)
; decrease ref count
modTargetCount(-1)
endif
endEvent
endSTATE
STATE hasBeenTriggered
; this is an empty state.
endSTATE
function modTargetCount(int modValue)
targetCountCurrent = targetCountCurrent + modValue
; failsafe - don't go below 0
if targetCountCurrent < 0
targetCountCurrent = 0
endif
; update bAllTargetsInTrigger
if targetCountCurrent >= targetCountTotal
bAllTargetsInTrigger = true
else
bAllTargetsInTrigger = false
endif
endFunction
int function GetCurrentTargetCount()
return targetCountCurrent
endFunction
int function GetTotalTargetCount()
return targetCountTotal
endFunction
bool function IsTriggerReady()
return ( GetCurrentTargetCount() >= GetTotalTargetCount() )
endfunction
bool function CheckTriggerRef(objectReference triggerRef)
; debug.trace(self + "CheckTriggerRef for " + triggerRef)
bool bSuccess = false
if triggerRef
Actor triggerActor = triggerRef as Actor
if triggerActor
; we have an actor, check if it matches any of our trigger actors
ActorBase triggerActorBase = triggerActor.GetActorBase()
; debug.trace(self + "CheckTriggerRef for " + triggerRef + ": actorbase=" + triggerActorBase)
if triggerActorBase == TriggerActor1 || triggerActorBase == TriggerActor2
; debug.trace(self + "CheckTriggerRef for " + triggerRef + ": MATCHED")
bSuccess = true
else
; debug.trace(self + "CheckTriggerRef for " + triggerRef + ": failed to match " + TriggerActor1 + ", " + TriggerActor2)
endif
endif
; if we haven't already found something, check aliases
if !bSuccess
if (TriggerAlias1 && triggerRef == TriggerAlias1.GetRef())
bSuccess = true
endif
endif
endif
return bSuccess
endFunction
; what happens when all my targets are in the trigger?
; override on subclass to change behavior
function TriggerMe()
if disableWhenDone
gotoState("hasBeenTriggered")
Disable()
endif
endFunction
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

  • Recently Browsing   0 members

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