Getting Started with Development: Difference between revisions
MrPancakers (talk | contribs) m (Missing "./" before events.js) |
|||
| Line 17: | Line 17: | ||
</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''': Is the Client side. (Client-side allows you to draw GUI or do [https://bitbucket.org/chromiumembedded/cef CEF] work) | ||
*'''Packages''': is the Server side. (Server-side allows you to manage the player and create your own world) | *'''Packages''': is the Server side. (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''': 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) | ||
Revision as of 19:22, 29 January 2018
Requirements
- Ragemp Updater
- Basic JS/NodeJS programming knowledge
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 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: Is the Client side. (Client-side allows you to draw GUI or do CEF work)
- Packages: is the Server side. (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)
- Plugins: Allows you to put your own dll plugins.
- config: Allows you to manage your server. For more information Click Here.
Currently you'll find your folders empty, so if you want to load a gamemode, there is a Freeroam Gamemode available to study/use for your server.
Creating your first resource
Rage Multiplayer 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.
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 if you haven't already, then in your server folder then create index.js file if you don't have one. After that you open the file and do
//init Commands file
require('./commands.js')
After that save and close. Now create another file called commands.js and open it.
Add those 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 those 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 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!.
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 a event which when the player dies it spawns the player in 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 and crashes might happen.
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 and everything and launch your server from server.exe and go test what you just did!.
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!