Getting Started with Development: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
m (Minor grammatical fixes.)
Line 7: Line 7:
== Introduction ==
== Introduction ==


Today we are going to show you how you can start developing your own server with a simple Tutorial. We will show you how you can create your own resource and run it in your server.
Today we are going to show you how you can start developing your own server with a simple tutorial. We will show you how you can create your own resource and run it in your server.


== Starting the server ==
== Starting the server ==
Line 22: Line 22:
*'''plugins''': Allows you to load custom '''dll''' plugins into the game.
*'''plugins''': Allows you to load custom '''dll''' plugins into the game.
*'''conf.json''': Contains the server configuration in JSON format. Read more about server settings [[Server_settings|here]].
*'''conf.json''': Contains the server configuration in JSON format. Read more about server settings [[Server_settings|here]].
*'''server.exe''': Server executable, which if you run starts the game server.
*'''server.exe''': Server executable, which if you run, starts the game server.


Currently you'll find your folders empty, so if you want to load a gamemode, there is a [https://github.com/n-n1ks/rage.mp-freeroam freeroam gamemode] available to study/use on your server.
Currently you'll find your folders empty, so if you want to load a gamemode there is a [https://github.com/n-n1ks/rage.mp-freeroam freeroam gamemode] available to study/use on your server.


== Setting up API autocomplete ==
== Setting up API autocomplete ==


