NPC movement script not working.

Post » Wed Oct 08, 2014 11:58 am

I'm trying to sync an NPC's movement with a chair that swings back and forth, but the NPC doesn't move at all. Can someone tell me what I'm doing wrong?

Here's the chair script, which has to have references persist checked:

Spoiler
Begin Uvi_Tower_SwingChair

Float timer
Float SwingTime
Short Flag

DontSaveObject

If ( MenuMode )
Return
Endif

If ( GetDistance, Player > 2000 )
Set Flag to 0
Return
Endif

Set swingTime to 1.5
Set timer to ( timer + GetSecondsPassed )

If ( timer < swingTime ) ;rotate forward
Rotate y 2
Set Flag to 1
Elseif ( timer < ( swingTime * 3 ) ) ;rotate backward
Rotate y -2
Set Flag to -1
Elseif ( timer < ( swingTime * 4 ) ) ;forward again
Rotate y 2
Set Flag to 1
Else ;reset timer back to zero
Set timer to 0
Set Flag to 0
SetAtStart
Endif

End

And here's the NPC's script:

Spoiler
Begin TMT_NPC_Patron_Sadela

Short NoLore
Short Disabler
Short Flag
Short Rand
Short currentDay
Short Visited
Short Disappear
Float Timer
Float StartPos
Float CurrentPos

If ( StartPos == 0 )
Set StartPos to GetPos x
Endif

If ( CellChanged )
Return
Elseif ( MenuMode )
Return
Elseif ( TM_CellLoad_Global == 1 )
If ( currentDay != Day )
Set currentDay to Day
Set Visited to 0
Endif
If ( Flag == 0 )
Set Flag to 1
Endif
Elseif ( Flag == -1 )
Set Flag to 0
Endif

If ( GetHealth < 1 )
If ( Disabler == 0 )
RemoveItem TM_shield_teacup 1
"sadela areth"->Disable
Set Disabler to -1
Endif
Return
Endif

If ( Disappear == 1 )
Cast TM_mystdummy Player
Set Disappear to -1
Elseif ( Disappear == -1 )
Set Timer to ( Timer + GetSecondsPassed )
If ( Timer < 3 )
Return
Endif
Set Timer to 0
Set Flag to 1
Endif

If ( HasItemEquipped TM_shield_teacup == 0 )
Equip TM_shield_teacup
Endif

;Relevant bit starts here
If ( TM_swingin_chair.Flag == 1 )
Set CurrentPos to ( GetPos x + 10 )
SetPos x CurrentPos
Elseif ( TM_swingin_chair.Flag == -1 )
Set CurrentPos to ( GetPos x - 10 )
SetPos x CurrentPos
Else
SetPos x StartPos
Endif

;If ( Flag < 1 ) commented out for testing
Return
;Endif

Set Rand to Random 100

If ( GetDeadCount "sadela areth" > 0 )
Set Disabler to 1
Elseif ( GameHour < 8 )
Set Disabler to 1
Elseif ( GameHour > 22 )
Set Disabler to 1
Elseif ( Visited )
Set Disabler to 1
Elseif ( Rand < 60 )
Set Disabler to 1
Elseif ( Rand > 80 )
Set Disabler to 1
Elseif ( GetDeadCount TMT_Johari_cat > 0 )
Set Disabler to 1
Elseif ( GetDeadCount TMT_Johari > 0 )
Set Disabler to 1
Else
Set Disabler to 0
Endif

If ( Disabler )
Disable
Else
Set Visited to 1
Enable
Endif

Set Flag to -1

End

I posted the whole script in case I missed something unrelated to the positioning stuff that might be screwing things up.

User avatar
sunny lovett
 
Posts: 3388
Joined: Thu Dec 07, 2006 4:59 am

Return to III - Morrowind