Trigger script issue

Post » Mon Jun 18, 2012 10:50 pm

I'm having an issue with a script I wrote. It's attached to a trigger box and when the player enters the trigger volume, it is supposed to activate and set a variable to 1. When the player leaves the volume it sets the variable back to 0. Unfortunately, I can't even seem to get the script to recognize that the player has entered the trigger.

Scriptname AADAArcheryTriggerScript extends ObjectReference  import gameimport debugint property startarchy = 0 autoauto State Waiting    Event onTriggerEnter (objectReference triggerRef)        Actor actorRef = triggerRef as Actor        if(actorRef == game.getplayer())            Debug.Trace("Player is in Trigger")            activate(self as objectReference)            gotoState("Active")        endif        EndEventEndStateState Active    Event onActivate(ObjectReference triggerRef)        startarchy = 1        gotoState("AllDone")        Debug.Trace("Trigger Activated")    EndEventEndState    State AllDone    Event onTriggerLeave (objectReference triggerRef)        Actor actorRef = triggerRef as Actor        if(actorRef == game.getplayer())            Debug.Trace("Player has left Trigger")            startarchy = 0            gotoState("Waiting")        endif    EndEventEndState

Any help would be much appreciated.
User avatar
DAVId MArtInez
 
Posts: 3410
Joined: Fri Aug 10, 2007 1:16 am

Post » Mon Jun 18, 2012 11:52 pm

I'm having an issue with a script I wrote. It's attached to a trigger box and when the player enters the trigger volume, it is supposed to activate and set a variable to 1. When the player leaves the volume it sets the variable back to 0. Unfortunately, I can't even seem to get the script to recognize that the player has entered the trigger.

Scriptname AADAArcheryTriggerScript extends ObjectReference  import gameimport debugint property startarchy = 0 autoauto State Waiting	Event onTriggerEnter (objectReference triggerRef)		Actor actorRef = triggerRef as Actor    <- Unnecessary as you only need to check against the player not if the player is an actor as its impossible for the player not to be an actor!		if(actorRef == game.getplayer())			Debug.Trace("Player is in Trigger")			activate(self as objectReference)  <- not sure in Papyrus if not decareing the activating ref is viable -> Self.Activate TriggerRef			gotoState("Active") <- you activate the object "BEFORE" setting its state to be activatable so this and the above need to be flipped to even have a chance at working.		endif		EndEventEndStateState Active	Event onActivate(ObjectReference triggerRef)		startarchy = 1		gotoState("AllDone")		Debug.Trace("Trigger Activated")	EndEventEndState	State AllDone	Event onTriggerLeave (objectReference triggerRef)		Actor actorRef = triggerRef as Actor -> Same as above unnecessary		if(actorRef == game.getplayer())			Debug.Trace("Player has left Trigger")			startarchy = 0			gotoState("Waiting")		endif	EndEventEndState

Any help would be much appreciated.

Also the States are unnecessary as this object only triggers on the player entering and since you set up states its possible for the player to leave the object before that state is ready for them to and thus breaking the script and object....
User avatar
Victor Oropeza
 
Posts: 3362
Joined: Sun Aug 12, 2007 4:23 pm

Post » Tue Jun 19, 2012 4:39 am

I'd recommend using an http://www.creationkit.com/OnBeginState event if you want to trigger an event as soon as you change states. If you want to run the same code in an http://www.creationkit.com/OnActivate_-_ObjectReference block then you can do this:
Event OnActivate(ObjectReference akActionRef)	OnBeginState()EndEvent

As SaidenStorm mentioned, I expect the following would evaluate to true, although I'd also like to test it (but can't at the moment):
Game.GetPlayer() == (Game.GetPlayer() as ObjectReference)

You can call http://www.creationkit.com/Activate_-_ObjectReference like that, but because your script extends http://www.creationkit.com/ObjectReference_Script you don't need to cast it in order to use it as a parameter of that function.

Cipscis
User avatar
Kaley X
 
Posts: 3372
Joined: Wed Jul 05, 2006 5:46 pm


Return to V - Skyrim