PDA

View Full Version : [Resuelto] Crear comandos con 3 o mas parametros.


M1GU3L
19/11/2009, 02:57 PM
Hola, si alguien me pudiera ayudar y dar un ejemplo de como hacer un comando con más de 3 parametros sería apreciado.
Ejm:

/y [Player ID] [Commando] [Parametro 1] [Opcional]

/y 14 cambiarvida 70.0

O

/y 16 colorvehiculo verde negro (incluyendo el parametro opcional).

Gracias.

Laconcha
19/11/2009, 06:09 PM
Osea quieres crear un comando para hacer que otros hagan un comando?

M1GU3L
19/11/2009, 07:39 PM
Si quisiera que alguien hiciera todo por mi, no estaría pidiendo ayuda, me buscaría un scripter. Solo necesito un ejemplo para empezar de allí. No tiene que ser el que di, puede ser de cualquier tipo pero con mas de 2 parametros.

Olvidenlo, ya encontre la respuesta:


Here is a demonstration of the method I use for second commands in a command:

// somewhere on the top of the script:
#define COLOR_RED 0xFF0000AA

dcmd_house(playerid, params[])
{
new
cmd2[64], // second command will be stored in this array
string[128]; // for additional parameters in the second commands (see below)
if (Account[playerid][pAdminLevel] >= 20) // admin level check
{
if (sscanf(params, "s ", cmd2) != 0) // cmd2 will become the first parameter, sscanf is tricked with the extra space to stop processing the string
{
// send proper command syntax for player, include only the first parameters (the second commands):
SendClientMessage(playerid, COLOR_RED, "Usage: /house <add / whatever more params here>");
return 1; // exit
}

if (strcmp("add", cmd2, true, 3) == 0) // check if the first 3 (!) characters of cmd2 are the same as 'add'
{
if (sscanf(params, "ss", cmd2, string) != 0) // read the additional parameters after the second command
{
// send proper syntax again, now with the needed parameters for the second command the player typed (in this case 'add'):
SendClientMessage(playerid, COLOR_RED, "Usage: /house <add> <owner>"); // we are expecting only one extra parameter, the 'owner'
return 1; // exit
}
/*
// you may want to add this extra check for more security ^^
if (strlen (string) > MAX_PLAYER_NAME) return SendClientMessage(playerid, COLOR_RED, "The given owner name is too long!");
*/
// command code follows (yours), note that string is now the owner
new
Float:x,
Float:y,
Float:z,
Float:angle;
GetPlayerPos(playerid,x,y,z);
GetPlayerFacingAngle(playerid,angle);
AddHouse(owner,x,y,z,GetPlayerVirtualWorld(playeri d),GetPlayerInterior(playerid),angle,0/*exitx*/,0/*exity*/,0/*exitz*/,1337/*exitinterior*/,0/*exitangle*/,0/*owned*/,0/*rentable*/,0/*rentcost*/,0/*houseprice*/,0/*locked*/);
return 1; // successful, exit
}
/*
// additional second commands may come here in this format:
else if (strcmp("remove", cmd2, true, 6) == 0)
{
// check for other params if any
// check validness of other params
// code follows
}
else if (strcmp("info", cmd2, true, 4) == 0)
{
// check for other params if any
// check validness of other params
// code follows
}
// you may add as many as you want
*/
}
/*
// you may want to send this warning if player if not a level 20 admin:
else SendClientMessage(playerid, SOME_COLOR, "This is a level 20 admin command!");
*/
return 1; // end of command
}

This works for me, I use it in multiple commands, hope it helps.


Gracias player007.

Laconcha
19/11/2009, 11:44 PM
Pues me malentendiste, no te estaba reprochando nada, solo era una pregunta para ver que querias :|

M1GU3L
19/11/2009, 11:48 PM
Disculpa por la mala respuesta.

CristianTdj
19/12/2009, 07:47 PM
Yo lo necesitaría para pintar el coche. Pero solo 2 parámetros.