06.03.2012, 22:24
(
Последний раз редактировалось RyDeR`; 05.01.2013 в 22:33.
Причина: Update topic for new version (v0.2.0)
)
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
NEW (IMPORTANT NOTES):
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)
Note the beastliness of sscanf integrated (with optional parameters and stuff).
Please make sure to use & before all your non-array variables (integers, floats, ..., NOT playerid and success).
Beautiful, isn't it?
Note that there are no parameters.
Some float example. Again, please don't forget the & sign!
Callback(s)
We have two callbacks:
This gets called before the actual command gets executed. So returning 0 here means the command won't be executed.
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.
Download
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, ...)
- 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; }
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;
}
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;
}
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;
}
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;
}
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;
}
Callback(s)
We have two callbacks:
pawn Код:
forward OnPlayerCommandReceived(playerid, cmdtext[]);
pawn Код:
forward OnPlayerCommandPerformed(playerid, cmdtext[], success);
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;
}
- 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!
- 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.
- 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:
String Character Integer Float User name/id Hex Binary sci or dfuhb - Fixed a bug where the stack didn't get restored when your command was incomplete.
- Changed the whole syntax so there's not rCmd_Init anymore (thanks ******):
- 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, ...)
- 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; }