Collecting data and storing it -
HeLiOn_PrImE - 28.12.2013
Hello there. I just started working on my first sqlite database script and I need some help.
Basically I want to check a vehicle for components. If a vehicle has, for example a body kit installed (alien front back spoiler and roof), I want to collect their ID's and store them.
I know I need to use the "GetVehicleComponent" functions (they should return the ID's), but I need a quick start guide about collecting these into variables and storing them. Can anyone show me how to do it?
Re: Collecting data and storing it -
Excelize - 28.12.2013
Use arrays or enums to save these.
Try use this
https://sampforum.blast.hk/showthread.php?tid=276688
Re: Collecting data and storing it -
dominik523 - 28.12.2013
it would look something like this:
pawn Код:
enum pInfo
{
// here is also your password, IP and other user data
pVehMod[14]
}
new PlayerInfo[MAX_PLAYERS][pInfo];
// saving vehicle components
for(new i=0; i<14; i++)
{
PlayerInfo[playerid][pVehMod][i] = GetVehicleComponentInSlot(PlayerInfo[playerid][pVeh], i);
}
Re: Collecting data and storing it -
HeLiOn_PrImE - 28.12.2013
It didn't really help me...
This is my database table:
Код:
db_free_result(db_query(Database, "CREATE TABLE IF NOT EXISTS `SavedCars` ('Name', 'CarID', 'CarHealth', 'Color1', 'Color2', 'PaintJob', 'CarPart0', 'CarPart1', 'CarPart2', 'CarPart3', 'CarPart4', 'CarPart5', 'CarPart6', 'CarPart7', 'CarPart8', 'CarPart9', 'CarPart10', 'CarPart11', 'CarPart12', 'CarPart13')"));
This is the function used to write stuff into the database table:
Код:
format(Query, sizeof(Query), "INSERT INTO `SavedCars` ('Name', 'CarID', 'CarHealth', 'Color1', 'Color2', 'PaintJob', 'CarPart0', 'CarPart1', 'CarPart2', 'CarPart3', 'CarPart4', 'CarPart5', 'CarPart6', 'CarPart7', 'CarPart8', 'CarPart9', 'CarPart10', 'CarPart11', 'CarPart12', 'CarPart13') VALUES(etc)", ("Helion"), 432, etc);
These are the variables the table's going to use:
Код:
Name,
CarID,
CarHealth,
Color1,
Color2,
PaintJob,
Carpart0,
Carpart1,
Carpart2,
Carpart3,
Carpart4,
Carpart5,
Carpart6,
Carpart7,
Carpart8,
Carpart9,
Carpart10,
Carpart11,
Carpart12,
Carpart13.
How do I store what I need into them?
Re: Collecting data and storing it -
dominik523 - 28.12.2013
are those variables inside some enum or? To save some data for players, houses, vehicles or anything in large numbers, you use enums.
Re: Collecting data and storing it -
HeLiOn_PrImE - 28.12.2013
I didn't really understood how to use the enumerators, so I tried the "classic way".
Basically tried to register the component from each slot along with the other data (player's name, car colors and paintjob). Kept failing over and over again.
Код:
if(!strcmp(cmdtext, "/savecar", true))
{
new Query[256];
new Float:health;
new veh = GetPlayerVehicleID(playerid);
GetVehicleHealth(veh, health);
format(Query, sizeof(Query), "INSERT INTO `SavedCars` ('Name', 'CarID', 'CarHealth', 'Color1', 'Color2', 'PaintJob', 'Spoiler', 'Hood', 'Roof', 'SideSkirt', 'Lamps', 'Nitro', 'Exhaust', 'Wheels', 'Stereo', 'Hydraulics', 'FrontBumper', 'RearBumper', 'VentRight', 'VentLeft') VALUES('%s', '%d', '%f')", '(GetPlayerName(playerid))', 'veh%d', 'health', '1','1','(GetVehiclePaintjob(veh))','(GetVehicleComponentInSlot(GetPlayerVehicleID(playerid), CARMODTYPE_SPOILER))','(GetVehicleComponentInSlot(GetPlayerVehicleID(playerid), CARMODTYPE_HOOD))','(GetVehicleComponentInSlot(GetPlayerVehicleID(playerid), CARMODTYPE_ROOF))','(GetVehicleComponentInSlot(GetPlayerVehicleID(playerid), CARMODTYPE_SIDESKIRT))','(GetVehicleComponentInSlot(GetPlayerVehicleID(playerid), CARMODTYPE_LAMPS))','(GetVehicleComponentInSlot(GetPlayerVehicleID(playerid), CARMODTYPE_NITRO))','(GetVehicleComponentInSlot(GetPlayerVehicleID(playerid), CARMODTYPE_EXHAUST))','(GetVehicleComponentInSlot(GetPlayerVehicleID(playerid), CARMODTYPE_WHEELS))','(GetVehicleComponentInSlot(GetPlayerVehicleID(playerid), CARMODTYPE_STEREO))','(GetVehicleComponentInSlot(GetPlayerVehicleID(playerid), CARMODTYPE_HYDRAULICS))','(GetVehicleComponentInSlot(GetPlayerVehicleID(playerid), CARMODTYPE_FRONT_BUMPER))','(GetVehicleComponentInSlot(GetPlayerVehicleID(playerid), CARMODTYPE_REAR_BUMPER))','(GetVehicleComponentInSlot(GetPlayerVehicleID(playerid), CARMODTYPE_VENT_RIGHT))', '(GetVehicleComponentInSlot(GetPlayerVehicleID(playerid), CARMODTYPE_VENT_LEFT))');
db_query(Database, Query);
db_free_result( db_query(Database, Query) );
}
and I get this:
Код:
C:\Users\HeLiOn\Desktop\ctuningv23.pwn(148) : error 037: invalid string (possibly non-terminated string)
C:\Users\HeLiOn\Desktop\ctuningv23.pwn(148) : error 017: undefined symbol "INSERT"
C:\Users\HeLiOn\Desktop\ctuningv23.pwn(148) : error 017: undefined symbol "INTO"
C:\Users\HeLiOn\Desktop\ctuningv23.pwn(148) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
4 Errors.
I don't get it...."INSERT INTO" is a function to edit tables in sqlite. It's supposed to be in samp.inc
Re: Collecting data and storing it -
HeLiOn_PrImE - 29.12.2013
I managed to store everything using enums (thank you Excelize).
Now I have a little problem understanding how to write in the table.
I took the example below from here:
https://sampforum.blast.hk/showthread.php?tid=253977
I am having trouble understanding what's with the bolded text. The guy gave 3 examples (name, cash and ratio), but I saw nothing regarding those letters.
Код:
//create a string named Query.
new Query[129];
//Format the string for writing into the table
format(Query, sizeof(Query), "INSERT INTO `Tabel` (`Nume`, `Bani`, `Ratio`) VALUES('%s', '%d', '%f')", ("Zh3r0"), 500, Float:555 / Float:34);
//write into the database table
db_query(Database, Query);
//dump the information
db_free_result( db_query(Database, Query) );
I have the following enum:
Код:
enum PlayerCarData
{
PName,
CarID,
CarHealth,
color1,
color2,
paintjob,
spoiler,
hood,
roof,
sideSkirt,
lamps,
nitro,
exhaust,
wheels,
wtereo,
hydraulics,
frontBumper,
rearBumper,
ventRight,
ventLeft
}
new
gPlayerData[MAX_PLAYERS][PlayerCarData];
And I have this table:
Код:
db_free_result(db_query(Database, "CREATE TABLE IF NOT EXISTS `SavedCars` ('Name', 'CarID', 'CarHealth', 'Color1', 'Color2', 'PaintJob', 'Spoiler', 'Hood', 'Roof', 'SideSkirt', 'Lamps', 'Nitro', 'Exhaust', 'Wheels', 'Stereo', 'Hydraulics', 'FrontBumper', 'RearBumper', 'VentRight', 'VentLeft')"));
The values are stored. How do I write them into the table?
Re: Collecting data and storing it -
HeLiOn_PrImE - 30.12.2013
no one?
Re: Collecting data and storing it -
JJB562 - 30.12.2013
pawn Код:
format(Query, sizeof(Query), "INSERT INTO `Tabel` (`Nume`, `Bani`, `Ratio`) VALUES('%s', '%d', '%f')", ("Zh3r0"), 500, Float:555 / Float:34);
The values you have in the bold text will be inserted to their corresponding rows. So,
Zh3r0 should be inserted into the 'Nume' row,
500 would be inserted into 'Bani', and the result of
Float:555 / Float:34 would be inserted in 'Ratio'.
Re: Collecting data and storing it -
HeLiOn_PrImE - 30.12.2013
I figured that. I was asking about
Код:
VALUES('%s', '%d', '%f')
does that stay the same regardless of the number of colums and their data? In other words, would the following row be correct or not?
It's a long line, I know. I adapted the code to the enum I mentioned above. Just tell me if it't right or not..
Код:
format(Query, sizeof(Query), "INSERT INTO `SavedCars` ('Name', 'CarID', 'CarHealth', 'Color1', 'Color2', 'PaintJob', 'Spoiler', 'Hood', 'Roof', 'SideSkirt', 'Lamps', 'Nitro', 'Exhaust', 'Wheels', 'Stereo', 'Hydraulics', 'FrontBumper', 'RearBumper', 'VentRight', 'VentLeft') VALUES('%s', '%d', '%f')", gPlayerData[playerid][PName],gPlayerData[playerid][CarID],gPlayerData[playerid][CarHealth],gPlayerData[playerid][color1],gPlayerData[playerid][color2],gPlayerData[playerid][paintjob],gPlayerData[playerid][spoiler],gPlayerData[playerid][hood],gPlayerData[playerid][roof],gPlayerData[playerid][sideSkirt],gPlayerData[playerid][lamps],gPlayerData[playerid][nitro],gPlayerData[playerid][exhaust],gPlayerData[playerid][wheels],gPlayerData[playerid][wtereo],gPlayerData[playerid][hydraulics],gPlayerData[playerid][frontBumper],gPlayerData[playerid][rearBumper],gPlayerData[playerid][ventRight],gPlayerData[playerid][ventLeft]);