Getting Started with Commands: Difference between revisions
(→Intro) |
No edit summary |
||
| 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 = | |||
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 | |||
<syntaxhighlight lang="javascript"> | |||
mp.events.addCommand("<name>", (player, args, args1, args2) | |||
</syntaxhighlight> | |||
*'''<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 | |||
<syntaxhighlight lang="javascript"> | |||
mp.events.addCommand("Hello", (player, FullText, args1, args1) | |||
</syntaxhighlight> | |||
*'''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. | |||
* '''args1, args2''': 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: | |||
<syntaxhighlight lang="javascript"> | |||
mp.events.addCommand("hello", (player, fullText, args1, args2) => { | |||
player.outputChatBox(`Hello! ${player.name}`); | |||
}); | |||
</syntaxhighlight> | |||
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]]. | |||
I wish you learned today how you can use the commands, and I wish you a happy scripting! | |||
Revision as of 09:18, 3 October 2017
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 coolit will return you withI 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!