[Include] rCmd.inc - Easiest way to create commands!
#1

Introduction

You're probably like "Oh no, another command system!" - Yes, but this one is different than all others and I'm pretty sure you'll like it! You can use dynamic parameters in your command function which makes everything faster and easier to use for you. The best thing is, in this new version, sscanf2 plugin is integrated and it automatically makes use of it. See more below!

Syntax

Код:
rCmd["specifiers"]->commandname(playerid, success, ...)
NEW (IMPORTANT NOTES):
  • You can use all sscanf specifiers in the specifiers input, yes, literally whole sscanf.
  • Note the quotes around specifiers in this new version. It's not necessary, but when you use brackets for optional parameters, it will give you errors without the quotes.
  • You have to use & in front of all non-array variables (floats, integers, ..., NOT playerid and success) because DynamicParams.inc is passes the address of the value. If you skip this, the value of the integer/float will be wrong. Example:
    Код:
    rCmd["us[24]"]->setname(playerid, success, &targetid, name[]) {
    	// ...
    	return 1;
    }
Specifiers

Simple answer, sscanf is integrated with this new version, so just use it as you would use sscanf, it will behave the same, without any problems.


Example(s)

pawn Код:
rCmd["uiI(500)"]->giveweapon(playerid, success, &targetid, &weaponid, &ammo) {
    if(!success) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: /giveweapon [player id/name] [weapon] [ammo (default 500)]");
    if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Player is not connected!");
   
    GivePlayerWeapon(targetid, weaponid, ammo);
    SendClientMessage(playerid, -1, "You gave the player a weapon!");
    return 1;
}
Note the beastliness of sscanf integrated (with optional parameters and stuff).

pawn Код:
rCmd["us[24]"]->setname(playerid, success, &targetid, name[]) {
    if(!success) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: /setname [player id/name] [name]");
    if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Player is not connected!");
   
    SetPlayerName(targetid, name);
    SendClientMessage(playerid, -1, "You changed the players name!");
    return 1;
}
Please make sure to use & before all your non-array variables (integers, floats, ..., NOT playerid and success).

