08.03.2012, 14:09
Great job!
I think this would be way better if you combined it with sscanf to support optional parameters, arrays etc.
|
public OnGameModeInit()
{
rCmd_Init(car, "iI(-1)I(-1)");
}
rCmd:car(playerid, success, iModel, iColor1, iColor2)
{
//code
return 1;
}
dcmd_help(playerid, params[]) // Alias of /commands
{
return dcmd_commands(playerid,params);
}
rCmd_Init(addcar, "iffffii"); // Init
rCmd:addcar(playerid, success, iModel, Float: fX, Float: fY, Float: fZ, Float: fA, iColor1, iColor2) {
if(!success)
return SendClientMessage(playerid, 0xFF0000FF, "<> Syntax: /addcar [model] [x] [y] [z] [angle] [color1] [color2]");
if(!(400 <= iModel <= 611))
return SendClientMessage(playerid, 0xFF0000FF, "<> Error: Invalid model. Need to be between 400 and 611!");
CreateVehicle(iModel, fX, fY, fZ, fA, iColor1, iColor2, 60);
SendClientMessage(playerid, 0x00FF00FF, "<> You succesfully created the vehicle!");
return 1;
}
rCmd_Init(createveh, "iffffii"); // Init
rCmd:createveh(playerid, success, iModel, Float: fX, Float: fY, Float: fZ, Float: fA, iColor1, iColor2) {
return cmd_addcar(playerid, success, iModel, Float: fX, Float: fY, Float: fZ, Float: fA, iColor1, iColor2);
}
Very good!
Tip: 1° Try to remove the rCmd_Init therefore more complicated for those who will change ZCMD for RCMD. 2° In the parameters a place for players as well, which uses sscanf type "u". Note: I do not know if the translation is nice ... Translated by ****** Translator. PT-BR for EN-US. |
OFFTOPIC: Greetings from Rio Grande do Sul :P
You can get rid of "rCmd_Init", it's just a little tricky. Probably the simplest demonstration of this is y_remote:
|
stock GetPublicNameByIndex(iIdx, szName[], iSize = sizeof(szName)) {
static
s_iBase,
s_iPublics,
s_iNatives,
s_iCount
;
if(!s_iBase) {
#emit LCTRL 1
#emit NEG
#emit STOR.PRI s_iBase
}
if(!s_iPublics) {
new
iAddr
;
#emit LOAD.PRI s_iBase
#emit ADD.C 32
#emit STOR.S.PRI iAddr
#emit LREF.S.PRI iAddr
#emit LOAD.S.ALT iAddr
#emit ADD
#emit CONST.ALT 32
#emit SUB
#emit STOR.PRI s_iPublics
}
if(!s_iNatives) {
new
iAddr
;
#emit LOAD.PRI s_iBase
#emit ADD.C 36
#emit STOR.S.PRI iAddr
#emit LREF.S.PRI iAddr
#emit LOAD.S.ALT iAddr
#emit ADD
#emit CONST.ALT 36
#emit SUB
#emit STOR.PRI s_iNatives
}
if(!s_iCount) {
s_iCount = ((s_iNatives - s_iPublics) >>> 3);
}
if(iIdx < s_iCount) {
new
iPos = (iIdx << 3) + s_iPublics + 4,
iCh,
i
;
#emit LREF.S.PRI iPos
#emit LOAD.ALT s_iBase
#emit ADD
#emit STOR.S.PRI iPos
do {
#emit LREF.S.PRI iPos
#emit STOR.S.PRI iCh
szName[i] = iCh & 0xFF;
iPos++;
} while(szName[i++] != EOS && i <= iSize);
szName[i] = EOS;
return 1;
}
return 0;
}