01.12.2014, 13:09
(
Last edited by Aerotactics; 01/12/2014 at 01:57 PM.
)
Vehicle Data
Ever wanted to store data for a vehicle? It's very simple. If you know how to store player data, you know how to store vehicle data.
Basics
Let's take a look at 2 key terms:
playerid and vehicleid
Both these terms represent integers, which is why it's possible to create "for" loops starting at zero and passing "i" as a playerid.
What We Know
Let's look at a simple player data table:
From what we know, if we wanted to set a player's money, all we would need to do is change pInfo[playerid][money].
This same concept can be applied to vehicles:
To use this data, all we need is a vehicleid.
Applications
To get a vehicleid, the easiest way would be to assign a vehicle with a custom variable:
To access and change the data, all we would have to do is use vInfo[WorldCar[0]][owner], or whatever you may choose for your variables. WorldCar[0] is a placeholder for an integer, the same way playerid is a placeholder for an integer.
The reason I chose to assign WorldCar to an array would be to easily loop all selected vehicles to detect a specific one easier, or to change 1 variable for all cars at once:
To test the data, you can set up a command to show vehicle data for a vehicle you entered.
After testing to make sure that data is working per vehicle, you can display vehicle data using chat, textdraws, 3dtextlabels, or anywhere you can place text.
I hope this tutorial was somewhat informative, thanks for reading.
Ever wanted to store data for a vehicle? It's very simple. If you know how to store player data, you know how to store vehicle data.
Basics
Let's take a look at 2 key terms:
playerid and vehicleid
Both these terms represent integers, which is why it's possible to create "for" loops starting at zero and passing "i" as a playerid.
What We Know
Let's look at a simple player data table:
pawn Code:
enum playerdata
{
pass[24],
money,
score
}
new pInfo[MAX_PLAYERS][playerdata];
This same concept can be applied to vehicles:
pawn Code:
enum vehicledata
{
owner[24],
engine,
tires
}
new vInfo[MAX_VEHICLES][vehicledata];
Applications
To get a vehicleid, the easiest way would be to assign a vehicle with a custom variable:
pawn Code:
new WorldCar[10];
//Under OnGameModeInIt
WorldCar[0] = CreateVehicle...
WorldCar[1] = CreateVehicle...
The reason I chose to assign WorldCar to an array would be to easily loop all selected vehicles to detect a specific one easier, or to change 1 variable for all cars at once:
pawn Code:
for(new i=0; i<MAX_VEHICLES; i++)
{
vInfo[WorldCar[i]][owner] = "Rental";
}
pawn Code:
CMD:test(playerid, params[])
{
for(new i=0; i<MAX_VEHICLES; i++)
{
if(IsPlayerInVehicle(playerid, WorldCar[i], 0))
{
PrintF("VDATA: owner: %s engine: %i tires: %i", vInfo[WorldCar[i]][owner], vInfo[WorldCar[i]][engine], vInfo[WorldCar[i]][tires]);
}
}
return 1;
}
I hope this tutorial was somewhat informative, thanks for reading.