Server Freeze after send command
#1

This is the command:
pawn Код:
CMD:comprarpatente(playerid, params[])
{
    if(Logueado[playerid] == 0) return SendClientMessage(playerid, -1, "{47D751}« ! » {FFFFFF}No estas logueado");
    if(PlayerVCantidad[playerid] == 0) return SendClientMessage(playerid, -1, "{47D751}« ! » {FFFFFF}No tienes vehiculos");
    new string[28], pv = 1;
    while(pv < MAX_PLAYER_VEHICLES)
    {
        if(validcar[PlayerVehicle[playerid][pv]])
        {
            format(string, sizeof(string), "Numero: %d || Vehicleid: %d", pv, PlayerVehicle[playerid][pv]);
            SendClientMessage(playerid, -1, string);
            pv ++;
        }
    }
    return 1;
}
Any idea? Thanks
Reply
#2

I'm pretty sure this line is causing problems: if(validcar[PlayerVehicle[playerid][pv]])
Quick fix
if(validcar(PlayerVehicle[playerid][pv]))
Edit also set bigger string array
Reply
#3

use this
pawn Код:
while(pv < MAX_PLAYER_VEHICLES)
    {
        if(validcar(PlayerVehicle[playerid][pv]))
        {
            format(string, sizeof(string), "Numero: %d || Vehicleid: %d", pv, PlayerVehicle[playerid][pv]);
            SendClientMessage(playerid, -1, string);
           
        }
     pv++;//outside the "if" not inside
    }
the 1st problem is told in the above reply
but the 2nd problem is that pv++ should be out side "if" statement because if one of the car id is not valid then it would result in an infinite loop which would cause the server freeze
Reply
#4

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
use this
pawn Код:
while(pv < MAX_PLAYER_VEHICLES)
    {
        if(validcar(PlayerVehicle[playerid][pv]))
        {
            format(string, sizeof(string), "Numero: %d || Vehicleid: %d", pv, PlayerVehicle[playerid][pv]);
            SendClientMessage(playerid, -1, string);
           
        }
     pv++;//outside the "if" not inside
    }
the 1st problem is told in the above reply
but the 2nd problem is that pv++ should be out side "if" statement because if one of the car id is not valid then it would result in an infinite loop which would cause the server freeze
I have this loops and work fine:

pawn Код:
new pv = 0;
    for(new v = 1; v < MAX_VEHICLES; v ++)
    {
        if(validcar[v])
        {
            if(cInformacion[v][cVenta] == 0)
            {
                if(strcmp(NombreJ(playerid), cInformacion[v][cOwner]) == 0)
                {
                    pv ++;
                    PlayerVehicle[playerid][pv] = v;
                    PlayerVCantidad[playerid] ++;
                }
            }
        }
    }
    return 1;
pawn Код:
CMD:checkvehicles(playerid, params[])
{
    if(Logueado[playerid] == 0) return SendClientMessage(playerid, -1, "{47D751}« ! » {FFFFFF}No estas logueado");
    if(PlayerVCantidad[playerid] == 0) return SendClientMessage(playerid, -1, "{47D751}« ! » {FFFFFF}No tienes vehiculos");
    new string[6], pv = 1;
    while(pv < MAX_PLAYER_VEHICLES)
    {
        if(validcar[PlayerVehicle[playerid][pv]])
        {
            format(string, sizeof(string), "%d: %d", pv, PlayerVehicle[playerid][pv]);
            SendClientMessage(playerid, -1, string);
            print(string);
            pv ++;
        }
    }
    return 1;
}
I'll try anyway
Reply
#5

Quote:
Originally Posted by FullCircle
Посмотреть сообщение
I have this loops and work fine:

pawn Код:
new pv = 0;
    for(new v = 1; v < MAX_VEHICLES; v ++)
    {
        if(validcar[v])
        {
            if(cInformacion[v][cVenta] == 0)
            {
                if(strcmp(NombreJ(playerid), cInformacion[v][cOwner]) == 0)
                {
                    pv ++;
                    PlayerVehicle[playerid][pv] = v;
                    PlayerVCantidad[playerid] ++;
                }
            }
        }
    }
    return 1;
pawn Код:
CMD:checkvehicles(playerid, params[])
{
    if(Logueado[playerid] == 0) return SendClientMessage(playerid, -1, "{47D751}« ! » {FFFFFF}No estas logueado");
    if(PlayerVCantidad[playerid] == 0) return SendClientMessage(playerid, -1, "{47D751}« ! » {FFFFFF}No tienes vehiculos");
    new string[6], pv = 1;
    while(pv < MAX_PLAYER_VEHICLES)
    {
        if(validcar[PlayerVehicle[playerid][pv]])
        {
            format(string, sizeof(string), "%d: %d", pv, PlayerVehicle[playerid][pv]);
            SendClientMessage(playerid, -1, string);
            print(string);
            pv ++;
        }
    }
    return 1;
}
I'll try anyway
It's work, thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)