Getting Started with Development: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
No edit summary
 
(28 intermediate revisions by 12 users not shown)
Line 1: Line 1:
__TOC__
__TOC__
== Requirements ==


* [https://cdn.rage.mp/client/updater.exe Ragemp Updater]
== Introduction ==
* Basic JS/NodeJS programming knowledge
We are going to show you how to 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. In here we are going to use NodeJS programming.
 
If you wish to learn server-side with C# programming, [[Development_with_Visual_Studio_Code|Click here]].


== Introduction ==
== Requirements ==


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.
* Server Files (read how to get them [[Getting_Started_with_Server|here]])
* Basic [[wikipedia:en:JavaScript|JavaScript]]/[[wikipedia:en:Node.js|NodeJS]] or [[wikipedia:en:C_Sharp_(programming_language)|C#]] programming knowledge
* A scripting/text editor of your choice (e.g. [[wikipedia:en:Visual Studio Code|Visual Studio Code]] or [[wikipedia:en:Notepad++|Notepad++]])


== Starting the server ==
== Starting the server ==
 
After downloading [[Getting_Started_with_Server|server files]] and running '''ragemp-server.exe''' for the first time, some new files will show up. Your folder should look like this:
When downloading the [https://cdn.rage.mp/client/updater.exe Updater] and running it, you'll get the server files. The folder name will be called <code>server-files</code>. When you open the folder you'll find this:


<gallery widths=800px heights=426px>
<gallery widths=800px heights=426px>
Line 17: Line 19:
</gallery>
</gallery>


*'''Client_packages''': Is the Client side. (Client-side allows you to draw GUI or do [https://bitbucket.org/chromiumembedded/cef CEF] work.
*'''client_packages''': Folder in which client-side scripts are located and downloaded by the client. (Client-side allows you to draw [[wikipedia:en:Graphical user interface|<abbr title="Graphical User Interface">GUI</abbr>]] or do <abbr title="Chromium Embedded Framework">[https://bitbucket.org/chromiumembedded/cef CEF]</abbr> work)
*'''Packages''': is the Server side. (Server-side allows you to manage the player and create your own world)
*'''packages''': Folder in which server-side scripts are located and loaded by the server. (Server-side allows you to manage the player and create your own world)
*'''Maps''': Allows your to load maps into your world. Only Json form maps are allowed. (Big '''JSON''' Size maps sometimes won't load or takes alot of time to load)
*'''maps''': Folder in which map files (in [[wikipedia:en:JSON|JSON]] format) are loaded into the game world.
*'''Plugins''': Allows you to put your own '''dll''' plugins.
*'''plugins''': Allows you to load custom <code>.dll</code> plugins into the server.
*'''config''': Allows you to manage your server. For more information [[Server_settings|Click Here]].
*'''conf.json''': Contains the server configuration in JSON format. Read more about server settings [[Server_settings|here]].
*'''ragemp-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 for your server.
Currently you will 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 sample] available to study/use on your server.
== Info ==
<b>Rage Multiplayer</b> consists of 3 sides of scripting:
* '''CEF''' allows you to create and develop <abbr title="User Interface">user interfaces</abbr> and show people your creativity.
* '''Client-side''' allows you to manipulate game client features and show people your creativity.
* '''Server-side''' allows you to manipulate the server itself with things like managing all players, vehicles, markers, etc ([[:Category:Assets|see more]]).


== Creating your first resource ==
== Setting up (TypeScript) ==
Learn how to setup your server using typescript [[Using_Typescript|here]].
== Setting Up (C#) ==
Learn how to setup your server using C# [[Development_with_Visual_Studio_Code|here]].


<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.
== Creating your first resource (Javascript) ==
We will create our first server-side resource, and will see how it works in game. To learn about creating client-side resource, see [[Getting Started with Client-side|Getting started with Client-side]].


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 (name of game mode anything you want).


First of all go to <code>packages</code> in your server folder then create <code>index.js</code> file if you don't have one. After that you open the file and do
=== Scripting server commands ===
In your game mode folder, create an <code>index.js</code> file. After that, open the file and write the following:


<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
Line 38: Line 51:
</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, then create another file named <code>commands.js</code> and open it.


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


<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
mp.events.addCommand('hp', (player) => {
    player.health = 100;
});
mp.events.addCommand('armor', (player) => {
    player.armour = 100;
});
mp.events.addCommand('kill', (player) => {
mp.events.addCommand('kill', (player) => {
     player.health = 0;
     player.health = 0;
});
});
</syntaxhighlight>
Learn more about these on [[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.
=== Scripting server event ===
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:
<syntaxhighlight lang="json">
{
    "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 }
    ]
}
</syntaxhighlight>
Done? Now save it and close.
Create a new file named <code>events.js</code> and add the following code:
<syntaxhighlight lang="javascript">
let spawnPoints = require('./spawn_points.json').SpawnPoints;


mp.events.addCommand('hp', (player) => {
mp.events.add('playerDeath', (player) => {
    player.spawn(spawnPoints[Math.floor(Math.random() * spawnPoints.length)]);
     player.health = 100;
     player.health = 100;
});
});
</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. When this event is triggered, they re-spawn in a random location from the spawn points you defined. Also do not forget to restore the player's health 100 again or they can teleport while dead to the spawn point.
'''IMPORTANT''': Do not forget to require the <code>events.js</code> in the <code>index.js</code>.
=== Putting it all together ===
In the end, your <code>index.js</code> file should look this:


mp.events.addCommand('armor', (player) => {
<syntaxhighlight lang="javascript">
    player.armour = 100;
//init Commands file
});
require('./commands.js')
 
//init Events file
require('./events.js')
</syntaxhighlight>  
</syntaxhighlight>  


if you don't understand those 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 everything then 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!
 
= See also =
*Javascript
**[[Server-side_events|Server Side JS Events]]
**[[Server-side_functions|Server Side JS Functions]]
**[[Client-side_events|Client Side JS Events]]
**[[Client-side_functions|Client Side JS Functions]]
 
* C#
**[[Server-side_CSharp_events|Server Side C# Events]]
**[[Server-side_CSharp_function|Server Side C# Functions]]
**[[Client-side_CSharp_events|Client Side C# Events]]
**[[Client-side_CSharp_functions|Client Side C# Functions]]


Now save the file and close it. Have you wondered anything wrong with the code up there? If no let me give you a hint. If you trigger the command kill this means it will kill the player, but will you re-spawn back? I have the solution for you!.
[[Category:Tutorials]]

Latest revision as of 11:04, 2 May 2024

Introduction

We are going to show you how to 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. In here we are going to use NodeJS programming.

If you wish to learn server-side with C# programming, Click here.

Requirements

Starting the server

After downloading server files and running ragemp-server.exe for the first time, some new files will show up. Your folder should look like this:

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

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

Info

Rage Multiplayer consists of 3 sides of scripting:

  • CEF allows you to create and develop user interfaces and show people your creativity.
  • Client-side allows you to manipulate game client features and show people your creativity.
  • Server-side allows you to manipulate the server itself with things like managing all players, vehicles, markers, etc (see more).

Setting up (TypeScript)

Learn how to setup your server using typescript here.

Setting Up (C#)

Learn how to setup your server using C# here.

Creating your first resource (Javascript)

We will create our first server-side resource, and will see how it works in game. To learn about creating client-side resource, see Getting started with Client-side.

First of all, go to packages and create a folder (name of game mode anything you want).

Scripting server commands

In your game mode 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, then create another file named commands.js and open it.

Add these simple commands to your file:

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

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

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

Learn more about these on 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.

Scripting server event

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 named 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 do not forget to restore the player's health 100 again or they can teleport while dead to the spawn point.

IMPORTANT: Do not forget to require the events.js in the index.js.

Putting it all together

In the end, your index.js file should look this:

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

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

Now save everything then 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!

See also