Jump to content

Locking a Pull Chain Script Help


daisy8

Recommended Posts

Hi there

 

I am trying to lock a portcullis by locking the pull chain that activates it. The following script works fine, however, it needs some tuning.

 

How can I fix these :

 

1. Prevent the pull chain activating without the key - I mean play the animation and sound

 

2. Prevent the portcullis from activating (with the key) until the pull chain animation has finished, once it is unlocked.

 

scriptName ADZChainNeedsaKey extends ObjectReference
{Nord portcullis pull chain is locked and needs ADZChainKey001 to operate the portcullis}

Message Property ADZLockedUpMessage Auto ;locked message
Message Property ADZUnlockedMessage Auto ;unlocked message
Key Property ADZChainKey001 Auto ;points at the key
ObjectReference Property BigPortcullis Auto ;points at the portcullis (which has no activate parent set)

Int DoOnce = 0

Event OnInit()

Self.blockActivation(true)

EndEvent

Event OnActivate(ObjectReference akActionRef)

if DoOnce < 1

	if (akActionRef == game.GetPlayer())
		
		if (Game.GetPlayer()).GetItemCount(ADZChainKey001) == 0  ;dont have the key
		ADZLockedUpMessage.Show()
		
		Else  ;have the key
		
		Self.BlockActivation(false)
		DoOnce = DoOnce + 1
		BigPortcullis.Activate(Self) ;raise portcullis
		ADZUnlockedMessage.Show()
	
		EndIf
	EndIf
EndIf	

If DoOnce >= 1
Self.BlockActivation(false)
BigPortcullis.Activate(Self) ;raise and lower portcullis after chain unlocked

EndIf
EndEvent

 

Thanks guys

Daisy

Edited by daisy8
Link to comment
Share on other sites

In answer to 1. You're saying that "if (Game.GetPlayer()).GetItemCount(ADZChainKey001) == 0" is always returning false?

ie. *always* says that the player has the key.

 

Oh, make sure the chain doesn't have the default script in it if so. Make a copy object if you've not done so already.

 

For 2, it sounds like PlayAnimationAndWait() is what you mean.

 

 

 

Not tested this ingame, but it compiled :)

scriptName ADZChainNeedsaKey extends ObjectReference
{Nord portcullis pull chain is locked and needs ADZChainKey001 to operate the portcullis}

Message Property ADZLockedUpMessage Auto ;locked message
Message Property ADZUnlockedMessage Auto ;unlocked message
Key Property ADZChainKey001 Auto ;points at the key
ObjectReference Property BigPortcullis Auto ;points at the portcullis (which has no activate parent set)

Event OnInit()
blockActivation(true) ; All activates controlled via this script
EndEvent

Auto State Waiting
Event OnActivate(ObjectReference akActionRef)
	GoToState("Blocked")
	Actor player = Game.GetPlayer()
	If player == akActionRef
		If player.GetItemCount(ADZChainKey001) ; Has Key
			ADZUnlockedMessage.Show()
			pullGate()
			GoToState("nowActive")
			Return
		Else ; No key
			ADZLockedUpMessage.Show()
		EndIf
	EndIf
	GoToState("Waiting")
EndEvent
EndState

State nowActive
Event OnActivate(ObjectReference akActionRef)
	GoToState("Blocked")
	pullGate()
	GoToState("nowActive")
EndEvent
EndState

State Blocked
Event OnActivate(ObjectReference akActionRef)
	; ignore repeat clicks.
EndEvent
EndState

Function pullGate()
RegisterForSingleUpdate(20)
PlayAnimationAndWait("Pull", "Reset")
UnregisterForUpdate()
BigPortcullis.Activate(Self) ; Toggle portcullis
EndFunction

Event OnUpdate()
Debug.Notification("The chain is not responding.  Check the strings.")
EndEvent

 

 

Link to comment
Share on other sites

Briefly, and so reading what is happening is easier :)

 

The States names aren't important, you call them pretty much what you want.

The states alter which part of the code is run only when a *new* event comes in. (They're not like a GOTO in other languages that jump to a different part of the code straight away.)

 

I've used them here so multiple versions of your code don't end up running concurrently if the use Activates it several times. As the script engine is threaded, this could easily happen, especially with latent functions like wait. States are just a convenient way to switch to another behaviour.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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