Need help with a string
#1

pawn Код:
CMD:respawnallcars(playerid)
{
    new string[128];
    if(IsPlayerConnected(playerid))
        {
            if(PlayerInfo[playerid][pAdmin] < 2)
            {
                SendClientMessage(playerid, COLOR_GRAD1, "You are not authorized to do this!");
                return 1;
            }
            new bool:unwanted[MAX_VEHICLES];
            for(new player=0; player<MAX_PLAYERS; player++)
            {
                if(IsPlayerInAnyVehicle(player)) { unwanted[GetPlayerVehicleID(player)]=true; }
            }
            for(new car = 1; car <= MAX_VEHICLES; car++)
            {
                if(!unwanted[car]) SetVehicleToRespawn(car);
            }
            format(string, sizeof(string), "SERVER: All unused cars were respawned by %s", sendername);
            SendClientMessageToAll(COLOR_YELLOW, string);
        }
    return 1;
}
The command works but the string doesn't send, help please
Reply
#2

Because your server crashes with out of bounds error. Install crashdetect to see for yourself.

Either start counting cars from 0:
pawn Код:
for(new car = 0; car < MAX_VEHICLES; car++)
{
    if(!unwanted[car]) SetVehicleToRespawn(car + 1);
}
Or sacrifice slot 0 in your array to be unused and add one slot more.
pawn Код:
new bool:unwanted[MAX_VEHICLES + 1];
Reply
#3

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Because your server crashes with out of bounds error. Install crashdetect to see for yourself.

Either start counting cars from 0:
pawn Код:
for(new car = 0; car < MAX_VEHICLES; car++)
{
    if(!unwanted[car]) SetVehicleToRespawn(car + 1);
}
Or sacrifice slot 0 in your array to be unused and add one slot more.
pawn Код:
new bool:unwanted[MAX_VEHICLES + 1];
So, changing it to 0 will make the string work?
Reply
#4

Just test it. Yes, it will, BUT focus on this
pawn Код:
SetVehicleToRespawn(car + 1);
Your array indexes will be -1 in relation to samp vehicle identifiers.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)