put player in random car
#1

hey,

is there a easyerway to put a player in a random vehicle than doing case 1: createvehicle.. etc

this is for a minigame so it can only include minigame cars

also is there a easyerway than using a varible and a timer to check if he is the only player?
Reply
#2

pawn Код:
new Float:Pos[3];
for(new i;i<MAX_VEHICLES;i++)
{
    GetVehiclePos(random(MAX_VEHICLES + 1),Pos[0],Pos[1],Pos[2]);
    if(Pos[0] == 0 && Pos[1] == 0 && Pos[2] == 0) continue;
    PutPlayerInVehicle(playerid,i);
    return 1;
}
Reply
#3

Why a for? Isn't better a while?
Take the case (also if a bit impossibile) all the random take an invalid car id.
Also the code has no sense... why getting a pos of a vehicle that isn't "i" and then teleporting to "i"?
Код:
new Float:XPos, Float:YPos, Float:ZPos, bool:a, veh_id;  //Don't use arrays, if it's not strictly necessary
while (!a)
{
    veh_id = random(MAX_VEHICLES + 1);
    GetVehiclePos(veh_id),XPos, YPos, ZPos);
    if(XPos != 0 && YPos != 0 && ZPos != 0) 
         {
         PutPlayerInVehicle(playerid,veh_id);
         a = true;
         }
    return 1;
}
Reply
#4

Miss code there.

Your code will fail if there's no vehicle in server.

pawn Код:
new Float:Pos[3],a,b[MAX_VEHICLES];
for(new i;i<MAX_VEHICLES;i++)
{
    a = random(MAX_VEHICLES + 1);
    for(new o;o<MAX_VEHICLES;o++)
    {
        if(b[o] == a)
        {
            i--;
            continue;
        }
    }
    b[i] = a;
    GetVehiclePos(a,Pos[0],Pos[1],Pos[2]);
    if(Pos[0] == 0 && Pos[1] == 0 && Pos[2] == 0) continue;
    PutPlayerInVehicle(playerid,a);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)