Skip to main content
Version: latest - a1.0.0 βš–οΈ

Quick Start

Start your Server and first Package in under 10 minutes!

Step 1: Download the Server#

You have three options for downloading nanos world server:

  1. Use the executable (.exe) already located at nanos-world/Server/NanosWorldServer.exe (if you downloaded the base game).
  2. Download nanos world Dedicated Server tool from Steam Client.
  3. Or use SteamCMD to download nanos world Dedicated Server.
tip

The server is as simple as one executable file NanosWorldServer.exe. After downloaded it, run it once to generate the proper and initial folders Assets, Packages and Config.toml file, keep your server open for following this guide!

Step 2: Creating a Basic Package#

  1. Create a folder inside Packages/ to be your Package, let's name it my-package/.
  2. Inside my-package/ create a folder called Server/ and a file called Index.lua inside Server/.
  3. In your server console, type package load my-package to load your new package and generate the configuration file Package.toml. You can edit this file with proper customization later on.

Step 3: Adding Script functionalities#

Open the file Index.lua in your preferred editor (we recommend using vscode), and let's edit our first script:

Packages/my-package/Server/Index.lua
-- Let's print to Console a friendly messagePackage.Log("Loading some Props =D")
-- Let's spawn some propsprop_table = Prop(Vector(200, 0, 0), Rotator(0, 0, 0), "nanos-world::SM_WoodenTable")prop_chair = Prop(Vector(400, 200, 0), Rotator(0, 0, 0), "nanos-world::SM_WoodenChair")prop_tire = Prop(Vector(600, 0, 0), Rotator(0, 0, 0), "nanos-world::SM_TireLarge")

To apply your changes, run the command in the server console: package reload all.

Step 4: Join your server#

tip

If you join your server you can already see the results 😁

Extra Step: Spawning a Character for the Player#

You may have noticed you are just a wandering soul flying around, let’s give you some flesh! For that, we will need to interact with some Events.

Let's append some code in your Index.lua:

my-package/Server/Index.lua
-- Called when Players join the server (i.e. Spawn)Player.Subscribe("Spawn", function(new_player)    -- Spawns a Character at position 0, 0, 0 with default's constructor parameters    local new_character = Character(Vector(0, 0, 0))
    -- Possess the new Character    new_player:Possess(new_character)end)

To apply your changes, run the command in the server console: package reload all.

tip

Now if you join the server, you will spawn into a Character!

Finishing up: Destroying the Character when a player Leaves the Server#

Note that Characters aren't destroyed automatically if the Player disconnects. For that, we will need to Subscribe for when the Player leaves the server (Destroy) and manually destroying the Character:

my-package/Server/Index.lua
-- Called when Players join the server (i.e. Spawn)Player.Subscribe("Spawn", function(new_player)    -- Spawns a Character at position 0, 0, 0 with default's constructor parameters    local new_character = Character(Vector(0, 0, 0))
    -- Possess the new Character    new_player:Possess(new_character)end)
-- When Player leaves the server, destroy it's CharacterPlayer.Subscribe("Destroy", function(player)    local character = player:GetControlledCharacter()    if (character) then        character:Destroy()    endend)

To apply your changes, run the command in the server console: package reload all.

Conclusion#

Congratulations! You have finished your first basic Script and learned:
  • How to setup your Server
  • How to setup a simple Package
  • Basic interact with entity Events
  • Spawning Props
  • Spawning & Destroying Characters

Recommended next step#

Classes Guidecore-concepts/scripting/classes-guide