CMD /id
#1

Hola,
Quisiera saber como hacer que el comando /id se pueda seleccionar la ID o Nombre, ejemplo;
/id ID y se mostrarнa el nombre de la persona y su ID y si estб offline pues error.., ahora tambiйn que se pueda usar /id pero con nombre osea /id Nombre_Apellido y se muestre si estб online el jugador etc. Tambiйn quisiera saber como hacer con el /id Nombre_Apellido que por ejemplo, coloque /id J y aparezca todos los usuarios que contengan esa letra J...

Bбsicamente tengo йsto, pero no se que hacer:

Код:
CMD:id(playerid, params[])
{
	new idname;
	if(sscanf(params, "u", idname)) return SendClientMessage(playerid, COLOR_GRAD, "Modo de uso: /id [ID - Nombre_Apellido]");
	if(idname == playerid) return SendClientMessage(playerid, COLOR_GRAD, "Te has seleccionado a ti mismo.");
  	if(IsPlayerNPC(idname)) return SendClientMessage(playerid, COLOR_GRAD, "Has seleccionado a un NPC.");
	if(!IsPlayerConnected(idname)) return SendClientMessage(playerid, COLOR_GRAD, "Jugador invбlido.");
	new NombreOn[24];
	GetPlayerName(idname, NombreOn, 24);
	format(strinx, sizeof(strinx), "%s (ID:%d)", NombreOn, idname);
	SendClientMessage(playerid, COLOR_AMARILLO, strinx);
 	return 1;
}
Reply
#2

Creo que podria salirte asi:

PHP код:
CMD:id(playeridparams[])
{
    new
        
nombre[MAX_PLAYER_NAME],
        
player_name[MAX_PLAYER_NAME],
        
string[128];
        
val_id = -1,
        ;
    if(
sscanf(params"s[MAX_PLAYER_NAME]"nombre))
        return 
SendClientMessage(playeridCOLOR_GRAD"Modo de uso: /id [ID - Nombre_Apellido]");
    if(
isnull(nombre))
        return 
SendClientMessage(playeridCOLOR_GRAD"No ingresaste un nombre!");
    if(
IsNumeric(nombre))
    {
        if(((
val_id strval(nombre)) < 0) || val_id GetPlayerPoolSize())
            return 
SendClientMessage(playeridCOLOR_GRAD"ID Invalido!");
        if(!
IsPlayerConnected(val_id))
            return 
SendClientMessage(playeridCOLOR_GRAD"ID Invalido!");
           
GetPlayerName(val_idplayer_nameMAX_PLAYER_NAME);
        
format(stringsizeof(string), "%s [ID: %i]"player_nameval_id);
        
SendClientMessage(playeridCOLOR_AMARILLOstring);
    }
    else
    {
        new
            
bool:users false;
        
SendClientMessage(playerid, -1"Jugadores con el nombre o letra que ingresaste:");
        for(new 
0<= GetPlayerPoolSize(); i++)
        {
            if (
== playerid || !IsPlayerConnected(i))
                continue;
            
GetPlayerName(iplayer_nameMAX_PLAYER_NAME);
              if (!(
strfind(player_namenombretrue) != -1))
                continue;
             
format(stringsizeof(string), "%s [ID: %i] "player_namei);
               
SendClientMessage(playeridCOLOR_AMARILLOstring);
               
users true;
         }
         if(
users != true)
            
SendClientMessage(playerid, -1"Ningun jugador con ese nombre o letra");
    }
     return 
1;

Reply
#3

Bien Zume, necesitarнa la funciуn de IsNumeric.
Reply
#4

http://forum.sa-mp.com/showpost.php?...41&postcount=2
Reply
#5

Quote:
Originally Posted by LatinZ
Посмотреть сообщение
Bien Zume, necesitarнa la funciуn de IsNumeric.
Como dijo _Zume, o:
pawn Код:
stock IsNumeric(const string[]) return !sscanf(string, "{d}");
Necesitaras sscanf [https://sampforum.blast.hk/showthread.php?tid=570927].

@_Zume, dice ahi "define IsNumeric creando un stock." y es una funciуn, y para acabarla la funciуn ni tiene la palabra clave "stock" jaja.
Reply
#6

Usar sscanf con una string sola carece de sentido totalmente, y le das al usuario la posibilidad de hacer un overflow (que el texto que el tipo ingresa sea mayor que la cantidad de memoria que sscanf usa para almacenarla. Directamente usa params

pawn Код:
CMD:id(playerid, params[]) {
    if (IsNumeric(params)) {
        new id = strval(params);
        if (!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "Desconectado");
        new string[80], idName[MAX_PLAYER_NAME];
        GetPlayerName(id, idName, 24);
        format(string, 80, "Nombre: %s", idName);
    } else {
        // el q puso zume
    }
    return 1;
}
Uno de los principios de la buena programaciуn dice que el cуdigo debe ser entendible para cualquiera, las variables y funciones tienen que llamarse por lo que hacen, etc etc
Reply
#7

Bien gracias por vuestra ayuda.

Aquн os dejo por si a otro le sirve, se necesita sscanf, zcmd y foreach.

Код:
CMD:id(playerid, params[]) {
    new nombre[MAX_PLAYER_NAME], player_name[MAX_PLAYER_NAME];
    if(sscanf(params, "s[MAX_PLAYER_NAME]", nombre)) return SendClientMessage(playerid, COLOR_GRAD, "Modo de uso: /id [ID - Nombre_Apellido]");
    if(IsNumeric(params)) {
        new id = strval(params);
        if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "ID invбlida.");
        format(strinx, sizeof(strinx), "%s [ID: %d]", NombreJugador(id), id);
        SendClientMessage(playerid, COLOR_GRAD, strinx);
    } else {
		new bool:users = false;
	    foreach(new i : Player)
	    {
			GetPlayerName(i, player_name, MAX_PLAYER_NAME);
			if(!(strfind(player_name, nombre, true) != -1)) continue;
			format(strinx, sizeof(strinx), "%s [ID: %d] ", player_name, i);
	        SendClientMessage(playerid, COLOR_GRAD, strinx);
	   		users = true;
	    }
	    if(users != true) SendClientMessage(playerid, -1, "Ningun jugador con ese nombre o letra.");
	}
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)