Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ScriptName TrapBase extends objectReference
- ;-- Properties --------------------------------------
- Group WarnProperties collapsedonref
- bool Property UseWarnTimer = True Auto Const
- { if this is set, use the WarnTimer otherwise it goes by the animation End }
- float Property WarnTime = 1.5 Auto Const
- { this is used if UseWarnTimer is true }
- int Property WarnTimerNumber = 100 Auto Const hidden
- Sound Property WarnSound Auto Const
- { Played from warn state is specified, but most should be hooked up on the anim }
- string Property WarnAnim = "Arm" Auto Const
- { Alert anim name }
- string Property WarnAnimEndEvent = "ArmState" Auto Const
- { Alert anim name }
- EndGroup
- Group FireTrapProperies collapsedonref
- bool Property IsPhysicalTrap = False Auto Const
- { if this is true, prep for a phyical hit, this trap must have TrapHitBase to function }
- string Property FireTrapAnim = "Trip" Auto Const
- { Anim played when this is fired }
- string Property FireTrapAnimEndEvent = "TransitionComplete" Auto Const
- { Anim played when this is fired }
- int Property aiSoundLevel = 50 Auto Const
- EndGroup
- Group DisarmProperties collapsedonref
- ObjectReference Property lastActivateRef Auto hidden
- { This tracks who activated this last across states for disarming }
- bool Property UseDefaultDisarm = True Auto Const
- { use the default Disarm behavior - IE just play the anim and disable if needed }
- LeveledItem Property TrapDisarmedReward Auto Const
- { This is given to the disarming actor }
- bool Property DisarmDisables = False Auto Const
- { if true, disarming this "disables" the object }
- string Property DisarmAnim = "Disarm" Auto Const
- { Disarm Anim to play }
- Sound Property DisarmSound Auto Const
- { This is the sound to play when disarming
- TRPDisarmHiTech & TRPDisarmLoTech are the usual choices }
- GlobalVariable Property TrapDisarmXPReward Auto Const
- Keyword Property WorkshopNoRepairKeyword Auto Const
- EndGroup
- bool Property init Auto hidden
- traphitbase Property hitBase Auto hidden
- int Property TrapLevel = 1 Auto Const
- { Used to determine the difficulty of the trap, currently only tied to damage
- 0 = Easy
- 1 = Medium (DEFAULT)
- 2 = Hard
- 3 = VeryHard }
- int Property damage Auto Const hidden
- bool Property IsWorkshopVersion = False Auto
- ;-- Variables ---------------------------------------
- bool isGrabbed = False
- ;-- Functions ---------------------------------------
- Function LocalOnTimer(int aiTimerID)
- ; Empty function
- EndFunction
- Function DisarmTrap()
- If (UseDefaultDisarm)
- Self.PlayAnimation(DisarmAnim)
- Else
- Self.LocalDisarmTrap()
- EndIf
- If (DisarmSound)
- ObjectReference ObjSelf = Self as ObjectReference
- DisarmSound.Play(ObjSelf)
- EndIf
- If (!Self.DefaultDisarmReward())
- Self.LocalDisarmReward()
- EndIf
- If (!IsWorkshopVersion)
- Game.RewardPlayerXP(TrapDisarmXPReward.GetValueInt(), False)
- EndIf
- If (DisarmDisables)
- Self.Disable(False)
- EndIf
- Self.SetDestroyed(True)
- EndFunction
- Function RepairTrap()
- Self.SetDestroyed(False)
- Self.PlayAnimation("set")
- Self.GoToState("Idle")
- EndFunction
- Function LocalRepairTrap()
- ; Empty function
- EndFunction
- Event OnTimer(int aiTimerID)
- If (Self.getState() != "Disarm" && Self.getState() != "Disarmed" && Self.getState() != "TrapFired")
- If (aiTimerID == WarnTimerNumber)
- Self.FireTrap()
- EndIf
- EndIf
- Self.LocalOnTimer(aiTimerID)
- EndEvent
- Function StartWarn()
- Self.ResolveLeveledDamage()
- If (UseWarnTimer)
- Self.PlayAnimation(WarnAnim)
- Self.StartTimer(WarnTime, WarnTimerNumber)
- Else
- Self.PlayAnimationAndWait(WarnAnim, WarnAnimEndEvent)
- Self.FireTrap()
- EndIf
- EndFunction
- Function resetLimiter()
- ; Empty function
- EndFunction
- bool Function DefaultDisarmReward()
- If ((lastActivateRef as Actor) as bool && TrapDisarmedReward as bool)
- If (lastActivateRef == Game.GetPlayer() as ObjectReference)
- (lastActivateRef as Actor).AddItem(TrapDisarmedReward as Form, 1, False)
- Else
- (lastActivateRef as Actor).AddItem(TrapDisarmedReward as Form, 1, True)
- EndIf
- return True
- Else
- return False
- EndIf
- EndFunction
- Function LocalDisarmReward()
- ; Empty function
- EndFunction
- Event OnWorkshopObjectMoved(ObjectReference akReference)
- isGrabbed = False
- If (Self.IsPowered())
- Self.Activate(Self as ObjectReference, False)
- EndIf
- EndEvent
- Function ResolveLeveledDamage()
- hitBase = (Self as ObjectReference) as traphitbase
- hitBase.damage = 0
- EndFunction
- Function initialize()
- ; Empty function
- EndFunction
- Event OnWorkshopObjectGrabbed(ObjectReference akReference)
- isGrabbed = True
- EndEvent
- Event onReset()
- Self.GoToState("Idle")
- Self.Enable(False)
- Self.SetDestroyed(False)
- Self.reset(None)
- EndEvent
- Event OnWorkshopObjectRepaired(ObjectReference akReference)
- Self.RepairTrap()
- If (Self.IsPowered())
- Self.Activate(Self as ObjectReference, False)
- EndIf
- EndEvent
- Function FireTrap()
- ObjectReference ObjSelf = Self as ObjectReference
- ObjSelf.AddKeyword(WorkshopNoRepairKeyword)
- Self.GoToState("TrapFired")
- Self.LocalFireTrap()
- Self.CreateDetectionEvent(Game.GetPlayer(), aiSoundLevel)
- If (IsPhysicalTrap)
- hitBase.GoToState("canHit")
- Self.PlayAnimationAndWait(FireTrapAnim, FireTrapAnimEndEvent)
- hitBase.GoToState("cannotHit")
- EndIf
- ObjSelf.RemoveKeyword(WorkshopNoRepairKeyword)
- EndFunction
- Function LocalDisarmTrap()
- ; Empty function
- EndFunction
- Function LocalFireTrap()
- ; Empty function
- EndFunction
- ;-- State -------------------------------------------
- State warn
- Event OnBeginState(string asOldState)
- Self.StartWarn()
- EndEvent
- Event onActivate(ObjectReference activateRef)
- lastActivateRef = activateRef
- If (activateRef as Actor)
- Self.GoToState("Disarm")
- EndIf
- EndEvent
- EndState
- ;-- State -------------------------------------------
- State Disarm
- Event OnBeginState(string asOldState)
- Self.DisarmTrap()
- EndEvent
- EndState
- ;-- State -------------------------------------------
- State TrapFired
- EndState
- ;-- State -------------------------------------------
- Auto State Idle
- Event onActivate(ObjectReference activateRef)
- lastActivateRef = activateRef
- If (init == False)
- Self.initialize()
- init = True
- EndIf
- If (activateRef as Actor)
- If (!IsWorkshopVersion)
- Self.GoToState("Disarm")
- EndIf
- Else
- Self.GoToState("warn")
- EndIf
- EndEvent
- Event OnPowerOn(ObjectReference akPowerGenerator)
- If (!isGrabbed)
- Self.Activate(Self as ObjectReference, False)
- EndIf
- EndEvent
- EndState
Advertisement
Add Comment
Please, Sign In to add comment