Please Explain "Team Vehicles"
#9

The reason these roleplay modes are scripting like that, are because, simply there not meant to be edited, so there just extremely static.

Try this, it's basic array work

More information: https://sampwiki.blast.hk/wiki/Scripting_Basics#Arrays

Put this below your includes, outside of any callback.

pawn Код:
new
    Vehicle[MAX_VEHICLES] = {-1,...};
That makes a new array 'Vehicle' with the size of the constant define 'MAX_VEHICLES' (2000) and sets every cell to -1.

Now, it depends on how you're planning it to work, you will have to assign a vehicle to every cell, for example:

pawn Код:
Vehicle[0] = CreateVehicle(411, 0.0, 0.0, 0.0, 0.0, -1, -1, -1);
Vehicle[1] = CreateVehicle(411, 0.0, 0.0, 0.0, 0.0, -1, -1, -1);
Vehicle[2] = CreateVehicle(411, 0.0, 0.0, 0.0, 0.0, -1, -1, -1);
Vehicle[3] = CreateVehicle(411, 0.0, 0.0, 0.0, 0.0, -1, -1, -1);
But that's going to be alot for lots of vehicles, I prefer using files and sscanf2, due to sscanf2 being able to read deliminators.

But you can use it like that if you wish .

for destroying only them vehicles you created with the array, you just use:

pawn Код:
for(new a = 0; a < sizeof(Vehicle); a++)
{
    if(Vehicle[a] == -1) continue;
   
    DestroyVehicle(Vehicle[a]);
}
That loops through all cells of 'Vehicle' (2000 iterations, so you may want to change the value of Vehicle)
Checks if that cell is -1, if it is, it will skip that iteration, if it's not, it will destroy the vehicle, and carry on with the loop.

If you want to check if a cetin vehicle is one of them vehicles you created with the Array, you use:

pawn Код:
for(new a = 0; a < sizeof(Vehicle); a++)
{
    if(vehicleid == Vehicle[a])
    {
        //Do something if the vehicle IS one of them vehicle created using the Array.
       
        RemovePlayerFromVehicle(playerid);
    }
}
That loops through all cells of Vehicle (again, that's 2000 iterations, should change the size of Vehicle to something smaller), checks if the vehicleid the player is driving is one of them vehicles, if it is, it removes them from the vehicle, otherwise it just keeps going through all vehicles until the if statement returns true, or there's not match.

You should make the size of Vehicle to the amount of vehicles You're planning on making +1, but I'd make it a phew over what I'd make, to make sure If I forget, it won't cause problems.
Reply


Messages In This Thread
Please Explain "Team Vehicles" - by Scenario - 17.07.2010, 04:12
Re: Please Explain "Team Vehicles" - by Kar - 17.07.2010, 04:18
Re: Please Explain "Team Vehicles" - by Scenario - 17.07.2010, 04:26
Re: Please Explain "Team Vehicles" - by Kar - 17.07.2010, 04:30
Re: Please Explain "Team Vehicles" - by Scenario - 17.07.2010, 04:36
Re: Please Explain "Team Vehicles" - by Venturas - 17.07.2010, 05:19
Re: Please Explain "Team Vehicles" - by Kar - 17.07.2010, 05:57
Re: Please Explain "Team Vehicles" - by Scenario - 17.07.2010, 06:27
Re: Please Explain "Team Vehicles" - by Joe_ - 17.07.2010, 09:47

Forum Jump:


Users browsing this thread: 1 Guest(s)