enderalse/source/scripts/defaultactivateself.psc

71 lines
2.3 KiB
Plaintext

ScriptName defaultActivateSelf extends objectReference
{Default script that simply activates itself when player enters trigger}
import game
import debug
bool property doOnce = TRUE auto
{Fire only once? Default: TRUE}
bool property disableWhenDone = FALSE auto
{Disable after activating? Default: FALSE}
bool property playerOnly = TRUE auto
{Only Player Triggers? Default: TRUE}
bool property playerAndAlliesOnly = False Auto
{Only player or Allies/Followers/Summons trigger? Overrides playerOnly if that's true as well. Default: TRUE}
int property minLevel auto
{Optional: If set, player must be >= minLevel to activate this}
Actor property PlayerRef Auto
Faction property CurrentFollowerFaction Auto
Package property Follow Auto
Package property FollowerPackageTemplate Auto
;************************************
auto State waiting
Event onTriggerEnter(objectReference triggerRef)
If PlayerRef == None
PlayerRef = Game.GetPlayer()
EndIf
Actor actorRef = triggerRef as Actor
; check whether we care if the player is activating
if(actorRef == PlayerRef || (playerAndAlliesOnly && IsPlayerAlly(actorRef)) || (playerOnly == False && playerAndAlliesOnly == False))
; also check level (if we even care about that)
if(minLevel <= 1 || PlayerRef.getLevel() >= minLevel)
if doOnce == TRUE
gotoState("allDone")
endif
if disableWhenDone
Self.Disable()
EndIf
; per the description of this script, pass self as the activating ref
activate(self)
endif
endif
endEvent
endState
bool Function IsPlayerAlly(Actor actorRef)
;Short-circuit this if this isn't an Actor at all, or if it's hostile to the player.
if (actorRef == None || actorRef.GetFactionReaction(PlayerRef) == 1)
return False
EndIf
;Is this a summon or one of the various types of player followers?
If actorRef.IsCommandedActor() || (actorRef.GetRelationshipRank(PlayerRef) > 0) || (CurrentFollowerFaction && actorRef.IsInFaction(CurrentFollowerFaction)) || actorRef.IsPlayerTeammate()
Return True
EndIf
Package curPackageTemplate = actorRef.GetCurrentPackage().GetTemplate()
Return ((curPackageTemplate == Follow) || (curPackageTemplate == FollowerPackageTemplate))
EndFunction
;************************************
State allDone
;do nothing
endState
;************************************