Creating Personal Vehicle via MySQL and ZCMD
#1

What I done until now.

PHP код:
new querystr4[340];
strcat(querystr4,"CREATE TABLE IF NOT EXISTS `vehicles` (`ID` int(6) NOT NULL,`Owner` int(11) NOT NULL,`Model` int(11) NOT NULL,`Color` int(11) NOT NULL,`Plate` int(11) NOT NULL,`SpawnX` int(11) NOT NULL,`SpawnY` int(11) NOT NULL,`SpawnZ` int(11) NOT NULL,`Daune` int(11) NOT NULL)");
mysql_tquery(handlequerystr4""""); 
but it shows me this at compilation
PHP код:

Header size
:          17020 bytes
Code size
:           801340 bytes
Data size
:         68927400 bytes
Stack
/heap size:      18000 bytesestimated maxusageunknowndue to recursion
Total requirements
:69763760 bytes 

I added at

PHP код:
enum playerinfo
{..
Cars

And at server i have those as createvehicle

PHP код:
stock DayZSA_CreateAllVehicles()
{
    
CreateVehicle(455,-51.6967,1165.8365,19.6247,357.9923,0,0,0); //
    
CreateVehicle(468,-48.1549,1166.2013,19.5904,357.9923,0,0,0); //
    
CreateVehicle(509,-44.6509,1166.1127,19.5610,357.9923,0,0,0); //
    
CreateVehicle(468,-41.2480,1165.7057,19.5344,357.9923,0,0,0); //
    
CreateVehicle(509,-37.5175,1165.5480,19.4839,357.9923,0,0,0); //
    
CreateVehicle(509,-34.1785,1165.5122,19.4425,357.9923,0,0,0); //
    
CreateVehicle(468,-36.4077,1198.4263,19.2109,20.4075,0,0,0); //
    
CreateVehicle(509,-92.2202,1213.5948,19.7422,58.3212,0,0,0); //
    
CreateVehicle(509,-135.8428,1215.4357,19.7422,87.7748,0,0,0); //
    
CreateVehicle(455,-150.3523,1181.6552,19.7422,142.6087,0,0,0); //
    
CreateVehicle(455,-197.5656,1156.7756,19.5938,189.8020,0,0,0); //
    
CreateVehicle(468,-229.1392,1134.2406,19.7422,111.6609,0,0,0); //
    
CreateVehicle(604,-246.6423,1088.4509,19.7344,184.9091,0,0,0); //
    
CreateVehicle(487,-218.9275,999.9144,19.6573,228.6558,0,0,0); // Helicopter
    
CreateVehicle(487,-296.4252,1018.8348,19.5938,121.8314,0,0,0); // Helicopter
    
CreateVehicle(487,-312.5156,1065.0649,19.5938,90.6183,0,0,0); // Helicopter
    
CreateVehicle(604,-353.0376,1160.4650,19.7422,351.2906,0,0,0); //
    
CreateVehicle(470,-299.9411,1162.6030,19.7689,285.1766,0,0,0); //
    
CreateVehicle(470,-229.6326,1214.7727,19.7422,336.2505,0,0,0); //
    
CreateVehicle(470,-216.9191,1215.3774,19.7422,268.8832,0,0,0); //
    
CreateVehicle(470,-110.4418,1131.8600,19.7422,181.4623,0,0,0); //
//mapa noua
    
CreateVehicle(500,1622.1256,-1762.0497,3.9531,262.6886,0,0,0); //Mesa aici sunt masinile
    
CreateVehicle(500,1742.7034,-1793.9995,13.5241,358.8828,0,0,0); //Mesa
    
CreateVehicle(500,1851.6797,-1883.8324,13.4368,270.8353,0,0,0); //Mesa
    
CreateVehicle(509,1923.2097,-1965.7340,13.5469,0.4015,0,0,0); //Bike
    
CreateVehicle(509,1984.2511,-2058.1633,13.3728,231.0416,0,0,0); //Bike
    
CreateVehicle(509,2016.3400,-2055.8066,13.5469,53.7167,0,0,0); //Bike
    
CreateVehicle(509,2124.2776,-2081.8381,13.5469,227.9083,0,0,0); //Bike
    
CreateVehicle(509,2220.9426,-2219.6169,13.5469,228.8483,0,0,0); //Bike
    
CreateVehicle(509,2320.3279,-2311.7148,13.5469,221.3283,0,0,0); //Bike
    
CreateVehicle(509,2407.1125,-2275.1704,13.5469,300.6024,0,0,0); //Bike
    
CreateVehicle(509,2471.8433,-2240.5352,13.5469,300.6024,0,0,0); //Bike
    
CreateVehicle(509,2517.1377,-2175.6655,13.5543,268.9554,0,0,0); //Bike
    
CreateVehicle(509,2557.6890,-2085.6328,2.7380,330.0560,0,0,0); //Bike
    
CreateVehicle(604,2590.7742,-1908.4336,3.8594,343.8428,0,0,0); //Glendale
    
CreateVehicle(468,2497.0508,-1749.8192,13.4586,12.3564,0,0,0); //Sanchez
    
CreateVehicle(604,2481.1421,-1703.8141,13.5312,12.3564,0,0,0); //Glendale
    
CreateVehicle(487,2490.3267,-1679.5411,13.3357,295.5891,0,0,0); //Maverick
    
CreateVehicle(487,2408.6533,-1656.4106,13.3828,82.8571,0,0,0); //Maverick
    
CreateVehicle(604,2364.3257,-1657.7428,13.3828,86.6171,0,0,0); //Maverick
    
CreateVehicle(554,2335.9487,-1508.9320,24.0000,357.6296,0,0,0); //Yosemite
    
CreateVehicle(554,2391.5723,-1437.5062,23.8354,349.1695,0,0,0); //Yosemite
    
CreateVehicle(554,2365.8848,-1362.3594,24.0103,44.9434,0,0,0); //Yosemite
    
CreateVehicle(431,2308.0725,-1273.4342,23.8398,4.2096,0,0,0); //Bus
    
CreateVehicle(431,2272.0269,-1186.7494,25.1085,52.7767,0,0,0); //Bus
    
CreateVehicle(431,2226.3057,-1150.0972,25.8287,119.5173,0,0,0); //Bus
    
CreateVehicle(531,2144.0215,-995.1120,61.7176,42.1232,0,0,0); //Tractor
    
CreateVehicle(468,818.0776,-1643.5748,13.3828,8.7501,0,0,0); //SANCHEZ
    
CreateVehicle(455,1268.1787,-1525.3687,13.5606,260.9624,0,0,0);//FIRETRUCK
    
CreateVehicle(433,1555.7581,-1626.7670,13.3828,81.1073,0,0,0);//BARRACKS
    
CreateVehicle(542,1987.5231,-1382.4735,23.6055,240.1862,0,0,0);//CLOVER
    
CreateVehicle(470,2262.4360,-1056.5121,49.6946,9.6666,0,0,0);//PATRIOT
    
CreateVehicle(422,2641.6079,-1446.6810,30.2758,271.9059,0,0,0);//BOBCAT
    
CreateVehicle(531,2795.2151,-1544.0227,10.9219,201.0919,0,0,0);//TRACTOR
    
CreateVehicle(418,2856.8699,-1646.5342,10.8750,200.1518,0,0,0);//Moonbeam
    
CreateVehicle(417,1716.9417,-2648.7917,13.5469,193.6419,0,0,0); //Leviathan
    
CreateVehicle(511,1444.7480,-2593.4758,13.5469,271.6626,0,0,0); //Beagle
    
CreateVehicle(487,1492.4017,-2416.5955,13.5547,149.9198,0,0,0); //Maverick
    
CreateVehicle(470,2284.8784,-2351.3674,13.5469,50.4473,0,0,0); //Patriot
    
CreateVehicle(484,3043.9883,-1631.1265,-0.6923,67.6806,0,0,0); //Predator
    
CreateVehicle(473,838.0151,-2155.6077,-0.5905,120.6344,0,0,0); //Squallo
    
CreateVehicle(453,544.7344,-2132.8005,-0.4374,319.2429,0,0,0); //Tropic
    
CreateVehicle(418,1945.7063,-1046.3296,23.9887,107.9238,0,0,0); //Moonbeam
    
CreateVehicle(455,1799.9100,-1062.4503,23.9609,93.5104,0,0,0); //Flatbed
    
CreateVehicle(433,1739.0516,-1083.1974,23.9609,138.5104,0,0,0); //Barracks
    
CreateVehicle(542,1577.0702,-1158.3517,23.9140,124.2173,0,0,0); //Clover
    
CreateVehicle(542,1453.1948,-1152.7224,23.9312,84.7369,0,0,0); //Clover
    
CreateVehicle(542,1401.6613,-1244.5524,13.3828,85.9903,0,0,0); //Clover
    
CreateVehicle(453,1354.6588,-1307.5546,13.3262,177.1711,0,0,0); //Reefer
    
CreateVehicle(453,718.4084,-1850.4904,0.0303,178.4715,0,0,0); //Reefer
    
CreateVehicle(473,702.9539,-2049.2385,-0.7037,158.5248,0,0,0); //Dinghy
    
CreateVehicle(473,646.3474,-2131.3247,-1.5953,158.5248,0,0,0); //Dinghy
    
CreateVehicle(473,569.4369,-2167.9968,-0.6127,32.8769,0,0,0); //Dinghy
    
CreateVehicle(484,356.9875,-2013.1938,-0.6513,16.9202,0,0,0); //Marquis
    
return 1;

This will be deleted (createvehicles) , but I don't know what to do next from now.

I want to create /v buy from dealership (isplayeronrange)



And, player's car will be exemple, Sultan (560) but on server it will have unique id like (64). VehicleID. How can I store that uniqueID on mysql instead of Sultan?



And exemple of buy car command

PHP код:
CMD:buysultan(playerid,params[])
{
    if(
IsPlayerInRangeOfPoint(playerid,5.02830.8057,2453.0632,1786.4811))
    {
    
pInfo[playerid][Cars] +=1;
    
Cars[playerid][Owner] = PlayerName
    Cars
[playerid][Model] = 560; (sultan)
    
Cars[playerid][ColorA] = 0;
    
Cars[playerid][ColorB] = 0;
    
Cars[playerid][Plate] = LS-424;
    
Cars[playerid][SpawnX] = 4.2424
    Cars
[playerid][SpawnY] = 4.2424
    Cars
[playerid][SpawnZ] = 4.2424
    
return 1;


but I don't know how to add unique ID, because if Player 2 buys Sultan Too, his Model will be 560 too, and when I create /lock command I want to assure that no player can lock another player's car.
Reply
#2

you have to use vehicle's ID as a player's current vehicle.
for example, add enum CarID
when you create a vehicle, set the player's pInfo[playerid][CarID] = vehid;
than you can use this pInfo[playerid][CarID] as an ID of the vehicle.
Reply
#3

Can you give me an exemple how I should do it?
Reply
#4

Lets use NRG for example.
Maybe like this
PHP код:
pInfo[playerid][CarID] = 522
Reply
#5

Just add an 'ID' column with the auto-increment enabled to your table and set that as primary key.
Each time someone buys a vehicle, you just insert a new row into your database and MySQL will automatically increase the ID by 1, giving every vehicle a truely unique ID.
After inserting the new vehicle, use "cache_insert_id" to get the newly created ID for that vehicle and store it in your enum.

Note that this ID isn't the same as the ingame vehicleid used by all vehicle-functions.
It's only a value to reference the vehicle in the database, you can't use it with SAMP's vehicle-functions.
Vehicleid's ingame range from 1 to 1999, but the ID in your database goes from 1 to 2 billion.
Vehicleid's ingame will be re-used when a vehicle is removed from the world and re-created afterwards, the ID in the database will never be used again.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)