Problema con SendClientMessage
#1

Hola, tengo el siguiente problema, Cuando pongo /recompensas analiza a cada jugador que hay conectado y manda el mensaje por cada jugador anializado.
Por ejemplo: Supongamos que en mi server hay 10 jugadores, y solo 2 tienes recompensa. Al poner /recompensa saldria lo siguiente
Код:
No hay Recompensas.
No hay Recompensas.
No hay Recompensas.
Godoy32 - Total [$20000]
Godoy - Total [$10000]
No hay Recompensas.
No hay Recompensas.
No hay Recompensas.
No hay Recompensas.
No hay Recompensas.
Cuando deberia salir
Код:
Godoy32 - Total [$20000]
Godoy - Total [$10000]
Acб esta el cуdigo para que lo puedan ver.


pawn Код:
dcmd_recompensas (playerid, params[])
{
    #pragma unused params
    new stingEX[256], i, count;
    for (i = 0; i < GetMaxPlayers(); i++)
    {
        if (IsPlayerConnected(i))
        {
            if (Cantidad[i] > 0) count ++;
            {
                if (count >= 1)
                {
                    format( stingEX, sizeof(stingEX),"- %s - Total [$%i]\n", pNombre(i), Cantidad[i]);
                    SendClientMessage(playerid,-1,stingEX);
                }
                else
                {
                    SendClientMessage(playerid, -1, "No hay Recompensas.");
                }
            }
        }
    }
    return 1;
}
Reply
#2

pawn Код:
else
                {
                    SendClientMessage(playerid, -1, "No hay Recompensas.");
                }
Entonces para que queres esto si no queres que se mande no? :/

pd: en pawn las variables se inicializan implicitamente a cero? pregunto, porque si no es asi, inicializala, porque acumula valores basura y te puede llegar a dar cualquier cosa

Saludos
Reply
#3

intenta asi:
pawn Код:
dcmd_recompensas (playerid, params[])
{
    #pragma unused params
    new stingEX[X], count;
    for(new i; i<GetMaxPlayers(); i++){
        if(IsPlayerConnected(i) && Cantidad[i]){
            count++;
            format(stringEX, sizeof(stringEX), "- %s - Total [$%i]\n", pNombre(i), Cantidad[i]);
            SendClientMessage(playerid,-1,stingEX);
        }
    }
    if(!count)return SendClientMessage(playerid, -1, "No hay recompenzas");
    return 1;
}
EDIT:

Quote:
Originally Posted by DreamOnIt
Посмотреть сообщение
en pawn las variables se inicializan implicitamente a cero?
Si, las variables se inicializan por defecto con el valor 0.
Reply
#4

Quote:
Originally Posted by the_chaoz
Посмотреть сообщение
intenta asi:
pawn Код:
dcmd_recompensas (playerid, params[])
{
    #pragma unused params
    new stingEX[X], count;
    for(new i; i<GetMaxPlayers(); i++){
        if(IsPlayerConnected(i) && Cantidad[i]){
            count++;
            format(stringEX, sizeof(stringEX), "- %s - Total [$%i]\n", pNombre(i), Cantidad[i]);
            SendClientMessage(playerid,-1,stingEX);
        }
    }
    if(!Cantidad[i])return SendClientMessage(playerid, -1, "No hay recompenzas");// <--
    return 1;
}
En ese lugar 'i' no existe.
Reply
#5

pawn Код:
dcmd_recompensas( playerid, params[ ] )
{
    #pragma unused params

    new bString[ MAX_CLIENT_MSG ], pName[ MAX_PLAYER_NAME ], counter; bString = "* ";

    SendClientMessage( playerid, COLOR_GREEN, "Recompensas:" );

    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if ( pData[ i ][ P_BOUNTY ] ) //AQUI PON TU VARIABLE DE LAS RECOMPENSAS
        {
            GetPlayerName( i, pName, MAX_PLAYER_NAME );

            if ( counter > 2 )
            {
                SendClientMessage( playerid, COLOR_YELLOW, bString );
                bString = "* ";
                format( bString, sizeof( bString ), "%s%s(%d)($%d), ", bString, pName, i,pData[ i ][ P_BOUNTY ] );//PON TU VARIABLE DE LAS RECOMPENSAS
                counter = 1;
            }

            else
            {
                format( bString, sizeof( bString ), "%s%s(%d)($%d), ", bString, pName, i, pData[ i ][ P_BOUNTY ] );// PON TU VARIABLE DE LAS RECOMPENSAS
                counter++;
            }
        }
    }

    if ( strlen( bString[ 2 ] ) )
        SendClientMessage( playerid, COLOR_YELLOW, bString );

    return 1;
}
Reply
#6

xq me confundi, es count. disculpas (ahi lo arregle)
Reply
#7

