Getting Started with Commands: Difference between revisions

From RAGE Multiplayer Wiki
(fix typos and more pro view)
No edit summary
 
(3 intermediate revisions by 2 users not shown)
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.


{{ServersideCode|
<pre>
<pre>
mp.events.addCommand("weapon", (player, fullText, weapon, ammo) => {
mp.events.addCommand("weapon", (player, fullText, weapon, ammo) => {
var weaponHash = mp.joaat(weapon);
  let weaponHash = mp.joaat(weapon);
 
  player.giveWeapon(weaponHash, parseInt(ammo) || 10000);
player.giveWeapon(weaponHash, parseInt(ammo) || 10000);
 
});
});
</pre>
</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 20: Line 20:
For example, <code>/weapon weapon_pistol 100</code>. This example gives me a pistol with 100 ammo.
For example, <code>/weapon weapon_pistol 100</code>. This example gives me a pistol with 100 ammo.
to see the list of weapons [[Weapons|Click Here]].
to see the list of weapons [[Weapons|Click Here]].


= Parameters =
= Parameters =


We have showed you an example up there about how the command system works. Now we'll tell you what is the use of the parameters that was shown.
We have showed you an example up there about how the command system works. Now we'll tell you what is the use of the parameters that was shown.
{{ServersideCode|
<pre>
<pre>
mp.events.addCommand("<name>", (player, args, arg1, arg2)
mp.events.addCommand("<name>", (player, args, ...arg)
</pre>
</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:
{{ServersideCode|
<pre>
<pre>
mp.events.addCommand("hello", (player, fullText, arg1, arg2)
mp.events.addCommand("hello", (player, fullText, ...arg)
</pre>
</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.


* '''fullText''': This will get all the words that the player typed after the command. For example if I typed <code>/Hello I am so cool</code> it will return you with <code>I am so cool</code>. You can name it whatever you want, so i'll keep it FullText.
* '''fullText''': This will get all the words that the player typed after the command. For example if I typed <code>/Hello I am so cool</code> it will return you with <code>I am so cool</code>. You can name it whatever you want, so i'll keep it FullText.


* '''arg1, arg2''': Those are optional parameters where you can get certain words. For example I made <code>/Hello I am so cool</code>, so if you tried to console.log(args1) it will return '''I'''. You can add any defined words you want.
* '''...arg''': Those are optional parameters where you can get certain words. For example I made <code>/Hello I am so cool</code>, 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:
So as a result the command will look like this:


{{ServersideCode|
<pre>
<pre>
mp.events.addCommand("hello", (player, fullText, arg1, arg2) => {
mp.events.addCommand("hello", (player, fullText, arg1, arg2) => {
Line 49: Line 52:
});
});
</pre>
</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.
For more detailed info about commands you can [[Events::addCommand|Click Here]].
For more detailed info about commands you can [[Events::addCommand|Click Here]].


I wish you learned today how you can use the commands, and I wish you a happy scripting!
== See also ==
{{ScriptingTutorials}}


[[Category:Tutorials]]
[[Category:Tutorials]]

Latest revision as of 10:55, 6 December 2019

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.

Server-Side
mp.events.addCommand("weapon", (player, fullText, weapon, ammo) => {
  let 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 an example up there about how the command system works. Now we'll tell you what is the use of the parameters that was shown.

Server-Side
mp.events.addCommand("<name>", (player, args, ...arg)
  • <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:

Server-Side
mp.events.addCommand("hello", (player, fullText, ...arg)
  • 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.
  • ...arg: 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:

Server-Side
mp.events.addCommand("hello", (player, fullText, arg1, arg2) => {
	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.

See also