Getting Started with Commands: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
No edit summary
Line 5: Line 5:
Commands are simple and easy to use via your server chat to do many things. Today we will show you how simple is it to create easy commands that can be useful for your server. Let's see the example below.
Commands are simple and easy to use via your server chat to do many things. Today we will show you how simple is it to create easy commands that can be useful for your server. Let's see the example below.


<syntaxhighlight lang="javascript">
<pre>
mp.events.addCommand("weapon", (player, fullText, weapon, ammo) => {
mp.events.addCommand("weapon", (player, fullText, weapon, ammo) => {
var weaponHash = mp.joaat(weapon);
var weaponHash = mp.joaat(weapon);
Line 12: Line 12:


});
});
</syntaxhighlight>
</pre>


This example shows a command with name '''weapon''' which gives the player weapon with ammo. If the player doesn't specify the ammo, the system will give him 10000 ammo automatically.
This example shows a command with name '''weapon''' which gives the player weapon with ammo. If the player doesn't specify the ammo, the system will give him 10000 ammo automatically.
Line 26: Line 26:
We have showed you a example up there about how the command system works. now we'll tell you what is the use of the parameters
We have showed you a example up there about how the command system works. now we'll tell you what is the use of the parameters
that was shown
that was shown
<syntaxhighlight lang="javascript">
<pre>
mp.events.addCommand("<name>", (player, args, args1, args2)
mp.events.addCommand("<name>", (player, args, args1, args2)
</syntaxhighlight>
</pre>


*'''<name>''': This is the place where you can put your command name. For example i'll name it '''Hello'''
*'''<name>''': This is the place where you can put your command name. For example i'll name it '''Hello'''


So now it will look like that
So now it will look like that
<syntaxhighlight lang="javascript">
<pre>
mp.events.addCommand("Hello", (player, FullText, args1, args1)
mp.events.addCommand("Hello", (player, FullText, args1, args1)
</syntaxhighlight>
</pre>


*'''player''': Player is a main definition you have to keep it the same and never change it. Player is used to get information about the player who executed the command.
*'''player''': Player is a main definition you have to keep it the same and never change it. Player is used to get information about the player who executed the command.
Line 45: Line 45:
So as a result the command will look like this:
So as a result the command will look like this:


<syntaxhighlight lang="javascript">
<pre>
mp.events.addCommand("hello", (player, fullText, args1, args2) => {
mp.events.addCommand("hello", (player, fullText, args1, args2) => {
player.outputChatBox(`Hello! ${player.name}`);
player.outputChatBox(`Hello! ${player.name}`);
});
});
</syntaxhighlight>
</pre>


So today we learned how the commands work and how you can use the parameters.
So today we learned how the commands work and how you can use the parameters.

Revision as of 17:55, 16 August 2018

Intro

Commands are simple and easy to use via your server chat to do many things. Today we will show you how simple is it to create easy commands that can be useful for your server. Let's see the example below.

mp.events.addCommand("weapon", (player, fullText, weapon, ammo) => {
	var weaponHash = mp.joaat(weapon);

	player.giveWeapon(weaponHash, parseInt(ammo) || 10000);

});

This example shows a command with name weapon which gives the player weapon with ammo. If the player doesn't specify the ammo, the system will give him 10000 ammo automatically.

How does it work? Simply you go to the chat and type /weapon <weapon_name> <ammo> For example, /weapon weapon_pistol 100. This example gives me a pistol with 100 ammo. to see the list of weapons Click Here.


Parameters

We have showed you a example up there about how the command system works. now we'll tell you what is the use of the parameters that was shown

mp.events.addCommand("<name>", (player, args, args1, args2)
  • <name>: This is the place where you can put your command name. For example i'll name it Hello

So now it will look like that

mp.events.addCommand("Hello", (player, FullText, args1, args1)
  • player: Player is a main definition you have to keep it the same and never change it. Player is used to get information about the player who executed the command.
  • <FullText>: This will get all the words that the player typed after the command. For example if I typed /Hello I am so cool it will return you with I am so cool. You can name it whatever you want, so i'll keep it FullText.
  • args1, args2: Those are optional parameters where you can get certain words. For example I made /Hello I am so cool, so if you tried to console.log(args1) it will return I. You can add any defined words you want.

So as a result the command will look like this:

mp.events.addCommand("hello", (player, fullText, args1, args2) => {
	player.outputChatBox(`Hello! ${player.name}`);
});

So today we learned how the commands work and how you can use the parameters. For more detailed info about commands you can Click Here.

I wish you learned today how you can use the commands, and I wish you a happy scripting!