Quote:
Originally Posted by the_chaoz
Посмотреть сообщение
intenta asi:
pawn Код:
dcmd_recompensas (playerid, params[])
{
    #pragma unused params
    new stingEX[X], count;
    for(new i; i<GetMaxPlayers(); i++){
        if(IsPlayerConnected(i) && Cantidad[i]){
            count++;
            format(stringEX, sizeof(stringEX), "- %s - Total [$%i]\n", pNombre(i), Cantidad[i]);
            SendClientMessage(playerid,-1,stingEX);
        }
    }
    if(!count)return SendClientMessage(playerid, -1, "No hay recompenzas");
    return 1;
}
EDIT:




Si, las variables se inicializan por defecto con el valor 0.
Me tira 4 errores
Код:
C:\Documents and Settings\Godoy\Mis documentos\GTA San Andreas User Files\SAMP\Server 6\gamemodes\server.pwn(594) : error 017: undefined symbol "X"
C:\Documents and Settings\Godoy\Mis documentos\GTA San Andreas User Files\SAMP\Server 6\gamemodes\server.pwn(594) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Godoy\Mis documentos\GTA San Andreas User Files\SAMP\Server 6\gamemodes\server.pwn(594) : error 017: undefined symbol "count"
C:\Documents and Settings\Godoy\Mis documentos\GTA San Andreas User Files\SAMP\Server 6\gamemodes\server.pwn(594) : fatal error 107: too many error messages on one line
Quote:
Originally Posted by DreamOnIt
Посмотреть сообщение
pawn Код:
else
                {
                    SendClientMessage(playerid, -1, "No hay Recompensas.");
                }
Entonces para que queres esto si no queres que se mande no? :/

pd: en pawn las variables se inicializan implicitamente a cero? pregunto, porque si no es asi, inicializala, porque acumula valores basura y te puede llegar a dar cualquier cosa

Saludos
Para que haga una funciуn y no se quede en blanco.

Quote:
Originally Posted by dis77urbio
Посмотреть сообщение
pawn Код:
dcmd_recompensas( playerid, params[ ] )
{
    #pragma unused params

    new bString[ MAX_CLIENT_MSG ], pName[ MAX_PLAYER_NAME ], counter; bString = "* ";

    SendClientMessage( playerid, COLOR_GREEN, "Recompensas:" );

    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if ( pData[ i ][ P_BOUNTY ] ) //AQUI PON TU VARIABLE DE LAS RECOMPENSAS
        {
            GetPlayerName( i, pName, MAX_PLAYER_NAME );

            if ( counter > 2 )
            {
                SendClientMessage( playerid, COLOR_YELLOW, bString );
                bString = "* ";
                format( bString, sizeof( bString ), "%s%s(%d)($%d), ", bString, pName, i,pData[ i ][ P_BOUNTY ] );//PON TU VARIABLE DE LAS RECOMPENSAS
                counter = 1;
            }

            else
            {
                format( bString, sizeof( bString ), "%s%s(%d)($%d), ", bString, pName, i, pData[ i ][ P_BOUNTY ] );// PON TU VARIABLE DE LAS RECOMPENSAS
                counter++;
            }
        }
    }

    if ( strlen( bString[ 2 ] ) )
        SendClientMessage( playerid, COLOR_YELLOW, bString );

    return 1;
}
Tambiйn me tira 4 errores
(Parecidos a los de arriba)
Reply
#8

prueba asi:

pawn Код:
dcmd_recompensas (playerid, params[])
{
    #pragma unused params
    new stingEX[256], count;
    for(new i; i<GetMaxPlayers(); i++){
        if(IsPlayerConnected(i) && Cantidad[i]){
            count++;
            format(stringEX, sizeof(stringEX), "- %s - Total [$%i]\n", pNombre(i), Cantidad[i]);
            SendClientMessage(playerid,-1,stingEX);
        }
    }
    if(!count)return SendClientMessage(playerid, -1, "No hay recompenzas");
    return 1;
}
Reply
#9

pawn Код:
dcmd_recompensas (playerid, params[])
{
    #pragma unused params
    new stingEX[128], count;
    for(new i; i<GetMaxPlayers(); i++){
        if(IsPlayerConnected(i) && Cantidad[i]){
            count++;
            format(stringEX, sizeof(stringEX), "- %s - Total [$%i]\n", pNombre(i), Cantidad[i]);
            SendClientMessage(playerid,-1,stingEX);
        }
    }
    if(!count)return SendClientMessage(playerid, -1, "No hay recompenzas");
    return 1;
}
MAX_STRING 128
Reply
#10

de hecho puede ser seteada mas eficientemente como: "[20+MAX_PLAYER_NAME]".
por eso la deje como X y utilize sizeof.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)