Issues with looping
#1

Hey,
I'm basically creating a /veh command.
The object of this command is to create a car for the administrator who executed the command.
Now, it works. But it will only spawn one vehicle. after that one is spawned, the command wont work at all.
I want to be able to spawn multiple vehicles at once...
My code:


pawn Код:
#define MAX_TEMP_CARS 20

enum avInfo //Admin Vehicle Info
{
    ModelID,
    Colour[2],
    Float:Posx,
    Float:Posy,
    Float:Posz,
    Float:Posa,
    Used,
    ID
}

new CreatedCars[MAX_TEMP_CARS][avInfo];


CMD:veh(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 5)
    {
        new model, colours[2], car;
        if(sscanf(params, "iii", model, colours[0], colours[1])) return SendClientMessageEx(playerid, COLOR_WHITE, "[Server] Usage: /veh [model] [colour1] [colour2]");
        if(model < 400 || model > 611) return SendClientMessageEx(playerid, COLOR_WHITE, "[Server] Error: Correct vehicle models range from 400 to 611.");
        if(colours[0] < 0 || colours[0] > 255 || colours[1] < 0 || colours[1] > 255) return SendClientMessageEx(playerid, COLOR_WHITE, "[Server] Error: Correct vehicle colours range from 0 to 255.");
        for(new i, j = MAX_TEMP_CARS; i != j; i++)
        {
            if(CreatedCars[i][Used] == 0)
            {
                SendClientMessageEx(playerid, COLOR_WHITE, "[Server] Spawning vehicle...");
                GetPlayerPos(playerid, CreatedCars[i][Posx], CreatedCars[i][Posy], CreatedCars[i][Posz]);
                GetPlayerFacingAngle(playerid, CreatedCars[i][Posa]);
                CreatedCars[i][Used] = 1;
                car = CreateVehicle(model, CreatedCars[i][Posx], CreatedCars[i][Posy], CreatedCars[i][Posz], CreatedCars[i][Posa], colours[0], colours[1], 0);
                CreatedCars[i][ID] = car;
                printf("%i", car);
                SendClientMessageEx(playerid, COLOR_WHITE, "[Server] Vehicle spawned with ID: %i", car);
                break;
            }
            return 1;
        }
        return 1;
    }
    else return SendClientMessageEx(playerid, COLOR_WHITE, "[Server] Insufficient permissions.");
}
I'm quite new to using loops with things like this so I'm eager to learn.
Reply
#2

Remove return 1 from the loop.
Reply
#3

Worked, thanks.
Reply
#4

Quote:
Originally Posted by Jacksta21
Посмотреть сообщение
pawn Код:
}
            return 1;
just remove this
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)