Passer au contenu principal
Version: dernière - a1.19.x ⚖️

Démarrage rapide

Démarrez votre serveur et votre premier Paquet en moins de 10 minutes!

Étape 1 : Télécharger le serveur

Vous avez trois options pour télécharger le serveur nanos world :

  1. Utilisez l'executable (.exe) déjà situé à nanos-world/Server/NanosWorldServer.exe (si vous avez téléchargé le jeu de base).
  2. Use SteamCMD to download nanos world™ Dedicated Server.
  3. Ou téléchargez l'outil nanos world™ Dedicated Server à partir de Steam.

Étape 2 : Créer un package basique

Après avoir téléchargé le serveur, nous allons créer un package de base. Nous utiliserons l'outil CLI pratique pour accélérer le processus :

Pour cela, ouvrez un terminal dans le dossier de votre serveur et exécutez la commande suivante :

./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!

Étape 3 : Ajout de fonctionnalités de script

Ouvrer le fichier my-awesome-package/Server/Index.lua dans votre éditeur préféré (nous recommandons d'utiliser VSCode) et éditons notre premier script. Let's spawn some Props!

Packages/my-awesome-package/Server/Index.lua
-- Affichons un message dans la console
Package.Log("Chargement de quelques Props =D")

-- Faisons apparaître quelques 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")

Étape 4 : Démarrage du serveur

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.

Étape 4 : Rejoignez votre serveur

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! 😁

Étape supplémentaire : Apparition d'un personnage

Faire apparaître un personnage pour le joueur

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), Rotator(0, 0, 0), "nanos-world::SK_Male")

-- 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

Pour appliquer vos modifications, exécutez la commande dans la console du serveur : package reload all. This will also live reload the packages and apply the changes immediatelly.

Détruire le personnage quand le joueur quitte le serveur

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)

Pour appliquer vos modifications, exécutez la commande dans la console du serveur : package reload all.

Conclusion

Félicitations ! Vous avez terminé votre premier script basique et appris:
  • Comment installer votre serveur
  • Comment configurer un package simple
  • Interaction de base avec les événements d'entité
  • Faire apparaître des Props
  • Apparition & Destruction des personnages

Étape suivante recommandée

Guide des classescore-concepts/scripting/classes-guide