pawn Код:
rCmd["iI(-1)I(-1)"]->vehicle(playerid, success, &model, &color1, &color2) {
    if(!success) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: /vehicle [model] [color 1 (default -1)] [color 2 (default -1)]");
    if(!(400 <= model <= 611)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Invalid vehicle model!");
   
    new Float: x, Float: y, Float: z;
    GetPlayerPos(playerid, x, y, z);
    CreateVehicle(model, x, y, z, 0.0, color1, color2, 60);
    SendClientMessage(playerid, -1, "You spawned a vehicle!");
   
    return 1;
}
Beautiful, isn't it?

pawn Код:
rCmd[]->time(playerid) {
    new
        szTime[32]
    ;
    gettime(szTime[0], szTime[1], szTime[2]);
    format(szTime, sizeof(szTime), "<> Time: %02d:%02d:%02d", szTime[0], szTime[1], szTime[2]);
    SendClientMessage(playerid, 0x00FF00FF, szTime);
    return 1;
}
Note that there are no parameters.
pawn Код:
rCmd["uF(100.0)"]->sethealth(playerid, success, &targetid, &Float: health) {
    if(!success) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: /sethealth [player id/name] [health (default = 100.0)]");
    if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Player is not connected!");
    if(!(0.0 <= health <= 100.0)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Health has to be between 0.0 and 100.0!");

    SetPlayerHealth(playerid, health);
    SendClientMessage(playerid, -1, "You have set players health!");
    return 1;
}
Some float example. Again, please don't forget the & sign!

Callback(s)

We have two callbacks:
pawn Код:
forward OnPlayerCommandReceived(playerid, cmdtext[]);
This gets called before the actual command gets executed. So returning 0 here means the command won't be executed.

pawn Код:
forward OnPlayerCommandPerformed(playerid, cmdtext[], success);
This gets called after the command gets executed. Returning 0 in here will result in standart "SERVER: Unknown Command" message. You can adjust that message under this callback.

As you probably may have noticed, I used the same callbacks as used in zcmd as they were pretty useful.
pawn Код:
public OnPlayerCommandReceived(playerid, cmdtext[]) {
    if(!strcmp(cmdtext, "/setname", true, 8)) {
        SendClientMessage(playerid, 0xFF0000FF, "ERROR: This command is not enabled right now!");
        return 0; // Command won't be executed
    }
    return 1;
}
pawn Код:
public OnPlayerCommandPerformed(playerid, cmdtext[], success) {
    if(!success) {
        return SendClientMessage(playerid, 0xFF0000FF, "ERROR: That command is unknown!");
    }
    return 1;
}
Download
  • rCmd.inc
  • DynamicParams.inc has also been updated, please make sure you redownload this!
  • You can download sscanf here! Also, I want to thank ****** for this beautiful plugin!
Notes
  • When a command doesn't work, it most probably means that the value MAX_FUNCTIONS (1024) has been exceeded. Just increase it and recompile it and you should be good to go.
  • The max length of the specifiers you can use is currently set to MAX_SSCANF_FORMAT (32). If you need longer specifiers, just increase it.
  • You can use MAX_DYNAMIC_PARAMS (16) parameters with the current settings. Just increase if you would ever need more than 16 parameters.
Changelog
  • 07/03/2012 - v0.1.0:
    • Initial release
  • 08/03/2012 - v0.1.1:
    • Fixed some important bugs. Please re-download if you're using it.
  • 21/04/2012 - v0.1.2:
    • Changed the whole syntax so there's not rCmd_Init anymore (thanks ******):
      Код:
      rCmd[specifiers]->commandname(playerid, success, ...)
    • Added some new useful specifiers h, b and u:
      StringCharacterIntegerFloatUser name/idHexBinary
      s
      c
      i or d
      f
      u
      h
      b
    • Fixed a bug where the stack didn't get restored when your command was incomplete.
  • 06/01/2013 - v0.2.0:
    • Rewrote the whole include, as well as DynamicParams.inc. I found some critical bugs that made this include completely worthless, but I'm sure it's completely fixed now and is %100 to use.
    • sscanf plugin is fully integrated now and automatically makes use of all features of the sscanf plugin.
    • Just make sure you read "Syntax" part of the topic again as there are some important things to note:
      Quote:
      Syntax

      Код:
      rCmd["specifiers"]->commandname(playerid, success, ...)
      NEW (IMPORTANT NOTES):
      • You can use all sscanf specifiers in the specifiers input, yes, literally whole sscanf.
      • Note the quotes around specifiers in this new version. It's not necessary, but when you use brackets for optional parameters, it will give you errors without the quotes.
      • You have to use & in front of all non-array variables (floats, integers, ..., NOT playerid and success) because DynamicParams.inc is passes the address of the value. If you skip this, the value of the integer/float will be wrong. Example:
        Код:
        rCmd["us[24]"]->setname(playerid, success, &targetid, name[]) {
        	// ...
        	return 1;
        }
Have fun using this!
Reply


Messages In This Thread
rCmd.inc - Easiest way to create commands! [NEW v0.2.0 ─ 6/01/2013] - by RyDeR` - 06.03.2012, 22:24
Re: rCmd.inc - Easiest way to create commands! - by Kar - 06.03.2012, 22:37
Respuesta: rCmd.inc - Easiest way to create commands! - by admantis - 06.03.2012, 23:18
Re: rCmd.inc - Easiest way to create commands! - by Ballu Miaa - 07.03.2012, 06:29
Re: rCmd.inc - Easiest way to create commands! - by Michael@Belgium - 07.03.2012, 06:30
Re: rCmd.inc - Easiest way to create commands! - by tyler12 - 07.03.2012, 06:36
Respuesta: rCmd.inc - Easiest way to create commands! - by Jovanny - 07.03.2012, 06:38
Re: rCmd.inc - Easiest way to create commands! - by Lorenc_ - 07.03.2012, 06:54
Re: rCmd.inc - Easiest way to create commands! - by Jack_Wilson - 07.03.2012, 06:58
Re: rCmd.inc - Easiest way to create commands! - by Stylock - 07.03.2012, 09:12
Re: rCmd.inc - Easiest way to create commands! - by System64 - 07.03.2012, 09:21
Re: rCmd.inc - Easiest way to create commands! - by CyNiC - 07.03.2012, 10:41
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 07.03.2012, 11:05
Re: rCmd.inc - Easiest way to create commands! - by Calgon - 07.03.2012, 11:08
Re: rCmd.inc - Easiest way to create commands! - by Shadow_ - 07.03.2012, 11:32
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 07.03.2012, 18:39
Re: rCmd.inc - Easiest way to create commands! - by Modrlicc - 07.03.2012, 21:07
Re: rCmd.inc - Easiest way to create commands! - by Modrlicc - 07.03.2012, 21:15
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 08.03.2012, 13:57
Respuesta: rCmd.inc - Easiest way to create commands! - by [DOG]irinel1996 - 08.03.2012, 14:02
Re: rCmd.inc - Easiest way to create commands! - by Ricop522 - 08.03.2012, 14:09
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 09.03.2012, 20:04
Re: rCmd.inc - Easiest way to create commands! - by TheArcher - 09.03.2012, 20:23
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 09.03.2012, 21:08
Re: rCmd.inc - Easiest way to create commands! - by Stylock - 09.03.2012, 22:30
Re: rCmd.inc - Easiest way to create commands! - by vpontin - 09.04.2012, 15:33
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 10.04.2012, 22:20
Re: rCmd.inc - Easiest way to create commands! - by DonWade - 10.04.2012, 22:36
Re: rCmd.inc - Easiest way to create commands! - by Juninho_Oakley - 10.04.2012, 22:49
Re: rCmd.inc - Easiest way to create commands! - by Armyw0w - 11.04.2012, 07:49
Re: rCmd.inc - Easiest way to create commands! - by sniperwars - 11.04.2012, 08:04
Re: rCmd.inc - Easiest way to create commands! - by paulor - 12.04.2012, 18:52
Re: rCmd.inc - Easiest way to create commands! - by VendenTTa - 12.04.2012, 20:14
Re: rCmd.inc - Easiest way to create commands! - by vpontin - 13.04.2012, 01:57
Re: rCmd.inc - Easiest way to create commands! - by MrDeath537 - 13.04.2012, 10:52
Re: rCmd.inc - Easiest way to create commands! - by dPlaYer_ - 13.04.2012, 16:51
Re: rCmd.inc - Easiest way to create commands! - by Biesmen - 18.04.2012, 07:12
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 21.04.2012, 10:12
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 21.04.2012, 12:17
Re: rCmd.inc - Easiest way to create commands! - by StreetGT - 21.04.2012, 12:40
Re: rCmd.inc - Easiest way to create commands! - by Ainseri - 21.04.2012, 14:24
Re: rCmd.inc - Easiest way to create commands! - by RoacH` - 21.04.2012, 14:44
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 21.04.2012, 15:02
Re: rCmd.inc - Easiest way to create commands! - by Ainseri - 21.04.2012, 15:11
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 21.04.2012, 21:06
Re: rCmd.inc - Easiest way to create commands! - by Ainseri - 21.04.2012, 21:27
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 21.04.2012, 21:45
Re: rCmd.inc - Easiest way to create commands! - by Hiddos - 21.04.2012, 21:49
Re: rCmd.inc - Easiest way to create commands! - by Ainseri - 21.04.2012, 21:52
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 22.04.2012, 13:51
Re: rCmd.inc - Easiest way to create commands! - by niels44 - 22.04.2012, 20:54
Re : rCmd.inc - Easiest way to create commands! - by Naruto_Emilio - 22.04.2012, 21:40
Re: rCmd.inc - Easiest way to create commands! - by Britas - 23.04.2012, 08:02
Re: rCmd.inc - Easiest way to create commands! - by SeoToX - 23.04.2012, 13:19
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 23.04.2012, 21:15
Re: rCmd.inc - Easiest way to create commands! - by Jason` - 24.04.2012, 03:20
Re: rCmd.inc - Easiest way to create commands! - by Ainseri - 24.04.2012, 14:50
Re: rCmd.inc - Easiest way to create commands! - by niels44 - 24.04.2012, 17:55
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 24.04.2012, 18:59
Re: rCmd.inc - Easiest way to create commands! - by SampLoverNo123 - 25.04.2012, 05:08
Respuesta: rCmd.inc - Easiest way to create commands! - by vampirmd - 25.04.2012, 05:14
Re: rCmd.inc - Easiest way to create commands! - by Biesmen - 25.04.2012, 07:25
Re: rCmd.inc - Easiest way to create commands! - by niels44 - 25.04.2012, 18:46
Re: rCmd.inc - Easiest way to create commands! - by zSuYaNw - 25.04.2012, 20:33
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 25.04.2012, 21:04
Re: rCmd.inc - Easiest way to create commands! - by niels44 - 26.04.2012, 17:28
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 26.04.2012, 17:57
Re: rCmd.inc - Easiest way to create commands! - by niels44 - 26.04.2012, 18:39
Re: rCmd.inc - Easiest way to create commands! - by raider19rus - 27.04.2012, 11:12
Re: rCmd.inc - Easiest way to create commands! - by Rudy_ - 27.04.2012, 13:40
Re: rCmd.inc - Easiest way to create commands! - by iCMDX - 28.04.2012, 17:38
Re: rCmd.inc - Easiest way to create commands! - by Dragony92 - 28.04.2012, 18:42
Re: rCmd.inc - Easiest way to create commands! - by Arnold_Collins - 28.04.2012, 20:03
Re: rCmd.inc - Easiest way to create commands! - by Hiddos - 02.05.2012, 16:56
Re: rCmd.inc - Easiest way to create commands! - by Mr.R - 08.05.2012, 09:37
Re: rCmd.inc - Easiest way to create commands! - by iggy1 - 09.05.2012, 09:26
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 17.05.2012, 08:46
AW: rCmd.inc - Easiest way to create commands! - by Dominik. - 28.05.2012, 15:42
Respuesta: rCmd.inc - Easiest way to create commands! - by Gryphus One - 02.06.2012, 18:05
Re: Respuesta: rCmd.inc - Easiest way to create commands! - by TheRoss - 07.06.2012, 16:18
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 16.06.2012, 15:58
Re: rCmd.inc - Easiest way to create commands! - by Kiwar_El - 16.06.2012, 16:06
Respuesta: rCmd.inc - Easiest way to create commands! - by Gryphus One - 16.06.2012, 16:12
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 16.06.2012, 16:23
Re: rCmd.inc - Easiest way to create commands! - by Jonny5 - 16.06.2012, 16:32
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 16.06.2012, 16:36
Re: rCmd.inc - Easiest way to create commands! - by TheRoss - 16.06.2012, 17:43
Re: rCmd.inc - Easiest way to create commands! - by Niko_boy - 16.06.2012, 18:09
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 16.06.2012, 18:52
Re: rCmd.inc - Easiest way to create commands! - by TheRoss - 16.06.2012, 19:11
Re: rCmd.inc - Easiest way to create commands! - by Hiddos - 13.08.2012, 08:37
Re: rCmd.inc - Easiest way to create commands! - by Erdbeerpudding - 14.10.2012, 12:09
Re: rCmd.inc - Easiest way to create commands! - by Plovix - 22.10.2012, 16:18
AW: rCmd.inc - Easiest way to create commands! - by Logan_Adams - 03.01.2013, 20:50
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 04.01.2013, 17:42
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 05.01.2013, 15:26
Re: rCmd.inc - Easiest way to create commands! [NEW v0.2.0 ─ 6/01/2013] - by RyDeR` - 05.01.2013, 22:24
Re: rCmd.inc - Easiest way to create commands! - by vMapper - 06.01.2013, 04:09
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 06.01.2013, 09:04
Re: rCmd.inc - Easiest way to create commands! - by Logan_Adams - 08.01.2013, 12:43
Re: rCmd.inc - Easiest way to create commands! - by SiDiCeR - 02.02.2013, 21:02
Re: rCmd.inc - Easiest way to create commands! - by Biesmen - 03.02.2013, 08:56
Re: rCmd.inc - Easiest way to create commands! - by Biesmen - 03.02.2013, 10:40
Re: rCmd.inc - Easiest way to create commands! - by SiDiCeR - 03.02.2013, 11:47
Re: rCmd.inc - Easiest way to create commands! - by Hiddos - 17.02.2013, 10:39
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 06.07.2013, 15:38
Re: rCmd.inc - Easiest way to create commands! - by SsHady - 06.07.2013, 16:19
Re: rCmd.inc - Easiest way to create commands! - by Salim_Karaja - 06.07.2013, 18:12
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 06.07.2013, 18:25
Re: rCmd.inc - Easiest way to create commands! - by Imperealist - 26.07.2013, 19:00
Re: rCmd.inc - Easiest way to create commands! - by RyDeR` - 27.07.2013, 07:02
Re: rCmd.inc - Easiest way to create commands! - by KingServerIRAN - 08.07.2015, 12:30

Forum Jump:


Users browsing this thread: 1 Guest(s)