Spawning a truck in Lua

From Rigs of Rods Wiki

Jump to:navigation, search
WarningIcon.png
Warning
The LUA system was removed from Rigs of Rods and replaced by AngelScript. (An AngelScript tutorial is yet to be written, but some information can be found here: http://docs.rigsofrods.com/angelscript)


This tutorial will show you how to spawn loads using The LUA System.

Contents

First Steps

To begin editing, you need to have a text editor, I prefer Notepad++, but wordpad/notepad will do.

Open "Base.lua" in the data folder (If your using notepad++, Right Click -> Open with Notepad++)

Spawning the truck

To Spawn the truck, we just need to add 1 Line of code!

spawnBeam("atruck.truck", "SpawnedTruck", 1450, 56, 1450, 0, 0, 0)

This will spawn 'atruck.truck', it will be called 'SpawnedTruck', It will be spawned at the position 1450 56 1450, and it won't have any rotation (0 0 0)

Extras

Spawning More than one truck

If you wanted to spawn say, a line of trucks, you could do it with a loop
The Result
dist = 10 --Distance between  the last truck, in the x direction
lastPos = 1450
for i=0,5 do
spawnBeam("atruck.truck", "SpawnedTruck"..i, lastPos, 56, 1450, 0, 0, 0) --Spawn the truck
lastPos = lastPos+dist --Add the distance onto the last position
end --End the loop

As you can see, things are a bit more complex now, but I'll explain:

dist = 10 --Distance between  the last truck, in the x direction
lastPos = 1450

In these lines, we simply set the distance between each truck, and set the position of the first truck (lastPos)

for i=0,5,1

This is how we start the loop, It starts at 1, and loops 5 times. (The 1 at the end, is simply the amount to add onto 'i' each loop)

spawnBeam("atruck.truck", "SpawnedTruck"..i, lastPos, 56, 1450, 0, 0, 0) --Spawn the truck

This Line Spawn the truck, The "SpawnedTruck"..i bit simply stops RoR from deleting the last truck we spawned, as it doesn't like trucks with the same name! And finally, this bit tells RoR where to put the truck: lastPos, 56, 1450

 lastPos = lastPos+dist --Add the distance onto the last position

This Line Increments our Spawn position (it adds dist onto the last spawn position)

 end --End the loop

This closes our for loop, without this, RoR would crash (For Extra points, can you make it load a box of trucks?)

But How Do i spawn loads?

You spawn loads (And anything else really) using the same command:

spawnBeam("acontainer.load", "SpawnedTruck", 1450, 56, 1450, 0, 0, 0) --Spawn the load
spawnBeam("an-12.airplane", "SpawnedTruck", 1450, 56, 1450, 0, 0, 0) --Spawn the plane
spawnBeam("wahoo.boat", "SpawnedTruck", 1450, 56, 1450, 0, 0, 0) --Spawn the boat 


(If any errors Occur, Send a PM to "Sweetman" on the official forums)