Scripted Linear Movement

From the Oblivion ConstructionSet Wiki
Revision as of 01:54, 1 May 2010 by imported>Darkness X (New article)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Warning

This script needs to be tested, if you tested this script, please leave your comment at the discussion page, thanks.

Introduction[edit | edit source]

This tutorial will explain how to script activators. Scripted Linear Movement or Scripted Vectors could be used as a replacement for (linear) animations (eg. linear moving platforms). This could be combined with rotations to create complex movements. These could be useful in the following situations:

  • moving platforms to cross distances
  • traps (moving spikes)
  • other floating objects
  • ...

You might have noticed TES CS doesn’t give us the possibility to add scripts to static objects so we need to use an activator. (If you want to use a vanilla Oblivion static object I suggest downloading a BSA Unpacker: Unpack the Oblivion-meshes.bsa file and use the mesh as an activator instead of a static object.

The Script[edit | edit source]

What we want to create is an activator moving between two (disabled) activators: First we are going to edit the activators. Open the reference window. Then we are going to adjust the name, Form ID and the Reference Editor ID:

  • Name: (Doesn’t matter)
  • Form ID: 000StartPointActivator
  • Reference Editor ID: StartPointRef

(Don’t forget to check the Persistent Reference and the Initially Disabled checkboxes!)

  • Name: (Doesn’t matter)
  • Form ID: 000EndPointActivator
  • Reference Editor ID: EndPointRef

(Don’t forget to check the Persistent Reference and the Initially Disabled checkboxes!)

  • Name: (in this case: Platform)
  • Form ID: 000Activator
  • Reference Editor ID: ActivatorRef

(Don’t forget to check the Persistent Reference checkbox!)

To determine the direction and speed of the activator we need to know the exact location (coordinates) from those three activators. We also need to know the (positive) difference between the x, y and z values from the StartPointRef and the EndPointRef. These values only need to be calculated once so we can add a DoOnce function at the start of the Gamemode block.

scn LinearMovement

short Active
short DoOnce

short MoveToEnd
short MoveToStart

Ref StartPointRef
Ref EndPointRef
Ref ActivatorRef

Float xStart
Float yStart
Float zStart

Float xEnd
Float yEnd
Float zEnd

Float xNew
Float yNew
Float zNew

Float xDifference
Float yDifference
Float zDifference

Begin OnActivate ;Check if the activator is activated
	If Active == 0
		Set Active to 1
	Else
		Set Active to 0
	Endif
End

Begin OnReset
	Set DoOnce to 0
	Set Active to 0
	Set MoveToEnd to 1
	Set MoveToStart to 0
End

Begin Gamemode
	If DoOnce == 0
		Set StartPointRef to 000StartPointActivator
		Set EndPointRef to 000EndPointActivator
		Set ActivatorRef to GetSelf

		Set xStart to StartPointRef.getpos x
		Set yStart to StartPointRef.getpos y
		Set zStart to StartPointRef.getpos z

		Set xEnd to EndPointRef.getpos x
		Set yEnd to EndPointRef.getpos y
		Set zEnd to EndPointRef.getpos z

		Set xNew to StartPointRef.getpos x
		Set yNew to StartPointRef.getpos y
		Set zNew to StartPointRef.getpos z

		Set xDifference to (xStart - xEnd)
		Set yDifference to (yStart - yEnd)
		Set zDifference to (zStart - zEnd)

		ActivatorRef.SetPos x xNew
		ActivatorRef.SetPos y yNew
		ActivatorRef.SetPos z zNew

		Set MoveToEnd to 1
		Set MoveToStart to 0

		Set DoOnce to 1
	Endif

	If (xNew != xEnd) && (yNew != yEnd) && (yNew != zEnd) && (MoveToEnd == 1)
		Set xNew to xNew - (xDifference/100)
		Set yNew to yNew - (yDifference/100)
		Set zNew to zNew - (zDifference/100)

		ActivatorRef.SetPos x xNew
		ActivatorRef.SetPos y yNew
		ActivatorRef.SetPos z zNew

	elseif (xNew == xEnd) || (yNew == yEnd) || (zNew == zEnd)
		if MoveToEnd == 1
			Set MoveToEnd to 0
			Set MoveToStart to 1
		Endif
	endif

	If (xNew != xStart) && (yNew != yStart) && (yNew != zStart) && (MoveToStart == 1)
		Set xNew to xNew + (xDifference/100)
		Set yNew to yNew + (yDifference/100)
		Set zNew to zNew + (zDifference/100)

		ActivatorRef.SetPos x xNew
		ActivatorRef.SetPos y yNew
		ActivatorRef.SetPos z zNew

	elseif (xNew == xStart) || (yNew == yStart) || (zNew == zStart)
		if MoveToStart == 1
			Set MoveToStart to 0
			Set MoveToEnd to 1
		Endif
	endif
End

Notes[edit | edit source]

More complex movement could be created with the use of rotations or Rotating an object around another object with a script