Loop through all vehicles.
#1

How can I loop through all vehicles?
If I know that I can set there engine state OnVehicleSpawn to OFF.
Thanks.
Reply
#2

pawn Код:
for(new c = 0; c < MAX_VEHICLES; c++)
Reply
#3

Quote:
Originally Posted by Xabi
Посмотреть сообщение
pawn Код:
for(new c = 0; c < MAX_VEHICLES; c++)
The correct one is
pawn Код:
for( new c = 1; c <= MAX_VEHICLES; c ++ )
Because vehicle IDs start from 1 and finish at 2000.
Reply
#4

I now have this but it doesnt work:

pawn Код:
public OnVehicleSpawn(vehicleid)
{
    for( new c = 1; c <= MAX_VEHICLES; c ++ )
    {
        new engine, lights, alarm, doors, bonnet, boot, objective;
        GetVehicleParamsEx(c, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(c,0,lights,alarm,doors,bonnet,boot,objective);
    }
    return 1;
}
Reply
#5

Ouch. You are looping through all vehicles when any new vehicle spawns. Why not something like
pawn Код:
public OnVehicleSpawn(vehicleid)
{
    new engine, lights, alarm, doors, bonnet, boot, objective;
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
    SetVehicleParamsEx(vehicleid, 0, lights,alarm,doors,bonnet,boot,objective);
    return 1;
}
Reply
#6

Quote:
Originally Posted by arjanforgames
Посмотреть сообщение
I now have this but it doesnt work:

pawn Код:
public OnVehicleSpawn(vehicleid)
{
    for( new c = 1; c <= MAX_VEHICLES; c ++ )
    {
        new engine, lights, alarm, doors, bonnet, boot, objective;
        GetVehicleParamsEx(c, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(c,0,lights,alarm,doors,bonnet,boot,objective);
    }
    return 1;
}
That looks to me like the cars will go into a huge loop.

1st car spawns turn off its engine
2nd car spawns turn off its engine and the 1st cars engine.
3rd car spawns turn off its engine and the 2nd and 1st car engine.

Why dont you set the parameters like:

pawn Код:
public OnVehicleSpawn(vehicleid)
{
    new engine, lights, alarm, doors, bonnet, boot, objective;
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
    SetVehicleParamsEx(vehicleid, 0,lights,alarm,doors,bonnet,boot,objective);
    return 1;
}
Reply
#7

I now have:

pawn Код:
public OnVehicleSpawn(vehicleid)
{
    new engine, lights, alarm, doors, bonnet, boot, objective;
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
    SetVehicleParamsEx(vehicleid, 0,lights,alarm,doors,bonnet,boot,objective);
    return 1;
}

But whenever I use the command /car the engine is already running;

pawn Код:
CMD:car(playerid, params[])
{
    new Float:x, Float:y, Float:z, Float:az;
    new vehid;
    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, az);
    vehid = CreateVehicle(402, x+1, y+5, z, az, -1, -1, 180);
    PutPlayerInVehicle(playerid, vehid, 0);
    return 1;
}
Reply
#8

OnVehicleSpawn is actually OnVehicleRespawn, you have to use SetVehicleParamsEx after you create each vehicle.
Reply
#9

So how would I apply this to vehicles that are made with AddStaticVehicle? (BTW is AddStaticVehicle the best way to add vehicles?)
Reply
#10

Using ManualVehicleEngineAndLights(); (https://sampwiki.blast.hk/wiki/ManualVehicleEngineAndLights) in OnGameModeInit will accomplish this for you.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)