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

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. Use SteamCMD to download nanos worldβ„’ Dedicated Server.
  3. Or download nanos worldβ„’ Dedicated Server tool from Steam Client.

Step 2: Creating a Basic Package​

After downloading the server, let's create a basic Package. We will use the handy CLI tool to speed up the proccess:

For that, open a terminal in your server folder and run the following command:

./NanosWorldServer.exe --cli add package my-awesome-package

This command will run the CLI to interactively create your new package:

[display] Please enter the Package Name: (my-awesome-package)

[display] Please enter the Package Author: ()

[display] Please enter the Package Version: (0.0.1)

[display] Please enter the Package Image URL: ()

[display] Please enter the Package Author: ()

[display] Please enter the Package Type: (game-mode)

After that, you will end up with a new folder inside Packages/ called my-awesome-package/. Inside that there will be 3 other folders: Server/, Client/ and Shared/, and a package file Package.toml.

Additionally, if this was the first time running the CLI, it will also create a Config.toml file at the root of the server folder executable. This is the server configuration file!

Step 3: Adding Script functionalities​

Open the file my-awesome-package/Server/Index.lua in your preferred editor (we recommend using VSCode), and let's edit our first script. Let's spawn some Props!

Packages/my-awesome-package/Server/Index.lua
-- Let's print to Console a friendly message
Package.Log("Loading some Props =D")

-- Let's spawn some props
prop_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")

Step 4: Starting the server​

Now let's start the server with the package you just created! For that, simply double click or launch the server from the terminal:

./NanosWorldServer.exe

After starting it, your console will display something like this:

[display]  nanos world (C) Copyright nanos. All Rights Reserved.
[display] Starting Server at Port: 7777. Version: 0.0.0. Map: 'nanos-world::TestingMap'.
[display] Loading Package 'my-awesome-package'...
[script] Loading some Props =D
[display] Package 'my-awesome-package' loaded.
[display] Loading Package 'map-package'...
[display] Package 'map-package' loaded.

You can see it loaded your package and outputted the text "Loading some Props =D" on it.

Step 4: Join your server​

Now let's see the results in-game! Open nanos world and connect to localhost at 127.0.0.1:7777.

After connecting, you will be a flying pawn and will be able to see the props spawned! 😁

Extra Step: Spawning Characters​

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, to spawn a Character when the Player join the server:

my-package/Server/Index.lua
-- Function to spawn a Character to a player
function SpawnCharacter(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
player:Possess(new_character)
end

-- Subscribes to an Event which is triggered when Players join the server (i.e. Spawn)
Player.Subscribe("Spawn", SpawnCharacter)

-- Iterates for all already connected players and give them a Character as well
-- This will make sure you also get a Character when you reload the package
for k, player in pairs(Player.GetAll()) do
SpawnCharacter(player)
end

To apply your changes, run the command in the server console: package reload all. This will also live reload the packages and apply the changes immediatelly.

Destroying the Character when the Player leaves the Server​

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

Append this code:

my-package/Server/Index.lua
-- When Player leaves the server, destroy it's Character
Player.Subscribe("Destroy", function(player)
local character = player:GetControlledCharacter()
if (character) then
character:Destroy()
end
end)

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 interaction with entity Events
  • Spawning Props
  • Spawning & Destroying Characters
Classes Guidecore-concepts/scripting/classes-guide