Posted on Leave a comment

Avorion Lua + Ship Renaming

[Return to Avorion home]

Maybe you’d like to change the name of your craft or the “Ship” title to something else, such as the size class. Or maybe you’re a server admin and someone is flying a ship with a rude name that you don’t want to be seeing; with a couple of Lua commands we can do something about that. This guide is for beginners that don’t know much about Lua or programming in general. I’m not a programmer, but I can help you get to speed faster than if you’re just learning on your own, as things can get confusing easily.

And be sure to try all of this on a test creative galaxy or something first. Messing with code can have unexpected results!

First of all, if we’re using the basic Lua print() function, we need to be able to see what the output is; to do this, you’ll have to open the Lua console in-game, which by default is the key. If you can’t find the key, you can change this key under the game’s Options->Controls->Key Bindings->Show Console.

You should also have at hand the game’s Lua documentation, which is found in the game’s folder. But first lets have a small introduction to how /run works. When you use:


…the commands should come through as the server – this means that the Server() is executing the commands, but we can get information about ourselves too, you’ll see how very soon.

Ok, so if you now did:

/run print(onServer(),onClient())

you should get two outputs:

1 0

Which we can read as; onServer? True, onClient? False. At least we can confirm that it’s the server executing the commands. As far as I know, this is important, because ship names and so on are handled on the server. So if you were trying to change a ship’s name as a client, that information probably wouldn’t get stored.

If we want to find out who’s online, say if you want to target a specific player, we can simply use the built-in command:


which will output something like

online players (1): NerArth

The (1) here is the index number of this player. This is what we’ll use to target the ship a player is flying. That’s right, these commands coming up only target the ship a player is currently inside of.

Now I founded a little ugly ship with no name, which gets named as “Craft” and I want to know what my current ship is called through the commands, and I can do this in more than a couple of ways, but for example:

/run print(Player(1)
we get: Craft

/run print(Entity().name)
we get: Craft

So what’s the difference? In the first command, we are saying find out the property “name” of the property “craft” of the function “Player()”. We provide the player index as the 1 inside “Player(1)”. So we have told the command we want to know the name of the craft of player 1. It’s that simple.

In the second command, the way that /run seems to work is that the player is identified through something like a callingPlayer() function, so when we simply say Entity().name this is referring to the entity that the player calling the /run command is currently in. Which is fine, if you just want to change your own ship name.

Anyway, I want to change the name, and the “Ship” above it, and I wanna use a player index target…

/run Player(1) = "Solar Wreck"

/run Player(1).craft.title = "Supreme Ship"

An important reminder here! Because of the way code usually works, we use around the name we entered because it tells the command that this is a string of text. If you for example tried /run Player(1) = Tank, this would be trying to fetch a variable called Tank, which it likely wouldn’t find, so nothing would happen other than an error, at most.

If you have the Lua console open, you may have spotted some errors. But even so, it works. That ugly Craft is now Solar Wreck, and it is now a Supreme Ship.

So, using the /players command, you can find out the index numbers of your players, and then using the /run command as shown, you can use those index numbers to target the ship a player is currently flying to rename it or mess around with it in general. If you want to target a ship that a player isn’t inside of, but owns, it gets more complex…

This section is a work-in-progress.

Ok, so now let’s say we want to know the name of every ship in a sector… This is gonna get complicated.

/run for name, entity in pairs({Sector():getEntitiesByType(EntityType.Ship)}) do print( end

This one was a small headache for me to figure out, but things become very obvious as you start to put pieces together.

I’ll explain: We are asking the command to check every Entity of the type Ship in the Sector() the command is being called.

Then, for each of these entities, print out their name property in the console.

This isn’t terribly useful on its own… But it lets us understand how to get lists of ships in a sector. It also lets us do things in batches, say if you wanted to remove or destroy (which leaves the wreckages) every ship in the sector, or every asteroid, etc…

[Return to Avorion home]


Leave a Reply

Your email address will not be published.