01.12.2014, 14:59
I would just add a field in the vehicledata enum that holds a bool to indicate if it's a worldvehicle or not.
Then you can check it easily as well, and this way all your data about a vehicle is combined into a single enum.
Otherwise you have multiple arrays, each one holding different data:
- vehicleinfo
- worldinfo
- copcar
- admincars
- whatever else
When you enter a vehicle and you want to know if this entered vehicle is a worldcar, you need to loop through all worldcar indices and see if you find a match.
If you found a match, it's a worldcar.
If you can't find a match, it's not a worldcar.
Putting all that data in one enum (vehicleinfo), removed that loop, speeding up your script as it doesn't need to search for a vehicleid.
The OnPlayerEnterVehicle callback already gives you the vehicleid.
You could easily check if this vehicle is a worldcar:
You don't need a loop to check this.
Or if you use another callback that doesn't give you a vehicleid, just use GetPlayerVehicleID to get the vehicleid you need to access ALL data about that vehicle, as it's all stored into one single enum.
And to make a worldcar, you only need a short function:
This is how my data is stored about every vehicle in my own scripts and it works perfectly.
Your solution works fine too, except you need loops to find data inside arrays, and you use less memory.
But memory is less of an issue these days because computers have more and more memory (mine has 12GB of RAM), a few extra kilobytes won't hurt a true server.
Then you can check it easily as well, and this way all your data about a vehicle is combined into a single enum.
Otherwise you have multiple arrays, each one holding different data:
- vehicleinfo
- worldinfo
- copcar
- admincars
- whatever else
When you enter a vehicle and you want to know if this entered vehicle is a worldcar, you need to loop through all worldcar indices and see if you find a match.
If you found a match, it's a worldcar.
If you can't find a match, it's not a worldcar.
Putting all that data in one enum (vehicleinfo), removed that loop, speeding up your script as it doesn't need to search for a vehicleid.
The OnPlayerEnterVehicle callback already gives you the vehicleid.
You could easily check if this vehicle is a worldcar:
pawn Code:
if (vehicleinfo[vehicleid][IsWorldCar] == true)
Or if you use another callback that doesn't give you a vehicleid, just use GetPlayerVehicleID to get the vehicleid you need to access ALL data about that vehicle, as it's all stored into one single enum.
And to make a worldcar, you only need a short function:
pawn Code:
CreateWorldCar()
{
new vehicleid = CreateVehicle(...
vehicleinfo[vehicleid][IsWorldCar] = true;
return vehicleid;
}
Your solution works fine too, except you need loops to find data inside arrays, and you use less memory.
But memory is less of an issue these days because computers have more and more memory (mine has 12GB of RAM), a few extra kilobytes won't hurt a true server.