2 Dudas "cortitas".
#1

Hola a todos, tengo en mi OnPlayerText que detecte cuando un admin estб en servicio y le mande antes de su nombre un texto ("Admin:").

pawn Код:
if(PlayerInfo[playerid][Servicio] >= 1) { //PlayerInfo[playerid][Servicio] = 0;
        new string[128]; GetPlayerName(playerid,string,sizeof(string));
        format(string,sizeof(string),"Admin %s: %s",string,text[1]); SendClientMessageToAll(COLOR_PINK,string);
        return 0;
    }
Pero cuando el administrador escribe normalmente "Hola" como deberнa ser, sale asн:

Admin Ejemplo: ola

Se "come" una letra, a si que me podrнan corregir que hice mal?

__________________________________________________ _________________________________________


Ahora la segunda duda es como hacer para que cuando un jugador comъn escriba en el chat la id de un jugador salga el nombre de este.

Explicaciуn: Escribo en el chat id1 y sale automбticamente el nombre del id1 que serнa ejemplo Pepito.

Juan: (Escribiу) id7
Juan: (Saliу en el chat) Pepito


De antemano muchas gracias.
Reply
#2

Pregunto yo, en mi santa ignorancia, їpor quй tienes text[1]? їNo deberнa ser text?

pawn Код:
if(PlayerInfo[playerid][Servicio] >= 1) { //PlayerInfo[playerid][Servicio] = 0;
        new string[128]; GetPlayerName(playerid,string,sizeof(string));
        format(string,sizeof(string),"Admin %s: %s",string,text); SendClientMessageToAll(COLOR_PINK,string);
        return 0;
    }
Si no me equivoco, estas empezando desde el carбcter 1, eso salta el primer carбcter y comienza desde el segundo (H = 0, o = 1...).
Reply
#3

A tu 1є pregunta:
pawn Код:
if(PlayerInfo[playerid][Servicio] >= 1)
{ //PlayerInfo[playerid][Servicio] = 0;
    new string[128];
    GetPlayerName(playerid, string, MAX_PLAYER_NAME);
    format(string, 128, "Admin %s: %s", string, text);
    SendClientMessageToAll(COLOR_PINK,string);
    return 0;
}
Sobre tu segunda duda, si es posible, deberias parsear toda la linea en busca de id{numero} (puedes utilizar sscanf) para una mayor performance, o el plugin de regex (Expresiones regulares). Luego deberias ver si el '{numero}' corresponde a un id valido y obtener el nombre de dicho jugador para luego colocarlo en ese lugar.

Edit: Edu fue mas rapido para el 1є problema.
Reply
#4

Quote:
Originally Posted by Edugta.
Посмотреть сообщение
Pregunto yo, en mi santa ignorancia, їpor quй tienes text[1]? їNo deberнa ser text?

pawn Код:
if(PlayerInfo[playerid][Servicio] >= 1) { //PlayerInfo[playerid][Servicio] = 0;
        new string[128]; GetPlayerName(playerid,string,sizeof(string));
        format(string,sizeof(string),"Admin %s: %s",string,text); SendClientMessageToAll(COLOR_PINK,string);
        return 0;
    }
Si no me equivoco, estas empezando desde el carбcter 1, eso salta el primer carбcter y comienza desde el segundo (H = 0, o = 1...).
Hmm, estaba haciendo otra cosa y al hacerlo rбpido creo que me confundн y no encontrй el error (fail), pero de todas formas gracias por ayudar.

EDIT: Chaoz, їme podrнas mostrar un ejemplo?
Reply
#5

No se me ocurrio un ejemplo, por lo cual te dejo el codigo casi listo:

pawn Код:
#include <a_samp>

new names[][MAX_PLAYER_NAME] = {"Nombre1", "Nombre 2", "Testing", "Mas nombres"};

public OnFilterScriptInit()
{
    Analizar("Esta es una cadena con id2 y mas texto luego.");
    return 1;
}

stock Analizar(const string[])
{
    new len = strlen(string);
    if(!len || len > (128 - MAX_PLAYER_NAME) || strfind(string, "id", false) == -1)
        return print(string);
    new pos, bool:first, tmp[128], i;
    pos = strfind(string, "id", false);
    first = true;
    i = pos + 2;
    while(i < (pos + 5))
    {
        if(!('0' <= string[i] <= '9'))
        {
            if(first)
                return print(string);
            break;
        }
        strcat(tmp, string[i], 3);
        first = false;
        i++;
    }
    new val = strval(tmp);
    if(sizeof(names) >= val)        //Reemplazar por "if(IsPlayerConnected(tmp))"
    {
        new res[128];
        strmid(res, string, 0, pos);
        strcat(res, names[val]);    //Reemplazar names[val] por el nombre del jugador con el id 'tmp'
        strmid(tmp, string, i, len);
        strcat(res, tmp);
        return print(res);
    }
    return print(string);
}
Si hay alguna parte que no entiendes, avisame.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)