Auto-completing is one of the most important stuff the developer always need while developing. It's annoying to keep searching in the wiki for the right syntax or find the right function you want. Thanks to '''CocaColaBear''' for his great contribution in creating a auto-complete package for RAGE JS API
Autocompletion is one of the most important features a developer can use while developing. It's annoying to keep searching in the wiki for the right syntax or find the right function you want. Thanks to '''CocaColaBear''' for his great contribution in creating an autocompletion package for RAGE JS API.


*[https://github.com/CocaColaBear/types-ragemp-s auto-complete SERVER]
*[https://github.com/CocaColaBear/types-ragemp-s autocomplete SERVER]
*[https://github.com/CocaColaBear/types-ragemp-c auto-complete CLIENT]
*[https://github.com/CocaColaBear/types-ragemp-c autocomplete CLIENT]


=== Installation ===
=== Installation ===
Line 43: Line 43:
== Creating your first resource ==
== Creating your first resource ==


<b>Rage Multiplayer</b> Consists of 2 sides of scripting, '''Client-side''' and '''Server-side''', so as mentioned up '''Client-side''' allows you create and develop UI and show people your creativity, and '''Server-side''' allows you to manage the server itself with its things like managing players, vehicles, and markers etc.
<b>Rage Multiplayer</b> consists of 2 sides of scripting, '''Client-side''' and '''Server-side'''. So as mentioned above, '''Client-side''' allows you to create and develop UI and show people your creativity, while '''Server-side''' allows you to manage the server itself with things like managing players, vehicles, and markers etc.


Today we will create our first server-side resource, and will see how it works ingame.
Today we will create our first server-side resource, and will see how it works ingame.


First of all go to <code>packages</code> and create a folder (Call it anything you want), then in your server folder create a <code>index.js</code> file. After that, open the file and write the following
First of all, go to <code>packages</code> and create a folder. (Call it anything you want) Then in your server folder, create an <code>index.js</code> file. After that, open the file and write the following:


<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
Line 54: Line 54:
</syntaxhighlight>  
</syntaxhighlight>  


After that save and close. Now create another file called <code>commands.js</code> and open it.
Now save and close the file. Now create another file called <code>commands.js</code> and open it.


Add these simple commands to your file.
Add these simple commands to your file:


<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
Line 74: Line 74:
If you don't understand these, please proceed to [[Getting Started with Commands|Getting started with commands]]. Now we have created a simple source with 3 basic commands. One that gives health, one that gives armor, and one that kills you.
If you don't understand these, please proceed to [[Getting Started with Commands|Getting started with commands]]. Now we have created a simple source with 3 basic commands. One that gives health, one that gives armor, and one that kills you.


Now save the file and close it. Have you noticed anything wrong with the code we just wrote? If not, let me give you a hint. If you trigger the kill command, this means it will kill the player, but will you re-spawn back? I have the solution for you!.
Now save the file and close it. Have you noticed anything wrong with the code we just wrote? If not, let me give you a hint. If you trigger the kill command, this means it will kill the player, but will you re-spawn back? I have the solution for you!


create a '''JSON''' file and name it <code>spawn_points.json</code> and then add the following code:
Create a '''JSON''' file and name it <code>spawn_points.json</code> and then add the following code:


<syntaxhighlight lang="json">
<syntaxhighlight lang="json">
Line 103: Line 103:
</syntaxhighlight>
</syntaxhighlight>


We have defined our spawn points that we want the player to spawn in, and then we added an event for when the player dies, they respawn in a random location from the spawn points you defined, and also don't forget to make his health 100 again or the player can teleport while dead to the spawn point.
We have defined our spawn points that we want the player to spawn in, and then we added an event for when the player dies. When this event is triggered, they re-spawn in a random location from the spawn points you defined. Also don't forget to make the player's health 100 again or they can teleport while dead to the spawn point.


'''IMPORTANT''': Don't forget to require the <code>events.js</code> in the <code>index.js</code>
'''IMPORTANT''': Don't forget to require the <code>events.js</code> in the <code>index.js</code>.


Your <code>index.js</code> file should be like this:
Your <code>index.js</code> file should be like this:
Line 117: Line 117:
</syntaxhighlight>  
</syntaxhighlight>  


Now save and everything and launch your server and go test what you just did!.
Now save everything and launch your server and go test what you just wrote!


I hope you enjoyed creating your first script in RAGE:MP and we will be sure to create further tutorials for you to learn more.
I hope you enjoyed creating your first script in RAGE:MP and we will be sure to create further tutorials for you to learn more.

Revision as of 07:38, 22 December 2018

Requirements

Introduction

Today we are going to show you how you can start developing your own server with a simple tutorial. We will show you how you can create your own resource and run it in your server.

Starting the server

When downloading the Rage MP updater and running it, you'll get the server files. The folder name will be called server-files. When you open the folder you'll find this:

  • client_packages: Folder in which client-side scripts reside. (Client-side allows you to draw GUI or do CEF work)
  • packages: Folder in which server-side scripts reside. (Server-side allows you to manage the player and create your own world)
  • maps: Allows you to load maps into the game world in JSON format.
  • plugins: Allows you to load custom dll plugins into the game.
  • conf.json: Contains the server configuration in JSON format. Read more about server settings here.
  • server.exe: Server executable, which if you run, starts the game server.

Currently you'll find your folders empty, so if you want to load a gamemode there is a freeroam gamemode available to study/use on your server.

Setting up API autocomplete

Autocompletion is one of the most important features a developer can use while developing. It's annoying to keep searching in the wiki for the right syntax or find the right function you want. Thanks to CocaColaBear for his great contribution in creating an autocompletion package for RAGE JS API.

Installation

  • Open your terminal and navigate to your server's folder.
  • Install the following Node packages:
  • You should now get autocomplete.
  • Follow our next title to find out how the environment works and you'll notice that autocomplete is working.

Creating your first resource

Rage Multiplayer consists of 2 sides of scripting, Client-side and Server-side. So as mentioned above, Client-side allows you to create and develop UI and show people your creativity, while Server-side allows you to manage the server itself with things like managing players, vehicles, and markers etc.

Today we will create our first server-side resource, and will see how it works ingame.

First of all, go to packages and create a folder. (Call it anything you want) Then in your server folder, create an index.js file. After that, open the file and write the following:

//init Commands file
require('./commands.js')

Now save and close the file. Now create another file called commands.js and open it.

Add these simple commands to your file:

mp.events.addCommand('kill', (player) => {
    player.health = 0;
});

mp.events.addCommand('hp', (player) => {
    player.health = 100;
});

mp.events.addCommand('armor', (player) => {
    player.armour = 100;
});

If you don't understand these, please proceed to Getting started with commands. Now we have created a simple source with 3 basic commands. One that gives health, one that gives armor, and one that kills you.

Now save the file and close it. Have you noticed anything wrong with the code we just wrote? If not, let me give you a hint. If you trigger the kill command, this means it will kill the player, but will you re-spawn back? I have the solution for you!

Create a JSON file and name it spawn_points.json and then add the following code:

{
    "SpawnPoints": [
        { "x": -425.517, "y": 1123.620, "z": 325.8544 },
        { "x": -415.777, "y": 1168.791, "z": 325.854 },
        { "x": -432.534, "y": 1157.461, "z": 325.854 },
        { "x": -401.850, "y": 1149.482, "z": 325.854 }
    ]
}

Done? Now save it and close.

Create a new file called events.js and add the following code:

let spawnPoints = require('./spawn_points.json').SpawnPoints;

mp.events.add('playerDeath', (player) => {
    player.spawn(spawnPoints[Math.floor(Math.random() * spawnPoints.length)]);
    player.health = 100;
});

We have defined our spawn points that we want the player to spawn in, and then we added an event for when the player dies. When this event is triggered, they re-spawn in a random location from the spawn points you defined. Also don't forget to make the player's health 100 again or they can teleport while dead to the spawn point.

IMPORTANT: Don't forget to require the events.js in the index.js.

Your index.js file should be like this:

//init Commands file
require('./commands.js')

//init Events file
require('./events.js')

Now save everything and launch your server and go test what you just wrote!

I hope you enjoyed creating your first script in RAGE:MP and we will be sure to create further tutorials for you to learn more. Happy Gaming!