Avorion Wiki

In this example, a new station script is introduced, which is both added as a separate new station, and added to some already existing stations.

The script demonstrates basic interaction between client- and server variants of entity scripts (which apply to Player and Sector scripts as well).

About[ | ]

  • init.lua Extends the initialization script for entities so that the paidbeacon.lua script is added to all Habitats as well
  • colony.lua Extends this sector generator script to always add a paid beacon in the middle of a colony sector

paidbeacon.lua[ | ]

The paidbeacon.lua script adds a new interaction and corresponding window to an entity. It also changes the interaction text that is displayed when a player presses F to interact with the station. Players can pay credits to set the message of the beacon.

Additionally, it updates regularly and broadcasts the message that was set to the sector chat.

When a player presses the Set Text button, the following happens:

  • The client-side of the script tells the server side that a player wants to change the text and sends the text to the server side of the script
  • The server side checks if the player (or alliance) has enough money to pay
    • If not, the server side sends an error message to the player and stops the interaction
  • The server side reduces the amount of cash the player has and sets the message
  • The server side broadcasts the message to all client side variants of the script in the sector so they all know about the changed message
  • The server side sends the message to chat for all players in the sector

Note: When writing scripts, you can rely on the server-side of the script always being initialize()d before the client side.

modinfo.lua[ | ]

  • serverSideOnly = false This mod can't be server side only, because it adds a new Entity script to the game, and Entity scripts have to be present on client and server. Also: Localization, which has to always be present on the client as well for translation.
  • clientSideOnly = false The mod can't be client side only, since it adds scripts to entities, which has to happen on the server.
  • saveGameAltering = true The mod adds a new script data/scripts/entity/paidbeacon.lua whose path will be saved into the database. Once the mod is disabled, the script is no longer existant and the savegame will be slightly corrupted (not unplayable though).

Localization[ | ]

In the data/localization/ folder you can find an example for a German localization of texts that appear in the mod.

Workshop Link[ | ]

See Also[ | ]