Jump to content

Script help


cypher2012

Recommended Posts

Hey guys. So I've made a overcome a massive hurdle on my monorail mod. I finally have a monorail that travels across the Commonwealth. All is working lovely!

 

However, I now want it to be able to travel back in the other direction.

 

Having a look at my code, any suggestions for a simple method to reverse it? The 'better' approach would be to make the script dynamic so it can send the train both ways depending on a direction variable, but I may just copy the script and create a second variant altered to send the train the other direction and attach that script to an identical button on the other end of the track. This might be easier.

 

Here's the current code:

Scriptname CMR:CMR_TEST_SplineMove extends ObjectReference

ObjectReference Property object_to_move Auto
{Train model.}

ObjectReference[] Property track_markers Auto
{Reference markers used to navigate the train.}

ObjectReference Property entry_marker Auto
{Location the player will be moved to at the start of the ride. Should be inside of the train.}
ObjectReference Property exit_marker Auto
{XMarker where the player will be exited to at the end of train ride.}

Int Property iTrainDir = 0 Auto
{Currently not used! Will be used to change direction of the train.}

Int iCurrentMarker = 0 

Event OnActivate(ObjectReference akActionRef)
	StartTrain()
	RegisterForRemoteEvent(object_to_move, "OnTranslationAlmostComplete")
EndEvent

Function StartTrain()
	Game.GetPlayer().MoveTo(entry_marker)
	object_to_move.MoveTo(track_markers[0])
	MoveToNextMarker(750.0)
EndFunction

Event ObjectReference.OnTranslationAlmostComplete(ObjectReference akSender)
	FindNextPoint()
EndEvent

Bool Function FindNextPoint()
	if(iCurrentMarker < track_markers.Length - 1)
		MoveToNextMarker(750.0)
		return True
	else
		Game.GetPlayer().MoveTo(exit_marker)
		iCurrentMarker = 0
		return False
	endif
EndFunction

Function MoveToNextMarker(Float fMoveSpeed = 500.0)
	float fSplineMagnitude = track_markers[iCurrentMarker].GetDistance(track_markers[iCurrentMarker+1])
	object_to_move.SplineTranslateTo(track_markers[iCurrentMarker+1].X, track_markers[iCurrentMarker+1].Y,track_markers[iCurrentMarker+1].Z, track_markers[iCurrentMarker+1].GetAngleX(), track_markers[iCurrentMarker+1].GetAngleY(), track_markers[iCurrentMarker+1].GetAngleZ(), fSplineMagnitude,  fMoveSpeed)
	iCurrentMarker += 1
EndFunction
Link to comment
Share on other sites

Maybe I'm missing something because it's really late, but can't you just iterate your list backwards? Add a var for direction, dupe your move to next marker but name it previous, have it go -1 on all the array indexes and then in your find next function have it decide which direction it's moving and call your next/previous move.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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