Advertisement
Guest User

Vehicle Ownership System (MySQL)

a guest
Mar 16th, 2015
4,835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 40.56 KB | None | 0 0
  1. /********************************
  2. ++    Created by Bondowocopz   ++
  3. ++ Credits to all samp players ++
  4. ++     Vehicle System for      ++
  5. ++         MySQL R39-2         ++
  6. ********************************/
  7. #include <a_samp>
  8. #include <a_mysql>
  9. #include <streamer>
  10. #include <vsystem/formatnumber>
  11. #include <vsystem/zcmd>
  12.  
  13. #define HOST        "localhost"
  14. #define USER        "bondowocopz"
  15. #define PASSWORD    "bondowocopz"
  16. #define DBNAME      "filterscript"
  17.  
  18. #define MAX_VEH                 500
  19. #define MAX_PLAYER_VEHICLES     5
  20.  
  21. #define DEFAULT_NUMBER_PLATE    "CCNR"
  22. #define SPORTVEHICLES           0
  23. #define SALOONS                 1
  24. #define BIKES                   2
  25. #define UNIQUE                  3
  26. #define INDUSTRIAL              4
  27. #define LOWRIDER                5
  28. #define OFFROAD                 6
  29. #define AIR                     7
  30.  
  31. #define DIALOG_BUYCAR           1
  32. #define DIALOG_DEALERSHIP       2
  33. #define DIALOG_VCP              3
  34. #define DIALOG_CHANGEPLATE      4
  35. #define DIALOG_CHANGECOLOR      5
  36. #define DIALOG_CHANGECOLOR2     6
  37. #define DIALOG_MYVEHICLES       7
  38. #define DIALOG_MYVEHICLES2      8
  39. #define DIALOG_SALESERVER       9
  40. #define DIALOG_VSELL            10
  41. #define DIALOG_VSELL2           11
  42. #define DIALOG_CONFVS           12
  43. #define DIALOG_CONFIRMVSELL     13
  44. #define DIALOG_UNUSED           14
  45.  
  46. #define CHAT_YELLOW             "{FFFF00}"
  47. #define CHAT_WHITE              "{FFFFFF}"
  48. #define CHAT_SERVER             "{808080}"
  49. #define CHAT_RED                "{FF0000}"
  50. #define COLOR_WHITE             0xFFFFFFFF
  51.  
  52. new koneksi = -1, buycarCP, Text:buycarTD[4],
  53.     Float:dealX = -1663.640014, Float:dealY = 1208.253662, Float:dealZ = 7.254645,
  54.     GPSObject[MAX_PLAYERS];
  55.    
  56. new Float:airX = -1665.9714,
  57.     Float:airY = 1210.7313,
  58.     Float:airZ = 32.9239,
  59.     Float:airA = 280.6097; // Change this for Helicopter & Plane Spawn
  60.  
  61. new Float:normalX = -1643.3745,
  62.     Float:normalY = 1213.0620,
  63.     Float:normalZ = 6.8095,
  64.     Float:normalA = 225.2126; // Change this for normal car spawn
  65.    
  66. enum __vehicleInfo
  67. {
  68.     bool:vehStatus,
  69.     vehID,
  70.     vehModel,
  71.     Float:vehPos[4],
  72.     vehColor[2],
  73.     vehInt,
  74.     vehVW,
  75.     vehOwner[MAX_PLAYER_NAME],
  76.     bool:vehLock,
  77.     bool:vehAlarm,
  78.     vehicleData,
  79.     vehPlate[16],
  80.     vehMods[14],
  81.     vehPaint
  82. }
  83. new Vehicles[MAX_VEH][__vehicleInfo];
  84.  
  85. enum __dealerInfo
  86. {
  87.     dialogID,
  88.     dealerModel,
  89.     dealerPrice,
  90.     dealerType
  91. }
  92.  
  93. new Dealership[][__dealerInfo] =
  94. {
  95.     {0, 451, 3000000, SPORTVEHICLES},
  96.     {1, 411, 3000000, SPORTVEHICLES},
  97.     {2, 415, 3000000, SPORTVEHICLES},
  98.     {3, 402, 3000000, SPORTVEHICLES},
  99.     {4, 541, 3000000, SPORTVEHICLES},
  100.     {5, 477, 3000000, SPORTVEHICLES},
  101.     {6, 603, 3000000, SPORTVEHICLES},
  102.     {7, 565, 4000000, SPORTVEHICLES},
  103.     {8, 429, 3000000, SPORTVEHICLES},
  104.     {9, 506, 3000000, SPORTVEHICLES},
  105.     {10, 589, 3000000, SPORTVEHICLES},
  106.     {11, 559, 4000000, SPORTVEHICLES},
  107.  
  108.     {0, 560, 3000000, SALOONS},
  109.     {1, 562, 3000000, SALOONS},
  110.     {2, 426, 1500000, SALOONS},
  111.     {3, 516, 1500000, SALOONS},
  112.     {4, 518, 1500000, SALOONS},
  113.     {5, 526, 1500000, SALOONS},
  114.     {6, 550, 1500000, SALOONS},
  115.     {7, 540, 1500000, SALOONS},
  116.     {8, 542, 750000, SALOONS},
  117.     {9, 547, 1500000, SALOONS},
  118.     {10, 434, 750000, SALOONS},
  119.    
  120.     {0, 522, 5000000, BIKES},
  121.     {1, 463, 2000000, BIKES},
  122.     {2, 468, 1000000, BIKES},
  123.     {3, 471, 1000000, BIKES},
  124.     {4, 462, 500000, BIKES},
  125.     {5, 481, 100000, BIKES},
  126.  
  127.     {0, 556, 7000000, UNIQUE},
  128.     {1, 557, 7000000, UNIQUE},
  129.     {2, 539, 5000000, UNIQUE},
  130.     {3, 588, 1000000, UNIQUE},
  131.     {4, 571, 5000000, UNIQUE},
  132.     {5, 572, 500000, UNIQUE},
  133.     {6, 508, 1000000, UNIQUE},
  134.     {7, 457, 500000, UNIQUE},
  135.    
  136.     {0, 455, 250000, INDUSTRIAL},
  137.     {1, 456, 250000, INDUSTRIAL},
  138.     {2, 499, 250000, INDUSTRIAL},
  139.     {3, 482, 500000, INDUSTRIAL},
  140.     {4, 543, 500000, INDUSTRIAL},
  141.     {5, 478, 200000, INDUSTRIAL},
  142.    
  143.     {0, 412, 1000000, LOWRIDER},
  144.     {1, 534, 1000000, LOWRIDER},
  145.     {2, 535, 1000000, LOWRIDER},
  146.     {3, 536, 1000000, LOWRIDER},
  147.     {4, 566, 1000000, LOWRIDER},
  148.     {5, 567, 1000000, LOWRIDER},
  149.     {6, 576, 1000000, LOWRIDER},
  150.     {7, 575, 1000000, LOWRIDER},
  151.  
  152.     {0, 489, 750000, OFFROAD},
  153.     {1, 495, 750000, OFFROAD},
  154.     {2, 579, 750000, OFFROAD},
  155.     {3, 400, 750000, OFFROAD},
  156.    
  157.     {0, 469, 15000000, AIR},
  158.     {1, 487, 15000000, AIR},
  159.     {2, 513, 15000000, AIR}
  160. };
  161.  
  162. enum _playerStats
  163. {
  164.     carVCP,
  165.     dealershipChoice,
  166.     timerSpeed,
  167.     vsellTo,
  168.     vsellPrice,
  169.     vsellFrom,
  170.     vsellCar
  171. }
  172. new Player[MAX_PLAYERS][_playerStats];
  173.  
  174. new namaCar[213][] =
  175. {
  176.     {"Landstalker"}, {"Bravura"}, {"Buffalo"}, {"Linerunner"}, {"Perrenial"}, {"Sentinel"}, {"Dumper"}, {"Firetruck"}, {"Trashmaster"}, {"Stretch"},
  177.     {"Manana"}, {"Infernus"}, {"Voodoo"}, {"Pony"}, {"Mule"}, {"Cheetah"}, {"Ambulance"}, {"Leviathan"}, {"Moonbeam"}, {"Esperanto"},
  178.     {"Taxi"}, {"Washington"}, {"Bobcat"}, {"Mr Whoopee"}, {"BF Injection"}, {"Hunter"}, {"Premier"}, {"Enforcer"}, {"Securicar"}, {"Banshee"},
  179.     {"Predator"}, {"Bus"}, {"Rhino"}, {"Barracks"}, {"Hotknife"}, {"Trailer 1"}, {"Previon"}, {"Coach"}, {"Cabbie"}, {"Stallion"},
  180.     {"Rumpo"}, {"RC Bandit"}, {"Romero"}, {"Packer"}, {"Monster"}, {"Admiral"}, {"Squalo"}, {"Seasparrow"}, {"Pizzaboy"}, {"Tram"},
  181.     {"Trailer 2"}, {"Turismo"}, {"Speeder"}, {"Reefer"}, {"Tropic"}, {"Flatbed"}, {"Yankee"}, {"Caddy"}, {"Solair"}, {"Berkley's RC Van"},
  182.     {"Skimmer"}, {"PCJ-600"}, {"Faggio"}, {"Freeway"}, {"RC Baron"}, {"RC Raider"}, {"Glendale"}, {"Oceanic"}, {"Sanchez"}, {"Standard Sparrow"},
  183.     {"Patriot"}, {"Quad"}, {"Coastguard"}, {"Dinghy"}, {"Hermes"}, {"Sabre"}, {"Rustler"}, {"ZR-350"}, {"Walton"}, {"Regina"},
  184.     {"Comet"}, {"BMX"}, {"Burrito"}, {"Camper"}, {"Marquis"}, {"Baggage"}, {"Dozer"}, {"Maverick"}, {"News Chopper"}, {"Rancher"},
  185.     {"FBI Rancher"}, {"Virgo"}, {"Greenwood"}, {"Jetmax"}, {"Hotring"}, {"Sandking"}, {"Blista Compact"}, {"Police Maverick"}, {"Boxville"}, {"Benson"},
  186.     {"Mesa"}, {"RC Goblin"}, {"Hotring Racer A"}, {"Hotring Racer B"}, {"Bloodring Banger"}, {"Rancher"}, {"Super GT"}, {"Elegant"}, {"Journey"}, {"Bike"},
  187.     {"Mountain Bike"}, {"Beagle"}, {"Cropdust"}, {"Stunt Plane"}, {"Tanker"}, {"Roadtrain"}, {"Nebula"}, {"Majestic"}, {"Buccaneer"}, {"Shamal"},
  188.     {"Hydra"}, {"FCR-900"}, {"NRG-500"}, {"HPV1000"}, {"Cement Truck"}, {"Tow Truck"}, {"Fortune"}, {"Cadrona"}, {"FBI Truck"}, {"Willard"},
  189.     {"Forklift"}, {"Tractor"}, {"Combine"}, {"Feltzer"}, {"Remington"}, {"Slamvan"}, {"Blade"}, {"Freight"}, {"Streak"}, {"Vortex"},
  190.     {"Vincent"}, {"Bullet"}, {"Clover"}, {"Sadler"}, {"Firetruck LA"}, {"Hustler"}, {"Intruder"}, {"Primo"}, {"Cargobob"}, {"Tampa"},
  191.     {"Sunrise"}, {"Merit"}, {"Utility"}, {"Nevada"}, {"Yosemite"}, {"Windsor"}, {"Monster A"}, {"Monster B"}, {"Uranus"}, {"Jester"},
  192.     {"Sultan"}, {"Stratum"}, {"Elegy"}, {"Raindance"}, {"RC Tiger"}, {"Flash"}, {"Tahoma"}, {"Savanna"}, {"Bandito"}, {"Freight Flat"},
  193.     {"Streak Carriage"}, {"Kart"}, {"Mower"}, {"Duneride"}, {"Sweeper"}, {"Broadway"}, {"Tornado"}, {"AT-400"}, {"DFT-30"}, {"Huntley"},
  194.     {"Stafford"}, {"BF-400"}, {"Newsvan"}, {"Tug"}, {"Trailer 3"}, {"Emperor"}, {"Wayfarer"}, {"Euros"}, {"Hotdog"}, {"Club"},
  195.     {"Freight Carriage"}, {"Trailer 3"}, {"Andromada"}, {"Dodo"}, {"RC Cam"}, {"Launch"}, {"Police Car (LSPD)"}, {"Police Car (SFPD)"}, {"Police Car (LVPD)"}, {"Police Ranger"},
  196.     {"Picador"}, {"S.W.A.T. Van"}, {"Alpha"}, {"Phoenix"}, {"Glendale"}, {"Sadler"}, {"Luggage Trailer A"}, {"Luggage Trailer B"}, {"Stair Trailer"}, {"Boxville"},
  197.     {"Farm Plow"}, {"Utility Trailer"}, {"Jetpack"}
  198. };
  199.  
  200. stock GetName(playerid)
  201. {
  202.     new pName[24];
  203.     GetPlayerName(playerid, pName, 24);
  204.     return pName;
  205. }
  206.  
  207. stock loadVehicles(playerid)
  208. {
  209.     new query[128];
  210.     Player[playerid][carVCP]            = -1;
  211.     Player[playerid][dealershipChoice]  = -1;
  212.     Player[playerid][timerSpeed]        = -1;
  213.     Player[playerid][vsellTo]           = INVALID_PLAYER_ID;
  214.     Player[playerid][vsellPrice]        = -1;
  215.     Player[playerid][vsellFrom]         = INVALID_PLAYER_ID;
  216.     Player[playerid][vsellCar]          = -1;
  217.     mysql_format(koneksi, query, sizeof(query), "SELECT * FROM `vehicle` where `owner` = '%s'", GetName(playerid));
  218.     mysql_tquery(koneksi, query, "OnPlayerLoadVehicles", "d", playerid);
  219.     return 1;
  220. }
  221.  
  222. stock createVehicle(vehicleid, bool:removeold = false)
  223. {
  224.     if(removeold)
  225.     {
  226.         DestroyVehicle(Vehicles[vehicleid][vehicleData]);
  227.     }
  228.     Vehicles[vehicleid][vehicleData]    = CreateVehicle(Vehicles[vehicleid][vehModel], Vehicles[vehicleid][vehPos][0], Vehicles[vehicleid][vehPos][1], Vehicles[vehicleid][vehPos][2], Vehicles[vehicleid][vehPos][3], Vehicles[vehicleid][vehColor][0], Vehicles[vehicleid][vehColor][1], 360000);
  229.     SetVehicleNumberPlate(Vehicles[vehicleid][vehicleData], Vehicles[vehicleid][vehPlate]);
  230.     LinkVehicleToInterior(Vehicles[vehicleid][vehicleData], Vehicles[vehicleid][vehInt]);
  231.     SetVehicleVirtualWorld(Vehicles[vehicleid][vehicleData], Vehicles[vehicleid][vehVW]);
  232.     for(new i = 0; i < 14; i++)
  233.     {
  234.         AddVehicleComponent(Vehicles[vehicleid][vehicleData], Vehicles[vehicleid][vehMods][i]);
  235.     }
  236.     ChangeVehicleColor(Vehicles[vehicleid][vehicleData], Vehicles[vehicleid][vehColor][0], Vehicles[vehicleid][vehColor][1]);
  237.     ChangeVehiclePaintjob(Vehicles[vehicleid][vehicleData], Vehicles[vehicleid][vehPaint]);
  238.     return 1;
  239. }
  240.  
  241. stock showDealership(playerid, category)
  242. {
  243.     new msg2[1000];
  244.     Player[playerid][dealershipChoice] = category;
  245.     for(new i = 0; i < sizeof(Dealership); i++)
  246.     {
  247.         if(Dealership[i][dealerType] == category)
  248.         {
  249.             format(msg2, sizeof(msg2), "%s\n%s "CHAT_YELLOW"$%s {FFFFFF}", msg2, namaCar[Dealership[i][dealerModel] - 400], FormatNumber(Dealership[i][dealerPrice]));
  250.         }
  251.     }
  252.     ShowPlayerDialog(playerid, DIALOG_DEALERSHIP, DIALOG_STYLE_LIST, "Bondowocopz Dealership - Choose Car", msg2, "Buy", "Cancel");
  253.     return 1;
  254. }
  255.  
  256. stock __createVehicle(model, playerid, Float:x, Float:y, Float:z, Float:a)
  257. {
  258.     new query[512];
  259.     mysql_format(koneksi, query, sizeof(query), "INSERT INTO `vehicle` (`owner`, `model`, `posX`, `posY`, `posZ`, `posA`) VALUES ('%s', '%d', '%f', '%f', '%f', '%f')", GetName(playerid), model, x, y, z, a);
  260.     mysql_tquery(koneksi, query, "OnSavedVehicleCreated", "ddffff", model, playerid, x, y, z, a);
  261.     return 1;
  262. }
  263.  
  264. stock giveMoney(playerid, amount)
  265. {
  266.     return GivePlayerMoney(playerid, GetPlayerMoney(playerid) - amount);
  267. }
  268.  
  269. stock takeMoney(playerid, amount)
  270. {
  271.     return GivePlayerMoney(playerid, GetPlayerMoney(playerid) + amount);
  272. }
  273.  
  274. stock Server(playerid, message[])
  275. {
  276.     new pesan[200];
  277.     format(pesan, sizeof(pesan), ""CHAT_SERVER"[SERVER] "CHAT_WHITE"%s", message);
  278.     return SendClientMessage(playerid, COLOR_WHITE, pesan);
  279. }
  280.  
  281. stock countplayerVeh(playerid)
  282. {
  283.     new query[256], count;
  284.     mysql_format(koneksi, query, sizeof(query), "SELECT count(*) as `total` from `vehicle` where `owner` = '%s'", GetName(playerid));
  285.     mysql_query(koneksi, query, true);
  286.     count = cache_get_field_content_int(0, "total");
  287.     return count;
  288. }
  289.  
  290. stock initTD()
  291. {
  292.     buycarTD[0] = TextDrawCreate(434.000000, 166.699996, "usebox");
  293.     TextDrawLetterSize(buycarTD[0], 0.000000, 6.546296);
  294.     TextDrawTextSize(buycarTD[0], 220.000000, 0.000000);
  295.     TextDrawAlignment(buycarTD[0], 1);
  296.     TextDrawColor(buycarTD[0], 0);
  297.     TextDrawUseBox(buycarTD[0], true);
  298.     TextDrawBoxColor(buycarTD[0], -1378294017);
  299.     TextDrawSetShadow(buycarTD[0], 0);
  300.     TextDrawSetOutline(buycarTD[0], 0);
  301.     TextDrawFont(buycarTD[0], 0);
  302.  
  303.     buycarTD[1] = TextDrawCreate(432.000000, 168.633331, "usebox");
  304.     TextDrawLetterSize(buycarTD[1], 0.000000, 6.046302);
  305.     TextDrawTextSize(buycarTD[1], 222.000000, 0.000000);
  306.     TextDrawAlignment(buycarTD[1], 1);
  307.     TextDrawColor(buycarTD[1], 0);
  308.     TextDrawUseBox(buycarTD[1], true);
  309.     TextDrawBoxColor(buycarTD[1], 255);
  310.     TextDrawSetShadow(buycarTD[1], 0);
  311.     TextDrawSetOutline(buycarTD[1], 0);
  312.     TextDrawFont(buycarTD[1], 0);
  313.  
  314.     buycarTD[2] = TextDrawCreate(279.000000, 168.933273, "Please Wait");
  315.     TextDrawLetterSize(buycarTD[2], 0.569000, 2.225334);
  316.     TextDrawAlignment(buycarTD[2], 1);
  317.     TextDrawColor(buycarTD[2], -1);
  318.     TextDrawSetShadow(buycarTD[2], 0);
  319.     TextDrawSetOutline(buycarTD[2], 1);
  320.     TextDrawBackgroundColor(buycarTD[2], 51);
  321.     TextDrawFont(buycarTD[2], 0);
  322.     TextDrawSetProportional(buycarTD[2], 1);
  323.  
  324.     buycarTD[3] = TextDrawCreate(236.000000, 202.533325, "Your vehicle is being created");
  325.     TextDrawLetterSize(buycarTD[3], 0.256999, 1.198666);
  326.     TextDrawAlignment(buycarTD[3], 1);
  327.     TextDrawColor(buycarTD[3], -1);
  328.     TextDrawSetShadow(buycarTD[3], 0);
  329.     TextDrawSetOutline(buycarTD[3], 1);
  330.     TextDrawBackgroundColor(buycarTD[3], 51);
  331.     TextDrawFont(buycarTD[3], 2);
  332.     TextDrawSetProportional(buycarTD[3], 1);
  333.     return 1;
  334. }
  335.  
  336. stock parkVehicles(vehicleid, int, vw)
  337. {
  338.     GetVehiclePos(Vehicles[vehicleid][vehicleData], Vehicles[vehicleid][vehPos][0], Vehicles[vehicleid][vehPos][1], Vehicles[vehicleid][vehPos][2]);
  339.     GetVehicleZAngle(Vehicles[vehicleid][vehicleData], Vehicles[vehicleid][vehPos][3]);
  340.     Vehicles[vehicleid][vehInt] = int;
  341.     Vehicles[vehicleid][vehVW]  = vw;
  342.     return 1;
  343. }
  344.  
  345. stock destroyCar(playerid)
  346. {
  347.     for(new i = 0; i < MAX_VEH; i++)
  348.     {
  349.         if(!Vehicles[i][vehStatus]) continue;
  350.        
  351.         if(!strcmp(Vehicles[i][vehOwner], GetName(playerid)))
  352.         {
  353.             saveVehicles(i);
  354.             removeVehicle(i);
  355.         }
  356.     }
  357.     return 1;
  358. }
  359.  
  360. stock saveVehicles(vehicleid)
  361. {
  362.     new query[1000];
  363.     format(query, sizeof(query), "UPDATE `vehicle` set");
  364.     format(query, sizeof(query), "%s `owner` = '%s',", query, Vehicles[vehicleid][vehOwner]);
  365.     format(query, sizeof(query), "%s `posX` = '%f',", query, Vehicles[vehicleid][vehPos][0]);
  366.     format(query, sizeof(query), "%s `posY` = '%f',", query, Vehicles[vehicleid][vehPos][1]);
  367.     format(query, sizeof(query), "%s `posZ` = '%f',", query, Vehicles[vehicleid][vehPos][2]);
  368.     format(query, sizeof(query), "%s `posA` = '%f',", query, Vehicles[vehicleid][vehPos][3]);
  369.     if(Vehicles[vehicleid][vehLock])
  370.         format(query, sizeof(query), "%s `locked` = '1',", query);
  371.     else
  372.         format(query, sizeof(query), "%s `locked` = '0',", query);
  373.        
  374.     if(Vehicles[vehicleid][vehAlarm])
  375.         format(query, sizeof(query), "%s `alarm` = '1',", query);
  376.     else
  377.         format(query, sizeof(query), "%s `alarm` = '0',", query);
  378.     format(query, sizeof(query), "%s `color1` = '%d',", query, Vehicles[vehicleid][vehColor][0]);
  379.     format(query, sizeof(query), "%s `color2` = '%d',", query, Vehicles[vehicleid][vehColor][1]);
  380.     format(query, sizeof(query), "%s `plate` = '%s',", query, safeString(Vehicles[vehicleid][vehPlate]));
  381.     format(query, sizeof(query), "%s `int` = '%d',", query, Vehicles[vehicleid][vehInt]);
  382.     format(query, sizeof(query), "%s `vw` = '%d',", query, Vehicles[vehicleid][vehVW]);
  383.     format(query, sizeof(query), "%s `mod1` = '%d',", query, Vehicles[vehicleid][vehMods][0]);
  384.     format(query, sizeof(query), "%s `mod2` = '%d',", query, Vehicles[vehicleid][vehMods][1]);
  385.     format(query, sizeof(query), "%s `mod3` = '%d',", query, Vehicles[vehicleid][vehMods][2]);
  386.     format(query, sizeof(query), "%s `mod4` = '%d',", query, Vehicles[vehicleid][vehMods][3]);
  387.     format(query, sizeof(query), "%s `mod5` = '%d',", query, Vehicles[vehicleid][vehMods][4]);
  388.     format(query, sizeof(query), "%s `mod6` = '%d',", query, Vehicles[vehicleid][vehMods][5]);
  389.     format(query, sizeof(query), "%s `mod7` = '%d',", query, Vehicles[vehicleid][vehMods][6]);
  390.     format(query, sizeof(query), "%s `mod8` = '%d',", query, Vehicles[vehicleid][vehMods][7]);
  391.     format(query, sizeof(query), "%s `mod9` = '%d',", query, Vehicles[vehicleid][vehMods][8]);
  392.     format(query, sizeof(query), "%s `mod10` = '%d',", query, Vehicles[vehicleid][vehMods][9]);
  393.     format(query, sizeof(query), "%s `mod11` = '%d',", query, Vehicles[vehicleid][vehMods][10]);
  394.     format(query, sizeof(query), "%s `mod12` = '%d',", query, Vehicles[vehicleid][vehMods][11]);
  395.     format(query, sizeof(query), "%s `mod13` = '%d',", query, Vehicles[vehicleid][vehMods][12]);
  396.     format(query, sizeof(query), "%s `mod14` = '%d',", query, Vehicles[vehicleid][vehMods][13]);
  397.     format(query, sizeof(query), "%s `paintjob` = '%d'", query, Vehicles[vehicleid][vehPaint]);
  398.     format(query, sizeof(query), "%s WHERE `id` = '%d'", query, Vehicles[vehicleid][vehID]);
  399.     mysql_format(koneksi, query, sizeof(query), "%s", query);
  400.     mysql_query(koneksi, query, false);
  401.     return 1;
  402. }
  403.  
  404. stock removeVehicle(i)
  405. {
  406.     DestroyVehicle(Vehicles[i][vehicleData]);
  407.     Vehicles[i][vehStatus]      = false;
  408.     Vehicles[i][vehID]          = INVALID_VEHICLE_ID;
  409.     Vehicles[i][vehModel]       = -1;
  410.     Vehicles[i][vehPos][0]      = 0.0;
  411.     Vehicles[i][vehPos][1]      = 0.0;
  412.     Vehicles[i][vehPos][2]      = 0.0;
  413.     Vehicles[i][vehPos][3]      = 0.0;
  414.     Vehicles[i][vehColor][0]    = -1;
  415.     Vehicles[i][vehColor][1]    = -1;
  416.     Vehicles[i][vehInt]         = -1;
  417.     Vehicles[i][vehVW]          = -1;
  418.     format(Vehicles[i][vehOwner], MAX_PLAYER_NAME, " ");
  419.     Vehicles[i][vehLock]        = false;
  420.     Vehicles[i][vehAlarm]       = false;
  421.     for(new w = 0; w < 14; w++)
  422.     {
  423.         Vehicles[i][vehMods][w] = 0;
  424.     }
  425.     Vehicles[i][vehPaint] = 255;
  426.     return 1;
  427. }
  428.  
  429. stock safeString(exploit[])
  430. {
  431.     new safe[128];
  432.     mysql_real_escape_string(exploit, safe, koneksi, 128);
  433.     return safe;
  434. }
  435.  
  436. stock isConnected(otherID)
  437. {
  438.     if(IsPlayerConnected(otherID))
  439.         return true;
  440.     else
  441.         return false;
  442. }
  443.  
  444. stock bool:isMe(playerid, otherid)
  445. {
  446.     if(playerid == otherid)
  447.         return true;
  448.    
  449.     return false;
  450. }
  451.  
  452. stock __deleteVehicle(i)
  453. {
  454.     new query[256];
  455.     mysql_format(koneksi, query, sizeof(query), "DELETE FROM `vehicle` where `id` = '%d'", Vehicles[i][vehID]);
  456.     mysql_query(koneksi, query, false);
  457.     removeVehicle(i);
  458.     return 1;
  459. }
  460.  
  461. stock Float:PointAngle(playerid, Float:xa, Float:ya, Float:xb, Float:yb)
  462. {
  463.     new Float:carangle;
  464.     new Float:xc, Float:yc;
  465.     new Float:angle;
  466.     xc = floatabs(floatsub(xa,xb));
  467.     yc = floatabs(floatsub(ya,yb));
  468.     if (yc == 0.0 || xc == 0.0)
  469.     {
  470.         if(yc == 0 && xc > 0) angle = 0.0;
  471.         else if(yc == 0 && xc < 0) angle = 180.0;
  472.         else if(yc > 0 && xc == 0) angle = 90.0;
  473.         else if(yc < 0 && xc == 0) angle = 270.0;
  474.         else if(yc == 0 && xc == 0) angle = 0.0;
  475.     }
  476.     else
  477.     {
  478.         angle = atan(xc/yc);
  479.         if(xb > xa && yb <= ya) angle += 90.0;
  480.         else if(xb <= xa && yb < ya) angle = floatsub(90.0, angle);
  481.         else if(xb < xa && yb >= ya) angle -= 90.0;
  482.         else if(xb >= xa && yb > ya) angle = floatsub(270.0, angle);
  483.     }
  484.     GetVehicleZAngle(GetPlayerVehicleID(playerid), carangle);
  485.     return floatadd(angle, -carangle);
  486. }
  487.  
  488. stock disableGPS(playerid)
  489. {
  490.     if(GetPVarInt(playerid,"YEAH") == 1)
  491.     {
  492.         DestroyObject(GPSObject[playerid]);
  493.         SetPVarInt(playerid, "YEAH",0);
  494.         DeletePVar(playerid, "Spongebob");
  495.         DeletePVar(playerid, "Mario");
  496.         DeletePVar(playerid, "SpiderPig");
  497.         DeletePVar(playerid, "FAIL");
  498.     }
  499.     return 1;
  500. }
  501.  
  502. stock checkVehicle(playerid, vehicleid)
  503. {
  504.     if(strcmp(Vehicles[vehicleid][vehOwner], GetName(playerid)))
  505.     {
  506.         if(Vehicles[vehicleid][vehLock])
  507.         {
  508.             Server(playerid, "This vehicle is locked.");
  509.             RemovePlayerFromVehicle(playerid);
  510.         }
  511.         else
  512.         {
  513.             new msg[128];
  514.             format(msg, sizeof(msg), "This vehicle belongs to "CHAT_YELLOW"%s"CHAT_WHITE".", Vehicles[vehicleid][vehOwner]);
  515.             Server(playerid, msg);
  516.         }
  517.        
  518.         if(Vehicles[vehicleid][vehAlarm])
  519.         {
  520.             ToggleAlarm(Vehicles[vehicleid][vehicleData], VEHICLE_PARAMS_ON);
  521.             SetTimerEx("offAlarm", 5000, false, "d", Vehicles[vehicleid][vehicleData]);
  522.         }
  523.     }
  524.     else
  525.     {
  526.         Server(playerid, "Welcome to your vehicle, type /vcp to view vehicle control panel.");
  527.     }
  528.     return 1;
  529. }
  530.  
  531. stock ToggleAlarm(vehicleid, toggle)
  532. {
  533.     new engine, lights, alarm, doors, bonnet, boot, objective;
  534.     GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
  535.     SetVehicleParamsEx(vehicleid, engine, lights, toggle, doors, bonnet, boot, objective);
  536. }
  537.  
  538. forward OnSavedVehicleCreated(model, playerid, Float:x, Float:y, Float:z, Float:a);
  539. forward putinVehicle(playerid, vehicleid);
  540. forward OnPlayerLoadVehicles(playerid);
  541. forward offAlarm(vehicleid);
  542.  
  543. public OnSavedVehicleCreated(model, playerid, Float:x, Float:y, Float:z, Float:a)
  544. {
  545.     for(new i = 0; i < MAX_VEH; i++)
  546.     {
  547.         if(Vehicles[i][vehStatus]) continue;
  548.        
  549.         Vehicles[i][vehStatus]      = true;
  550.         Vehicles[i][vehID]          = cache_insert_id();
  551.         Vehicles[i][vehModel]       = model;
  552.         Vehicles[i][vehPos][0]      = x;
  553.         Vehicles[i][vehPos][1]      = y;
  554.         Vehicles[i][vehPos][2]      = z;
  555.         Vehicles[i][vehPos][3]      = a;
  556.         Vehicles[i][vehColor][0]    = 1;
  557.         Vehicles[i][vehColor][1]    = 1;
  558.         Vehicles[i][vehInt]         = 0;
  559.         Vehicles[i][vehVW]          = 0;
  560.         format(Vehicles[i][vehOwner], MAX_PLAYER_NAME, "%s", GetName(playerid));
  561.         Vehicles[i][vehLock]        = true;
  562.         Vehicles[i][vehAlarm]       = true;
  563.         for(new w = 0; w < 14; w++)
  564.         {
  565.             Vehicles[i][vehMods][w] = 0;
  566.         }
  567.         Vehicles[i][vehPaint] = 255;
  568.         format(Vehicles[i][vehPlate], 16, DEFAULT_NUMBER_PLATE);
  569.         createVehicle(i);
  570.         TextDrawShowForPlayer(playerid, buycarTD[0]);
  571.         TextDrawShowForPlayer(playerid, buycarTD[1]);
  572.         TextDrawShowForPlayer(playerid, buycarTD[2]);
  573.         TextDrawShowForPlayer(playerid, buycarTD[3]);
  574.         SetTimerEx("putinVehicle", 2000, false, "dd", playerid, Vehicles[i][vehicleData]);
  575.         break;
  576.     }
  577.     return 1;
  578. }
  579.  
  580. public putinVehicle(playerid, vehicleid)
  581. {
  582.     TextDrawHideForPlayer(playerid, buycarTD[0]);
  583.     TextDrawHideForPlayer(playerid, buycarTD[1]);
  584.     TextDrawHideForPlayer(playerid, buycarTD[2]);
  585.     TextDrawHideForPlayer(playerid, buycarTD[3]);
  586.     PutPlayerInVehicle(playerid, vehicleid, 0);
  587.     return 1;
  588. }
  589.  
  590. public OnPlayerLoadVehicles(playerid)
  591. {
  592.     new rows = cache_num_rows(koneksi), count = 0, tempString[16];
  593.     if(rows > 0)
  594.     {
  595.         new tempInt;
  596.         for(new z = 0; z < rows; z++)
  597.         {
  598.             for(new i = 0; i < MAX_VEH; i++)
  599.             {
  600.                 if(Vehicles[i][vehStatus]) continue;
  601.                
  602.                 Vehicles[i][vehStatus]      = true;
  603.                 Vehicles[i][vehID]          = cache_get_field_content_int(z, "id");
  604.                 Vehicles[i][vehModel]       = cache_get_field_content_int(z, "model");
  605.                 cache_get_field_content(z, "owner", tempString);
  606.                 format(Vehicles[i][vehOwner], MAX_PLAYER_NAME, "%s", tempString);
  607.                 Vehicles[i][vehPos][0]      = cache_get_field_content_float(z, "posX");
  608.                 Vehicles[i][vehPos][1]      = cache_get_field_content_float(z, "posY");
  609.                 Vehicles[i][vehPos][2]      = cache_get_field_content_float(z, "posZ");
  610.                 Vehicles[i][vehPos][3]      = cache_get_field_content_float(z, "posA");
  611.                 Vehicles[i][vehColor][0]    = cache_get_field_content_int(z, "color1");
  612.                 Vehicles[i][vehColor][1]    = cache_get_field_content_int(z, "color2");
  613.                 Vehicles[i][vehInt]         = cache_get_field_content_int(z, "int");
  614.                 Vehicles[i][vehVW]          = cache_get_field_content_int(z, "vw");
  615.                 new a = 1;
  616.                 for(new w = 0; w < 14; w++)
  617.                 {
  618.                     format(tempString, sizeof(tempString), "mod%d", a);
  619.                     Vehicles[i][vehMods][w] = cache_get_field_content_int(z, tempString);
  620.                     a++;
  621.                 }
  622.                 tempInt = cache_get_field_content_int(z, "locked");
  623.                 if(tempInt == 1)
  624.                     Vehicles[i][vehLock]        = true;
  625.                 else
  626.                     Vehicles[i][vehLock]        = false;
  627.                 tempInt = cache_get_field_content_int(z, "alarm");
  628.                 if(tempInt == 1)
  629.                     Vehicles[i][vehAlarm]       = true;
  630.                 else
  631.                     Vehicles[i][vehAlarm]       = false;
  632.                 cache_get_field_content(z, "plate", tempString);
  633.                 format(Vehicles[i][vehPlate], 16, "%s", tempString);
  634.                 createVehicle(i);
  635.                 count++;
  636.                 break;
  637.             }
  638.         }
  639.     }
  640.     printf("Loaded %d vehicles from %s", count, GetName(playerid));
  641.     return 1;
  642. }
  643.  
  644. public offAlarm(vehicleid)
  645. {
  646.     ToggleAlarm(vehicleid, VEHICLE_PARAMS_OFF);
  647.     return 1;
  648. }
  649.  
  650. COMMAND:gotodealership(playerid, params[])
  651. {
  652.     if(!IsPlayerAdmin(playerid))
  653.         return 0;
  654.        
  655.     SetPlayerPos(playerid, dealX, dealY, dealZ);
  656.     return 1;
  657. }
  658.  
  659. COMMAND:vcp(playerid, params[])
  660. {
  661.     if(IsPlayerInAnyVehicle(playerid))
  662.     {
  663.         new bool:found = false;
  664.         for(new i = 0; i < MAX_VEH; i++)
  665.         {
  666.             if(Vehicles[i][vehicleData] == GetPlayerVehicleID(playerid) && Vehicles[i][vehStatus])
  667.             {
  668.                 if(!strcmp(Vehicles[i][vehOwner], GetName(playerid)))
  669.                 {
  670.                     new message[256];
  671.                     format(message, sizeof(message), "Status \t\t\t");
  672.                     if(Vehicles[i][vehLock])
  673.                         format(message, sizeof(message), "%s"CHAT_YELLOW"Locked", message);
  674.                     else
  675.                         format(message, sizeof(message), "%s"CHAT_RED"Unlocked", message);
  676.                     format(message, sizeof(message), "%s\nAlarm \t\t\t", message);
  677.                     if(Vehicles[i][vehAlarm])
  678.                         format(message, sizeof(message), "%s"CHAT_YELLOW"On", message);
  679.                     else
  680.                         format(message, sizeof(message), "%s"CHAT_RED"Off", message);
  681.                     format(message, sizeof(message), "%s\nPlate \t\t\t"CHAT_YELLOW"%s", message, Vehicles[i][vehPlate]);
  682.                     format(message, sizeof(message), "%s\nPark your vehicle here", message);
  683.                     format(message, sizeof(message), "%s\nColour 1\t\t"CHAT_YELLOW"%d", message, Vehicles[i][vehColor][0]);
  684.                     format(message, sizeof(message), "%s\nColour 2\t\t"CHAT_YELLOW"%d", message, Vehicles[i][vehColor][1]);
  685.                     Player[playerid][carVCP] = i;
  686.                     ShowPlayerDialog(playerid, DIALOG_VCP, DIALOG_STYLE_LIST, "Vehicle Control Panel", message, "Choose", "Cancel");
  687.                 }
  688.                 else
  689.                 {
  690.                     Server(playerid, "You're not owner of this vehicle.");
  691.                 }
  692.                 found = true;
  693.                 break;
  694.             }
  695.         }
  696.         if(!found)
  697.         {
  698.             Server(playerid, "This command only for private vehicles.");
  699.         }
  700.     }
  701.     else
  702.     {
  703.         Server(playerid, "You must be in any vehicles to use this command.");
  704.     }
  705.     return 1;
  706. }
  707.  
  708. COMMAND:myvehicles(playerid, params[])
  709. {
  710.     new bool:found = false, msg[256];
  711.     for(new i = 0; i < MAX_VEH; i++)
  712.     {
  713.         if(!Vehicles[i][vehStatus]) continue;
  714.        
  715.         if(!strcmp(Vehicles[i][vehOwner], GetName(playerid)))
  716.         {
  717.             found = true;
  718.             format(msg, sizeof(msg), "%s%s ID : "CHAT_YELLOW"%d"CHAT_WHITE"\n", msg, namaCar[Vehicles[i][vehModel] - 400], Vehicles[i][vehID]);
  719.         }
  720.     }
  721.     if(found)
  722.     {
  723.         ShowPlayerDialog(playerid, DIALOG_MYVEHICLES, DIALOG_STYLE_LIST, "My Vehicles", msg, "Choose", "Cancel");
  724.     }
  725.     else
  726.     {
  727.         Server(playerid, "You didn't have any vehicles.");
  728.     }
  729.     return 1;
  730. }
  731.  
  732. public OnFilterScriptInit()
  733. {
  734.     print("\n-----------------------------------------");
  735.     print("        Vehicle System by Bondowocopz      ");
  736.     print("-----------------------------------------\n");
  737.     mysql_log(LOG_ERROR | LOG_WARNING, LOG_TYPE_HTML);
  738.     koneksi     =   mysql_connect(HOST, USER, DBNAME, PASSWORD);
  739.     buycarCP    =   CreateDynamicCP(dealX, dealY, dealZ, 1.0); // Checkpoint for buy vehicles
  740.     initTD();
  741.     return 1;
  742. }
  743.  
  744. public OnFilterScriptExit()
  745. {
  746.     mysql_close();
  747.     for(new i = 0; i < MAX_VEH; i++)
  748.     {
  749.         Vehicles[i][vehStatus]  = false;
  750.     }
  751.     return 1;
  752. }
  753.  
  754. public OnPlayerConnect(playerid)
  755. {
  756.     //GivePlayerMoney(playerid, 999999999);
  757.     loadVehicles(playerid);
  758.     return 1;
  759. }
  760.  
  761. public OnPlayerDisconnect(playerid, reason)
  762. {
  763.     disableGPS(playerid);
  764.     destroyCar(playerid);
  765.     return 1;
  766. }
  767.  
  768. public OnPlayerDeath(playerid, killerid, reason)
  769. {
  770.     if(GetPVarInt(playerid, "YEAH") == 1)
  771.     {
  772.         DestroyObject(GPSObject[playerid]);
  773.         SetPVarInt(playerid, "YEAH",0);
  774.         DeletePVar(playerid, "Spongebob");
  775.         DeletePVar(playerid, "Mario");
  776.         DeletePVar(playerid, "SpiderPig");
  777.         DeletePVar(playerid, "FAIL");
  778.     }
  779.     return 1;
  780. }
  781.  
  782. public OnPlayerEnterDynamicCP(playerid, checkpointid)
  783. {
  784.     if(checkpointid == buycarCP)
  785.     {
  786.         ShowPlayerDialog(playerid, DIALOG_BUYCAR, DIALOG_STYLE_LIST, "Bondowocopz Dealership", "Fast Cars\nSaloons\nMotorbikes\nUnique Cars\nIndustry Cars\nLowriders \nOff Road \nHelicopter & Plane", "Select", "Cancel");
  787.     }
  788.     return 1;
  789. }
  790.  
  791. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  792. {
  793.     new message[256];
  794.     switch(dialogid)
  795.     {
  796.         case DIALOG_BUYCAR:
  797.         {
  798.             if(response)
  799.             {
  800.                 showDealership(playerid, listitem);
  801.             }
  802.         }
  803.         case DIALOG_DEALERSHIP:
  804.         {
  805.             if(response)
  806.             {
  807.                 for(new i = 0; i < sizeof(Dealership); i++)
  808.                 {
  809.                     if(Dealership[i][dealerType] == Player[playerid][dealershipChoice])
  810.                     {
  811.                         new bool:success = false;
  812.                         if(Dealership[i][dialogID] == listitem)
  813.                         {
  814.                             if(GetPlayerMoney(playerid) >= Dealership[i][dealerPrice])
  815.                             {
  816.                                 takeMoney(playerid, Dealership[i][dealerPrice]);
  817.                                 success = true;
  818.                             }
  819.                             else
  820.                             {
  821.                                 Server(playerid, "You didn't have enough money to buy this vehicles.");
  822.                                 success = false;
  823.                             }
  824.                            
  825.                             if(success)
  826.                             {
  827.                                 new count2 = countplayerVeh(playerid);
  828.                                 if(count2 <= MAX_PLAYER_VEHICLES)
  829.                                 {
  830.                                     if (Dealership[i][dealerType] != AIR)
  831.                                     {
  832.                                         __createVehicle(Dealership[i][dealerModel], playerid, airX, airY, airZ, airA);
  833.                                     }
  834.                                     else
  835.                                     {
  836.                                         __createVehicle(Dealership[i][dealerModel], playerid, normalX, normalY, normalZ, normalA);
  837.                                     }
  838.                                 }
  839.                                 else
  840.                                 {
  841.                                     Server(playerid, "You've reached maximum car limit.");
  842.                                 }
  843.                             }
  844.                             Player[playerid][dealershipChoice] = -1;
  845.                         }
  846.                     }
  847.                 }
  848.             }
  849.         }
  850.         case DIALOG_VCP:
  851.         {
  852.             if(response)
  853.             {
  854.                 new i = Player[playerid][carVCP];
  855.                 if(i == INVALID_VEHICLE_ID)
  856.                 {
  857.                     Server(playerid, "Error when receiving vehicle data.");
  858.                     return 1;
  859.                 }
  860.                
  861.                 switch(listitem)
  862.                 {
  863.                     case 0:
  864.                     {
  865.                         if(Vehicles[i][vehLock])
  866.                         {
  867.                             Vehicles[i][vehLock] = false;
  868.                             Server(playerid, "You "CHAT_RED"unlocked"CHAT_WHITE" this vehicle.");
  869.                         }
  870.                         else
  871.                         {
  872.                             Vehicles[i][vehLock] = true;
  873.                             Server(playerid, "You "CHAT_YELLOW"locked"CHAT_WHITE" this vehicle.");
  874.                         }
  875.                         cmd_vcp(playerid, "");
  876.                     }
  877.                     case 1:
  878.                     {
  879.                         if(Vehicles[i][vehAlarm])
  880.                         {
  881.                             Vehicles[i][vehAlarm] = false;
  882.                             Server(playerid, "You toggle the alarm "CHAT_RED"off"CHAT_WHITE".");
  883.                         }
  884.                         else
  885.                         {
  886.                             Vehicles[i][vehAlarm] = true;
  887.                             Server(playerid, "You toggle the alarm "CHAT_YELLOW"on"CHAT_WHITE".");
  888.                         }
  889.                         cmd_vcp(playerid, "");
  890.                     }
  891.                     case 2:
  892.                     {
  893.                         format(message, sizeof(message), "Current Plate : "CHAT_YELLOW"%s", Vehicles[i][vehPlate]);
  894.                         ShowPlayerDialog(playerid, DIALOG_CHANGEPLATE, DIALOG_STYLE_INPUT, "Change Plate", message, "Change", "Cancel");
  895.                     }
  896.                     case 3:
  897.                     {
  898.                         parkVehicles(i, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
  899.                         Server(playerid, "Your vehicle will be spawned here next time.");
  900.                     }
  901.                     case 4:
  902.                     {
  903.                         format(message, sizeof(message), "Current Color : "CHAT_YELLOW"%d", Vehicles[i][vehColor][0]);
  904.                         ShowPlayerDialog(playerid, DIALOG_CHANGECOLOR, DIALOG_STYLE_INPUT, "Change Color", message, "Change", "Cancel");
  905.                     }
  906.                     case 5:
  907.                     {
  908.                         format(message, sizeof(message), "Current Color : "CHAT_YELLOW"%d", Vehicles[i][vehColor][1]);
  909.                         ShowPlayerDialog(playerid, DIALOG_CHANGECOLOR2, DIALOG_STYLE_INPUT, "Change Color", message, "Change", "Cancel");
  910.                     }
  911.                 }
  912.             }
  913.         }
  914.         case DIALOG_CHANGEPLATE:
  915.         {
  916.             if(response)
  917.             {
  918.                 if(strlen(inputtext) > 10 || strlen(inputtext) < 3)
  919.                 {
  920.                     Server(playerid, "Please insert 3-10 character.");
  921.                 }
  922.                 else
  923.                 {
  924.                     new i = Player[playerid][carVCP];                  
  925.                     if(i == INVALID_VEHICLE_ID)
  926.                     {
  927.                         Server(playerid, "Error when receiving vehicle data.");
  928.                         return 1;
  929.                     }
  930.                     format(Vehicles[i][vehPlate], 16, "%s", inputtext);
  931.                     SetVehicleNumberPlate(Vehicles[i][vehicleData], Vehicles[i][vehPlate]);
  932.                     createVehicle(Vehicles[i][vehicleData], true);
  933.                 }
  934.             }
  935.             cmd_vcp(playerid, "");
  936.         }
  937.         case DIALOG_CHANGECOLOR:
  938.         {
  939.             if(response)
  940.             {
  941.                 if(strval(inputtext) >= 0 && strval(inputtext) <= 255)
  942.                 {
  943.                     new i = Player[playerid][carVCP];
  944.                     Vehicles[i][vehColor][0] = strval(inputtext);
  945.                     ChangeVehicleColor(Vehicles[i][vehicleData], Vehicles[i][vehColor][0], Vehicles[i][vehColor][1]);
  946.                 }
  947.                 else
  948.                 {
  949.                     Server(playerid, "Please input between 0 - 255.");
  950.                 }
  951.             }
  952.         }
  953.         case DIALOG_CHANGECOLOR2:
  954.         {
  955.             if(response)
  956.             {
  957.                 if(strval(inputtext) >= 0 && strval(inputtext) <= 255)
  958.                 {
  959.                     new i = Player[playerid][carVCP];
  960.                     Vehicles[i][vehColor][1] = strval(inputtext);
  961.                     ChangeVehicleColor(Vehicles[i][vehicleData], Vehicles[i][vehColor][0], Vehicles[i][vehColor][1]);
  962.                 }
  963.                 else
  964.                 {
  965.                     Server(playerid, "Please input between 0 - 255.");
  966.                 }
  967.             }
  968.         }
  969.         case DIALOG_MYVEHICLES:
  970.         {
  971.             if(response)
  972.             {
  973.                 new count = 0;
  974.                 for(new i = 0; i < MAX_VEH; i++)
  975.                 {
  976.                     if(!Vehicles[i][vehStatus]) continue;
  977.                    
  978.                     if(!strcmp(Vehicles[i][vehOwner], GetName(playerid)))
  979.                     {
  980.                         if(count == listitem)
  981.                         {
  982.                             Player[playerid][carVCP] = i;
  983.                             format(message, sizeof(message), "%s - %d", namaCar[Vehicles[i][vehModel] - 400], Vehicles[i][vehID]);
  984.                             ShowPlayerDialog(playerid, DIALOG_MYVEHICLES2, DIALOG_STYLE_LIST, message, "Locate Vehicle\nRespawn Vehicle\nSell Vehicle To Server\nSell Vehicle To Player", "Choose", "Back");
  985.                             break;
  986.                         }
  987.                         else
  988.                         {
  989.                             count++;
  990.                         }
  991.                     }
  992.                 }
  993.             }
  994.         }
  995.         case DIALOG_MYVEHICLES2:
  996.         {
  997.             if(response)
  998.             {
  999.                 new i = Player[playerid][carVCP];
  1000.                 switch(listitem)
  1001.                 {
  1002.                     case 0:
  1003.                     {
  1004.                         if(IsPlayerInAnyVehicle(playerid))
  1005.                         {
  1006.                             new Float:x, Float:y, Float:z;
  1007.                             GetVehiclePos(Vehicles[i][vehicleData], x, y, z);
  1008.                             SetPVarFloat(playerid, "Spongebob", x);
  1009.                             SetPVarFloat(playerid, "Mario", y);
  1010.                             SetPVarFloat(playerid, "SpiderPig", z);
  1011.                             SetPVarString(playerid, "FAIL", "Your Car");
  1012.                             Server(playerid, "Follow the arrow to find your car.");
  1013.                             GPSObject[playerid] = CreateObject(1318, 0, 0, 0, 0.0, 0.0, 0);
  1014.                             SetPVarInt(playerid, "YEAH", 1);
  1015.                         }
  1016.                         else
  1017.                         {
  1018.                             Server(playerid, "You must be in vehicle to locate your car.");
  1019.                         }
  1020.                     }
  1021.                     case 1:
  1022.                     {
  1023.                         createVehicle(i, true);
  1024.                         Server(playerid, "Your vehicle has been respawned.");
  1025.                     }
  1026.                     case 2:
  1027.                     {
  1028.                         new price = 0;
  1029.                         for(new m = 0; m < sizeof(Dealership); m++)
  1030.                         {
  1031.                             if(Dealership[m][dealerModel] == Vehicles[i][vehModel])
  1032.                             {
  1033.                                 price = Dealership[m][dealerPrice];
  1034.                                 break;
  1035.                             }
  1036.                         }
  1037.                         price = price - floatround(price * 0.20, floatround_round);
  1038.                         format(message, sizeof(message), "Are you sure you want to sell your vehicle for "CHAT_YELLOW"$%s"CHAT_WHITE"?", FormatNumber(price));
  1039.                         ShowPlayerDialog(playerid, DIALOG_SALESERVER, DIALOG_STYLE_MSGBOX, "Sell Vehicle", message, "Sell", "Cancel");
  1040.                     }
  1041.                     case 3:
  1042.                     {
  1043.                         Player[playerid][vsellCar] = Player[playerid][carVCP];
  1044.                         ShowPlayerDialog(playerid, DIALOG_VSELL, DIALOG_STYLE_INPUT, "Sell Vehicle", "Insert player ID", "Sell", "Cancel");
  1045.                     }
  1046.                 }
  1047.             }
  1048.             else
  1049.             {
  1050.                 cmd_myvehicles(playerid, "");
  1051.             }
  1052.         }
  1053.         case DIALOG_SALESERVER:
  1054.         {
  1055.             if(response)
  1056.             {
  1057.                 new i = Player[playerid][carVCP], price = 0;
  1058.                 for(new m = 0; m < sizeof(Dealership); m++)
  1059.                 {
  1060.                     if(Dealership[m][dealerModel] == Vehicles[i][vehModel])
  1061.                     {
  1062.                         price = Dealership[m][dealerPrice];
  1063.                         break;
  1064.                     }
  1065.                 }
  1066.                 price = price - floatround(price * 0.20, floatround_round);
  1067.                 format(message, sizeof(message), CHAT_WHITE"You sold your vehicle for "CHAT_YELLOW"$%s"CHAT_WHITE".", FormatNumber(price));
  1068.                 Server(playerid, message);
  1069.                 giveMoney(playerid, price);
  1070.                 __deleteVehicle(i);
  1071.             }
  1072.         }
  1073.         case DIALOG_VSELL:
  1074.         {
  1075.             if(response)
  1076.             {
  1077.                 if(!isConnected(strval(inputtext)))
  1078.                 {
  1079.                     ShowPlayerDialog(playerid, DIALOG_VSELL, DIALOG_STYLE_INPUT, "Sell Vehicle", CHAT_WHITE"That player isn't connected!\nInsert player ID", "Sell", "Cancel");
  1080.                 }
  1081.                 else if(isMe(playerid, strval(inputtext)))
  1082.                 {
  1083.                     ShowPlayerDialog(playerid, DIALOG_VSELL, DIALOG_STYLE_INPUT, "Sell Vehicle", CHAT_WHITE"You can't sell to yourself!\nInsert player ID", "Sell", "Cancel");
  1084.                 }
  1085.                 else
  1086.                 {
  1087.                     Player[playerid][vsellTo] = strval(inputtext);
  1088.                     format(message, sizeof(message), CHAT_WHITE"You want to sell your vehicle to "CHAT_YELLOW"%s"CHAT_WHITE".\nInsert price for your vehicle", GetName(Player[playerid][vsellTo]));
  1089.                     ShowPlayerDialog(playerid, DIALOG_VSELL2, DIALOG_STYLE_INPUT, "Sell Vehicle", message, "Sell", "Cancel");
  1090.                 }
  1091.             }
  1092.         }
  1093.         case DIALOG_VSELL2:
  1094.         {
  1095.             if(response)
  1096.             {
  1097.                 if(!isConnected(Player[playerid][vsellTo]))
  1098.                 {
  1099.                     Server(playerid, "That player isn't connected.");
  1100.                     return 1;
  1101.                 }
  1102.                 if(strval(inputtext) >= 100000)
  1103.                 {
  1104.                     new msg2[512];
  1105.                     Player[playerid][vsellPrice] = strval(inputtext);
  1106.                     format(msg2, sizeof(msg2), CHAT_WHITE"Are you sure you want to sell your vehicle to "CHAT_YELLOW"%s"CHAT_WHITE".\nWith price "CHAT_YELLOW"%s", GetName(Player[playerid][vsellTo]), FormatNumber(Player[playerid][vsellPrice]));
  1107.                     ShowPlayerDialog(playerid, DIALOG_CONFVS, DIALOG_STYLE_MSGBOX, "Sell Vehicle", msg2, "Sell", "Cancel");
  1108.                 }
  1109.                 else
  1110.                 {
  1111.                     format(message, sizeof(message), CHAT_WHITE"Minimum price is 100.000!\nYou want to sell your vehicle to "CHAT_YELLOW"%s"CHAT_WHITE".\nInsert price for your vehicle", GetName(Player[playerid][vsellTo]));
  1112.                     ShowPlayerDialog(playerid, DIALOG_VSELL2, DIALOG_STYLE_INPUT, "Sell Vehicle", message, "Sell", "Cancel");
  1113.                 }
  1114.             }
  1115.         }
  1116.         case DIALOG_CONFVS:
  1117.         {
  1118.             if(response)
  1119.             {
  1120.                 new otherID = Player[playerid][vsellTo];
  1121.                 if(!isConnected(Player[playerid][vsellTo]))
  1122.                 {
  1123.                     Server(playerid, "That player isn't connected.");
  1124.                     return 1;
  1125.                 }
  1126.                 if(Player[otherID][vsellFrom] == INVALID_PLAYER_ID)
  1127.                 {
  1128.                     Player[otherID][vsellFrom] = playerid;
  1129.                     new msg2[512], i = Player[playerid][vsellCar];
  1130.                     format(msg2, sizeof(msg2), CHAT_YELLOW"%s "CHAT_WHITE" want to sell "CHAT_YELLOW"%s"CHAT_WHITE".\nWith price "CHAT_YELLOW"%s"CHAT_WHITE".\nDo you want to buy?", GetName(playerid), namaCar[Vehicles[i][vehModel] - 400], FormatNumber(Player[playerid][vsellPrice]));
  1131.                     ShowPlayerDialog(otherID, DIALOG_CONFIRMVSELL, DIALOG_STYLE_MSGBOX, "Buy Vehicle", msg2, "Buy", "Cancel");
  1132.                 }
  1133.                 else
  1134.                 {
  1135.                     Server(playerid, "That player already in transaction.");
  1136.                 }
  1137.             }
  1138.         }
  1139.         case DIALOG_CONFIRMVSELL:
  1140.         {
  1141.             new otherID = Player[playerid][vsellFrom], i = Player[otherID][vsellCar];
  1142.             if(response && Player[playerid][vsellFrom] != INVALID_PLAYER_ID)
  1143.             {
  1144.                 if(!isConnected(Player[playerid][vsellFrom]))
  1145.                 {
  1146.                     Server(playerid, "Request is expired.");
  1147.                     return 1;
  1148.                 }
  1149.                 new count2 = countplayerVeh(playerid);
  1150.                 if(count2 < MAX_PLAYER_VEHICLES)
  1151.                 {
  1152.                     if(GetPlayerMoney(playerid) >= Player[otherID][vsellPrice])
  1153.                     {
  1154.                         giveMoney(otherID, Player[otherID][vsellPrice]);
  1155.                         takeMoney(playerid, Player[otherID][vsellPrice]);
  1156.                         RemovePlayerFromVehicle(otherID);
  1157.                         format(message, sizeof(message), CHAT_YELLOW"%s bought your car for "CHAT_YELLOW"%s"CHAT_WHITE".", GetName(playerid), FormatNumber(Player[otherID][vsellPrice]));
  1158.                         ShowPlayerDialog(otherID, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Congratulations!!!", message, "Confirm", "");
  1159.                         format(message, sizeof(message), CHAT_YELLOW"Succesfully bought "CHAT_YELLOW"%s "CHAT_WHITE"car for "CHAT_YELLOW"%s"CHAT_WHITE".", GetName(otherID), Player[otherID][vsellPrice]);
  1160.                         Server(playerid, message);
  1161.                         format(Vehicles[i][vehOwner], MAX_PLAYER_NAME, GetName(playerid));
  1162.                         saveVehicles(i);
  1163.                         Player[playerid][vsellFrom] = INVALID_PLAYER_ID;
  1164.                         Player[otherID][vsellCar]   = -1;
  1165.                         Player[otherID][vsellPrice] = -1;
  1166.                     }
  1167.                     else
  1168.                     {
  1169.                         Server(playerid, "You didn't have enough money to buy that vehicle.");
  1170.                         Server(otherID, "That player didn't have enough money to buy your vehicle.");
  1171.                     }
  1172.                 }
  1173.                 else
  1174.                 {
  1175.                     Server(playerid, "You've reached maximum car limit.");
  1176.                     Server(otherID, "That player has reached maximum car limit.");
  1177.                 }
  1178.             }
  1179.             else
  1180.             {
  1181.                 if(isConnected(Player[playerid][vsellFrom]))
  1182.                 {
  1183.                     Server(otherID, "Your vehicle sell request has been denied.");
  1184.                 }
  1185.             }
  1186.             Player[playerid][vsellFrom] = INVALID_PLAYER_ID;
  1187.         }
  1188.     }
  1189.     return 1;
  1190. }
  1191.  
  1192. public OnPlayerUpdate(playerid)
  1193. {
  1194.     if(GetPVarInt(playerid,"YEAH") == 1)
  1195.     {
  1196.         new
  1197.             Float:VPos[3],
  1198.             Float:Rotation
  1199.         ;
  1200.  
  1201.         GetVehiclePos(GetPlayerVehicleID(playerid), VPos[0], VPos[1], VPos[2]);
  1202.         Rotation = PointAngle(playerid, VPos[0], VPos[1], GetPVarFloat(playerid, "Spongebob"), GetPVarFloat(playerid, "Mario"));
  1203.         AttachObjectToVehicle(GPSObject[playerid], GetPlayerVehicleID(playerid), 0.0, 0.0, 1.5, 0.0, 90.0, Rotation);
  1204.         if(IsPlayerInRangeOfPoint(playerid, 10.0, GetPVarFloat(playerid, "Spongebob"), GetPVarFloat(playerid, "Mario"), GetPVarFloat(playerid, "SpiderPig")))
  1205.         {
  1206.             DestroyObject(GPSObject[playerid]);
  1207.             SetPVarInt(playerid,"YEAH",0);
  1208.             DeletePVar(playerid,"Spongebob");
  1209.             DeletePVar(playerid,"Mario");
  1210.             DeletePVar(playerid,"SpiderPig");
  1211.             DeletePVar(playerid,"FAIL");
  1212.             Server(playerid, "You've reached your destination.");
  1213.         }
  1214.     }
  1215.     return 1;
  1216. }
  1217.  
  1218. public OnPlayerExitVehicle(playerid, vehicleid)
  1219. {
  1220.     disableGPS(playerid);
  1221.     return 1;
  1222. }
  1223.  
  1224. public OnPlayerStateChange(playerid, newstate, oldstate)
  1225. {
  1226.     disableGPS(playerid);
  1227.     if(newstate == PLAYER_STATE_DRIVER)
  1228.     {
  1229.         new vehicleid = GetPlayerVehicleID(playerid);
  1230.         for(new i = 0; i < MAX_VEH; i++)
  1231.         {
  1232.             if(Vehicles[i][vehicleData] == vehicleid)
  1233.             {
  1234.                 checkVehicle(playerid, i);
  1235.                 break;
  1236.             }
  1237.         }
  1238.     }
  1239.     return 1;
  1240. }
  1241.  
  1242. public OnVehicleMod(playerid, vehicleid, componentid)
  1243. {
  1244.     for(new i = 0; i < MAX_VEH; i++)
  1245.     {
  1246.         if(Vehicles[i][vehicleData] == vehicleid)
  1247.         {
  1248.             Vehicles[i][vehMods][GetVehicleComponentType(componentid)] = componentid;
  1249.             break;
  1250.         }
  1251.     }
  1252.     return 1;
  1253. }
  1254.  
  1255. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  1256. {
  1257.     for(new i = 0; i < MAX_VEH; i++)
  1258.     {
  1259.         if(Vehicles[i][vehicleData] == vehicleid)
  1260.         {
  1261.             Vehicles[i][vehPaint] = paintjobid;
  1262.             break;
  1263.         }
  1264.     }
  1265.     return 1;
  1266. }
  1267.  
  1268. //Hope you like it!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement