Hello, I have been trying to find some help with a few scripts and have posted in a few other places. While searching about scripts I found a link to this forum and Im hoping someone here can help me. I am trying to make a puzzle that uses a number of levers and a single button to create one puzzle with two possible solutions. Im trying to make the scripts so that almost any number of levers can be used. I am using two scripts, one on the button, and one on the lever. The scripts compile fine, and the lever/button function, but nothing happens other than the lever and button moving. I want it to disable and enable certain objects, but that part doesnt happen and I am not sure why. I havent really messed with scripting since morrowind so Im pretty rusty, but I do need this to work for a mod Im trying to make.
{
- User can use properties to set the levers initial state
- The script first checks to see if the initial state is the same as the solve state
- When the lever is activated, the lever rotates to a new position and then checks to see if its solved
- If lever is solved, the script increments neccessary vars in the sgleverPuzzlebutton.psc
- Each pillar needs to have its linkedRef point to the lever where the sgleverPuzzlebutton.psc lives
}
import debug
import utility
import game
import sound
bool leftNext = TRUE ; this bool helps us remember which state to go to next
bool property startactive auto
SGdwepuztest01 myLinkedRef
int property solveState auto
{
This is the position the lever needs to be in to be considered solved.
1 = Position 1 (pulled)
2 = Position 2 (middle)
3 = Position 3 (pushed)
Position 1,2,3 refer to the havok animations
}
int property solveState2 auto
{
This is the position the pillar needs to be in to be considered solved.
1 = Position 1 (pulled)
2 = Position 2 (middle)
3 = Position 3 (pushed)
Position 1,2,3 refer to the havok animations
}
EVENT onLoad()
playAnimation("MidPosition")
if startActive == true
wait(RandomFloat(0.25, 2))
activate(getPlayer())
endif
endEVENT
FUNCTION checkforsolve (int statenumber)
if (SolveState == statenumber)
;trace(self + " Lever Solved!")
myLinkedRef.numLeversSolved = myLinkedRef.numLeversSolved + 1
if myLinkedRef.numLeversSolved2 == 0
;donothing
elseif myLinkedRef.numLeversSolved2 >= 1
myLinkedRef.numLeversSolved2 = myLinkedRef.numLeversSolved2 - 1
endif
elseif (SolveState2 == statenumber)
;trace(self + " Lever Solved!")
myLinkedRef.numLeversSolved2 = myLinkedRef.numLeversSolved2 + 1
if myLinkedRef.numLeversSolved == 0
;donothing
elseif myLinkedRef.numLeversSolved >= 1
myLinkedRef.numLeversSolved = myLinkedRef.numLeversSolved - 1
endif
endif
endFUNCTION
AUTO STATE OFFpos
EVENT onActivate (objectReference triggerRef)
gotoState ("busyState")
trace("Switch Animating Down")
if leftNEXT == true
playAnimationandWait("pushDown","pushed")
trace ("done animating")
checkforsolve(3)
gotoState ("busy")
gotoState("LEFTpos")
leftNEXT = false
else
playAnimationandWait("pullDown","pulled")
trace ("done animating")
checkforsolve(1)
gotoState ("busy")
gotoState("RIGHTpos")
leftNEXT = true
endif
endEVENT
endSTATE
STATE LEFTpos
EVENT onBeginState()
utility.wait(0.4)
trace("entering left state")
endEVENT
EVENT onActivate(objectReference triggerREF)
gotoState("busyState")
playAnimationandWait("pushUp","unPushed")
checkforsolve(2)
; debug.trace("start wait")
gotoState ("busy")
utility.wait(0.4)
; debug.trace("end wait")
gotoState("OFFpos")
endEVENT
EVENT onEndState()
; debug.trace("play endstate stuff (left)")
trace("exiting left state")
endEVENT
endSTATE
STATE RIGHTpos
EVENT onBeginState()
utility.wait(0.4)
trace("entering right state")
endEVENT
EVENT onActivate(objectReference triggerREF)
gotoState("busyState")
playAnimationandWait("pullUp","unPulled")
checkforsolve(2)
gotoState ("busy")
utility.wait(0.4)
gotoState("OFFpos")
endEVENT
EVENT onEndState()
trace("exiting right state")
endEVENT
endSTATE
Button Script
{
- This script lives on the button that controls each of the pillars
- Each lever should have its linkedRef point to the button that this script is on
}
import debug
import utility
sound property QSTAstrolabeButtonPressX auto
objectReference property objSelf auto hidden
int property levercount auto
{number of levers in puzzle}
int property numleversSolved auto hidden
{this counts how many levers are correct for first lever combo}
int property numleversSolved2 auto hidden
{this counts how many levers are correct for second lever combo}
bool property puzzlesolved1 auto hidden
{states if levers are in correct position for first combo}
bool property puzzlesolved2 auto hidden
{states if levers are in correct position for second combo}
bool property itemdisabled1 auto hidden
bool property itemdisabled2 auto hidden
ObjectReference property refEnableOnSuccess auto
{This ref is enabled on successfully solving the puzzle}
ObjectReference property refDisableonSuccess auto
{This ref is disabled on successfully solving the puzzle}
objectReference property refEnableOnSuccess2 auto
{This Ref is Enabled on successfully solving the second sequence}
objectReference property refDisableOnSuccess2 auto
{This Reference is Disabled on successfully solving the second sequence}
event onCellAttach()
objSelf = self as objectReference
playAnimation("Open")
endEvent
Function enableordisable()
;if the puzzle is solved, disable the refDisableonSuccess
;else if the puzzle is not solved, activate the refActOnFailures (the dart traps
;in the case of BleakFallsBarrow01)
;wait(6)
if (numleversSolved == levercount)
puzzleSolved1 = true
puzzleSolved2 = false
refEnableOnSuccess.enable()
refDisableOnSuccess.disable()
itemdisabled1 = true
if itemdisabled2 == false
;do nothing
elseif itemdisabled2 == true
refDisableOnSuccess2.enable()
refEnableOnSuccess2.disable()
itemdisabled2 = false
endif
else
puzzleSolved1 = false
endif
endFunction
auto state open
event onActivate(objectReference akActivator)
goToState("waiting")
playAnimationAndWait("Trigger01","done")
if QSTAstrolabeButtonPressX
QSTAstrolabeButtonPressX.play(objSelf)
endif
goToState("Open")
enableordisable()
endEvent
endState
state waiting
endState