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:
- Use the executable (.exe) already located at
nanos-world/Server/NanosWorldServer.exe
(if you downloaded the base game). - Download nanos world Dedicated Server tool from Steam Client.
- 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β
- Create a folder inside
Packages/
to be your Package, let's name itmy-package/
. - Inside
my-package/
create a folder calledServer/
and a file calledIndex.lua
insideServer/
. - In your server console, type
package load my-package
to load your new package and generate the configuration filePackage.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:
-- 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")
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
:
-- 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:
-- 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 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 interact with entity Events
- Spawning Props
- Spawning & Destroying Characters