[Tutorial] Vehicle Data
#8

Quote:
Originally Posted by PowerPC603
View Post
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:
pawn Code:
if (vehicleinfo[vehicleid][IsWorldCar] == true)
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:
pawn Code:
CreateWorldCar()
{
new vehicleid = CreateVehicle(...
vehicleinfo[vehicleid][IsWorldCar] = true;
return vehicleid;
}
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.
Ah, I see. Memory is not an issue on my end, although I haven't worked extensively with vehicle data. I can only think of 2 scripts I used vehicle data for, and they used the method that I used in the tutorial. I'll definitely consider adding your method to the tutorial when I get back to my desktop computer.
Reply


Messages In This Thread
Vehicle Data - by Aerotactics - 01.12.2014, 13:09
Re: Vehicle Data - by Luis- - 01.12.2014, 13:55
Re: Vehicle Data - by Aerotactics - 01.12.2014, 13:56
Re: Vehicle Data - by Luis- - 01.12.2014, 13:57
Re: Vehicle Data - by PowerPC603 - 01.12.2014, 14:01
Re: Vehicle Data - by Aerotactics - 01.12.2014, 14:06
Re: Vehicle Data - by PowerPC603 - 01.12.2014, 14:59
Re: Vehicle Data - by Aerotactics - 01.12.2014, 15:31

Forum Jump:


Users browsing this thread: 4 Guest(s)