Advertisement
Guest User

Rent a Car by K3VIN

a guest
Oct 3rd, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 15.36 KB | None | 0 0
  1.  
  2. ////////////////// ========================= ///////////////////////
  3. /*
  4.     Dynamic RentaCar System by K3VIN ( http://adf.ly/WpKIm )
  5. */
  6. ////////////////////////////////////////////////////////////////////
  7.  
  8.  
  9. #include <a_samp>
  10. #include <zcmd>
  11. #include <a_mysql>
  12.  
  13.  
  14. #define Weiss       0xFFFFFFFF
  15. #define Gelb        0xFFE600FF
  16. #define Orange      0xFF9C00FF
  17.  
  18. #define MAX_RRCARS 100
  19. #define KEY_N      131072
  20.  
  21. #define SQL_HOST "127.0.0.1"
  22. #define SQL_USER "root"
  23. #define SQL_PASS "" // müsst ihr ausfüllen
  24. #define SQL_DATA "" // müsst ihr ausfüllen
  25.  
  26.  
  27. new SaveRCarPos[MAX_PLAYERS],
  28.     RentVeh[MAX_RRCARS],
  29.     FahrzeugNamen[][] =
  30.     {
  31.     "Landstalker","Bravura","Buffalo","Linerunner","Perrenial","Sentinel",
  32.     "Dumper","Firetruck","Trashmaster","Stretch","Manana","Infernus",
  33.     "Voodoo","Pony","Mule","Cheetah","Ambulance","Leviathan","Moonbeam",
  34.     "Esperanto","Taxi","Washington","Bobcat","Whoopee","BF Injection",
  35.     "Hunter","Premier","Enforcer","Securicar","Banshee","Predator","Bus",
  36.     "Rhino","Barracks","Hotknife","Trailer","Previon","Coach","Cabbie",
  37.     "Stallion","Rumpo","RC Bandit","Romero","Packer","Monster","Admiral",
  38.     "Squalo","Seasparrow","Pizzaboy","Tram","Trailer","Turismo","Speeder",
  39.     "Reefer","Tropic","Flatbed","Yankee","Caddy","Solair","Berkley's RC Van",
  40.     "Skimmer","PCJ-600","Faggio","Freeway","RC Baron","RC Raider","Glendale",
  41.     "Oceanic","Sanchez","Sparrow","Patriot","Quad","Coastguard","Dinghy",
  42.     "Hermes","Sabre","Rustler","ZR-350","Walton","Regina","Comet","BMX",
  43.     "Burrito","Camper","Marquis","Baggage","Dozer","Maverick","News Chopper",
  44.     "Rancher","FBI Rancher","Virgo","Greenwood","Jetmax","Hotring","Sandking",
  45.     "Blista Compact","Police Maverick","Boxvillde","Benson","Mesa","RC Goblin",
  46.     "Hotring Racer A","Hotring Racer B","Bloodring Banger","Rancher","Super GT",
  47.     "Elegant","Journey","Bike","Mountain Bike","Beagle","Cropduster","Stunt",
  48.     "Tanker","Roadtrain","Nebula","Majestic","Buccaneer","Shamal","Hydra",
  49.     "FCR-900","NRG-500","HPV1000","Cement Truck","Tow Truck","Fortune",
  50.     "Cadrona","FBI Truck","Willard","Forklift","Tractor","Combine","Feltzer",
  51.     "Remington","Slamvan","Blade","Freight","Streak","Vortex","Vincent",
  52.     "Bullet","Clover","Sadler","Firetruck","Hustler","Intruder","Primo",
  53.     "Cargobob","Tampa","Sunrise","Merit","Utility","Nevada","Yosemite",
  54.     "Windsor","Monster","Monster","Uranus","Jester","Sultan","Stratum",
  55.     "Elegy","Blackhawk","RC Tiger","Flash","Tahoma","Savanna","Bandito",
  56.     "Freight Flat","Streak Carriage","Kart","Mower","Dune","Sweeper",
  57.     "Broadway","Tornado","AT-400","DFT-30","Huntley","Stafford","BF-400",
  58.     "News Van","Tug","Trailer","Emperor","Wayfarer","Euros","Hotdog","Club",
  59.     "Freight Box","Trailer","Andromada","Dodo","RC Cam","Launch","Police Car",
  60.     "Police Car","Police Car","Police Ranger","Picador","S.W.A.T","Alpha",
  61.     "Phoenix","Glendale","Sadler","Luggage","Luggage","Stairs","Boxville",
  62.     "Tiller","Utility Trailer"
  63.     };
  64.  
  65. main()
  66. {
  67.     print("\n----------------------------------");
  68.     print("\tRent a Car by K3VIN");
  69.     print("----------------------------------\n");
  70. }
  71.  
  72. enum
  73. {
  74.     DIALOG_CREATECAR,
  75.     DIALOG_MODELID,
  76.     DIALOG_RENTPREIS,
  77.     DIALOG_COLOR1,
  78.     DIALOG_COLOR2,
  79.     DIALOG_SPAWNPOS,
  80.     DIALOG_CREATERC,
  81.     DIALOG_RENTCAR
  82. }
  83.  
  84. enum RRCars
  85. {
  86.     cID,
  87.     Modelid,
  88.     Mietpreis,
  89.     Color1,
  90.     Color2,
  91.     Float:x,
  92.     Float:y,
  93.     Float:z,
  94.     Float:sx,
  95.     Float:sy,
  96.     Float:sz
  97. }
  98. new RentCar[MAX_RRCARS][RRCars];
  99.  
  100. public OnFilterScriptInit()
  101. {
  102.     Connect_To_Database();
  103.     mysql_query("CREATE TABLE IF NOT EXISTS `RentCars` (`id` int(11),`Modelid` int(11),`Mietpreis` int(11),`Color1` int(11),`Color2` int(11),`x` varchar(40),`y` varchar(40),`z` varchar(40),`sx` varchar(40),`sy` varchar(40),`sz` varchar(40), PRIMARY KEY(`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
  104.     LoadRC();
  105.     return 1;
  106. }
  107.  
  108. public OnFilterScriptExit()
  109. {
  110.     mysql_close();
  111.     return 1;
  112. }
  113.  
  114. COMMAND:createrentcar(playerid,params[])
  115. {
  116.     ShowPlayerDialog(playerid,DIALOG_CREATECAR,DIALOG_STYLE_INPUT,"Rent a Car Fahrzeug erstellen","Bitte gib die ID ein, die in die Datenbank eingeragen wird.\nNicht die Model ID!","absenden","abbrechen");
  117.     return 1;
  118. }
  119.  
  120. public OnPlayerEnterCheckpoint(playerid)
  121. {
  122.     DisablePlayerCheckpoint(playerid);
  123.     return 1;
  124. }
  125.  
  126. public OnPlayerStateChange(playerid, newstate, oldstate)
  127. {
  128.     new vehicleid = GetPlayerVehicleID(playerid);
  129.     if(newstate == PLAYER_STATE_DRIVER && IstRC(vehicleid))
  130.     {
  131.         new string[128],carid = GetRCIndex(vehicleid),model = RentCar[carid][Modelid];
  132.         SetPVarInt(playerid,"CARID",carid);
  133.         format(string,sizeof(string),"Fahrzeugname: {FFAA00}%s{FEFEFE}\nFahrzeug ID: {FFAA00}%d{FEFEFE}\nMietpreis: {FFAA00}%d$\n\nMöchtest du dieses Fahrzeug mieten ?",FahrzeugNamen[model-400],carid,RentCar[carid][Mietpreis]);
  134.         ShowPlayerDialog(playerid,DIALOG_RENTCAR,DIALOG_STYLE_MSGBOX,"Rent a Car",string,"mieten","verlassen"); return 1;
  135.     }
  136.     return 1;
  137. }
  138.  
  139. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  140. {
  141.     if(newkeys & KEY_N)
  142.     {
  143.         if(SaveRCarPos[playerid] == 1)
  144.         {
  145.             new model = GetPVarInt(playerid,"MODELID"), string[256],Float:px,Float:py,Float:pz; GetPlayerPos(playerid,px,py,pz); SetPVarFloat(playerid,"SPX",px); SetPVarFloat(playerid,"SPY",py); SetPVarFloat(playerid,"SPZ",pz);
  146.             format(string,sizeof(string),"Fahrzeugname: %s\nFahrzeug ID: %d\nModel ID: %d\nMietpreis: %d$\nPrimärfarbe: %d\nSekundfärbe: %d\nPos X: %f\nPos Y: %f\nPos Z: %f\nSpawnpos X: %f\nSpawnpos Y: %f\nSpawnpos Z: %f\n\n\nMöchtest du dieses Fahrzeug erstellen?",
  147.             FahrzeugNamen[model-400],GetPVarInt(playerid,"CARID"),GetPVarInt(playerid,"MODELID"),GetPVarInt(playerid,"MIETPREIS"),GetPVarInt(playerid,"COLOR1"),GetPVarInt(playerid,"COLOR2"),GetPVarFloat(playerid,"PX"),GetPVarFloat(playerid,"PY"),GetPVarFloat(playerid,"PZ"),GetPVarFloat(playerid,"SPX"),GetPVarFloat(playerid,"SPY"),GetPVarFloat(playerid,"SPZ"));
  148.             ShowPlayerDialog(playerid,DIALOG_CREATERC,DIALOG_STYLE_MSGBOX,"Rent a Car erstellen",string,"erstellen","abbrechen"); SaveRCarPos[playerid] = 0; return 1;
  149.         }
  150.     }
  151.     return 1;
  152. }
  153.  
  154. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  155. {
  156.     new string[256];
  157.     if(dialogid==DIALOG_CREATECAR)
  158.     {
  159.         if(response) {
  160.             new carid = strval(inputtext),Float:px,Float:py,Float:pz;
  161.             GetPlayerPos(playerid,px,py,pz);
  162.             if(mysql_CheckRC(carid) == 1) { ShowPlayerDialog(playerid,DIALOG_CREATECAR,DIALOG_STYLE_INPUT,"Rent a Car Fahrzeug erstellen","Diese ID existiert bereits !\n\nBitte gib die ID ein, die in die Datenbank eingeragen wird.\nNicht die Model ID!","absenden","bbrechen"); }
  163.             else { SetPVarInt(playerid,"CARID",carid); SetPVarFloat(playerid,"PX",px); SetPVarFloat(playerid,"PY",py); SetPVarFloat(playerid,"PZ",pz); ShowPlayerDialog(playerid,DIALOG_MODELID,DIALOG_STYLE_INPUT,"Rent a Car Model ID","Bitte gib die Model ID des Fahrzeuges an. 400 - 611","absenden","abbrechen"); return 1; }
  164.         }
  165.     }
  166.     if(dialogid==DIALOG_MODELID)
  167.     {
  168.         if(!response) { SetPVarInt(playerid,"CARID",0); SetPVarFloat(playerid,"PX",0.0); SetPVarFloat(playerid,"PY",0.0); SetPVarFloat(playerid,"PZ",0.0); }
  169.         if(response) {
  170.             new modelid = strval(inputtext);
  171.             if(modelid < 400)return ShowPlayerDialog(playerid,DIALOG_MODELID,DIALOG_STYLE_INPUT,"Rent a Car Model ID","Bitte gib die Model ID des Fahrzeuges an. 400 - 611","absenden","abbrechen");
  172.             if(modelid > 611)return ShowPlayerDialog(playerid,DIALOG_MODELID,DIALOG_STYLE_INPUT,"Rent a Car Model ID","Bitte gib die Model ID des Fahrzeuges an. 400 - 611","absenden","abbrechen");
  173.             SetPVarInt(playerid,"MODELID",modelid); ShowPlayerDialog(playerid,DIALOG_RENTPREIS,DIALOG_STYLE_INPUT,"Rent a Car Mietpreis","Bitte gib den Mietpreis für das Fahrzeug an!","absenden","abbrechen"); return 1;
  174.         }
  175.     }
  176.     if(dialogid==DIALOG_RENTPREIS)
  177.     {
  178.         if(!response) { SetPVarInt(playerid,"CARID",0); SetPVarFloat(playerid,"PX",0.0); SetPVarFloat(playerid,"PY",0.0); SetPVarFloat(playerid,"PZ",0.0); SetPVarInt(playerid,"MODELID",0); }
  179.         if(response) {
  180.             new mietpreis = strval(inputtext);
  181.             if(mietpreis <= 0)return ShowPlayerDialog(playerid,DIALOG_RENTPREIS,DIALOG_STYLE_INPUT,"Rent a Car Mietpreis","Der Mietpreis ist zu niedrig!\n\nBitte gib den Mietpreis für das Fahrzeug an!","absenden","abbrechen");
  182.             SetPVarInt(playerid,"MIETPREIS",mietpreis); ShowPlayerDialog(playerid,DIALOG_COLOR1,DIALOG_STYLE_INPUT,"Rent a Car Primär Farbe","Bitte gib die Farb ID der Primärfarbe des Fahrzeuges an! 0 - 255","absenden","abbrechen"); return 1;
  183.         }
  184.     }
  185.     if(dialogid==DIALOG_COLOR1)
  186.     {
  187.         if(!response) { SetPVarInt(playerid,"CARID",0); SetPVarFloat(playerid,"PX",0.0); SetPVarFloat(playerid,"PY",0.0); SetPVarFloat(playerid,"PZ",0.0); SetPVarInt(playerid,"MODELID",0); SetPVarInt(playerid,"MIETPREIS",0); }
  188.         if(response)
  189.         {
  190.             new c1 = strval(inputtext);
  191.             if(c1 < 0)return ShowPlayerDialog(playerid,DIALOG_COLOR1,DIALOG_STYLE_INPUT,"Rent a Car Primär Farbe","Bitte gib die Farb ID der Primärfarbe des Fahrzeuges an! 0 - 255","absenden","abbrechen");
  192.             if(c1 > 255)return ShowPlayerDialog(playerid,DIALOG_COLOR1,DIALOG_STYLE_INPUT,"Rent a Car Primär Farbe","Bitte gib die Farb ID der Primärfarbe des Fahrzeuges an! 0 - 255","absenden","abbrechen");
  193.             SetPVarInt(playerid,"COLOR1",c1); ShowPlayerDialog(playerid,DIALOG_COLOR2,DIALOG_STYLE_INPUT,"Rent a Car Sekundär Farbe","Bitte gib die ID der Sekundär Farbe des Fahrzeuges an! 0 - 255","absenden","abbrechen"); return 1;
  194.         }
  195.     }
  196.     if(dialogid==DIALOG_COLOR2)
  197.     {
  198.         if(!response) { SetPVarInt(playerid,"CARID",0); SetPVarFloat(playerid,"PX",0.0); SetPVarFloat(playerid,"PY",0.0); SetPVarFloat(playerid,"PZ",0.0); SetPVarInt(playerid,"MODELID",0); SetPVarInt(playerid,"MIETPREIS",0); SetPVarInt(playerid,"COLOR1",0); }
  199.         if(response) {
  200.             new c2 = strval(inputtext);
  201.             if(c2 < 0)return ShowPlayerDialog(playerid,DIALOG_COLOR2,DIALOG_STYLE_INPUT,"Rent a Car Sekundär Farbe","Bitte gib die ID der Sekundär Farbe des Fahrzeuges an! 0 - 255","absenden","abbrechen");
  202.             if(c2 > 255)return ShowPlayerDialog(playerid,DIALOG_COLOR2,DIALOG_STYLE_INPUT,"Rent a Car Sekundär Farbe","Bitte gib die ID der Sekundär Farbe des Fahrzeuges an! 0 - 255","absenden","abbrechen");
  203.             SetPVarInt(playerid,"COLOR2",c2); ShowPlayerDialog(playerid,DIALOG_SPAWNPOS,DIALOG_STYLE_MSGBOX,"Rent a Car Spawnpos","Bitte gehe nun zu der Position wo das Fahrzeug\nbei einer vermietung spawnen soll und drücke '{FFAA00}N{FEFEFE}'","weiter","abbrechen"); SaveRCarPos[playerid] = 1; return 1;
  204.         }
  205.     }
  206.     if(dialogid==DIALOG_CREATERC)
  207.     {
  208.         if(!response) { SetPVarInt(playerid,"CARID",0); SetPVarInt(playerid,"MODELID",0); SetPVarInt(playerid,"MIETPREIS",0); SetPVarInt(playerid,"COLOR1",0); SetPVarInt(playerid,"COLOR2",0); SetPVarFloat(playerid,"PX",0.0); SetPVarFloat(playerid,"PY",0.0); SetPVarFloat(playerid,"PZ",0.0); SetPVarFloat(playerid,"SPX",0.0); SetPVarFloat(playerid,"SPY",0.0); SetPVarFloat(playerid,"SPZ",0.0); }
  209.         if(response) {
  210.             new carid = GetPVarInt(playerid,"CARID");
  211.             RentCar[carid][cID] = carid;
  212.             RentCar[carid][Modelid] = GetPVarInt(playerid,"MODELID");
  213.             RentCar[carid][Mietpreis] = GetPVarInt(playerid,"MIETPREIS");
  214.             RentCar[carid][Color1] = GetPVarInt(playerid,"COLOR1");
  215.             RentCar[carid][Color2] = GetPVarInt(playerid,"COLOR2");
  216.             RentCar[carid][x] = GetPVarFloat(playerid,"PX");
  217.             RentCar[carid][y] = GetPVarFloat(playerid,"PY");
  218.             RentCar[carid][z] = GetPVarFloat(playerid,"PZ");
  219.             RentCar[carid][sx] = GetPVarFloat(playerid,"SPX");
  220.             RentCar[carid][sy] = GetPVarFloat(playerid,"SPY");
  221.             RentCar[carid][sz] = GetPVarFloat(playerid,"SPZ");
  222.             format(string,sizeof(string),"INSERT INTO `RentCars` (`id`,`Modelid`,`Mietpreis`,`Color1`,`Color2`,`x`,`y`,`z`,`sx`,`sy`,`sz`) VALUES('%d','%d','%d','%d','%d','%f','%f','%f','%f','%f','%f')",
  223.             RentCar[carid][cID],RentCar[carid][Modelid],RentCar[carid][Mietpreis],RentCar[carid][Color1],RentCar[carid][Color2],RentCar[carid][x],RentCar[carid][y],RentCar[carid][z],RentCar[carid][sx],RentCar[carid][sy],RentCar[carid][sz]);
  224.             mysql_query(string);
  225.             RentVeh[carid] = CreateVehicle(RentCar[carid][Modelid],RentCar[carid][x],RentCar[carid][y],RentCar[carid][z],0.0,RentCar[carid][Color1],RentCar[carid][Color2],-1);
  226.         }
  227.     }
  228.     if(dialogid==DIALOG_RENTCAR)
  229.     {
  230.         if(!response) { RemovePlayerFromVehicle(playerid); }
  231.         if(response) {
  232.             new carid = GetPVarInt(playerid,"CARID");
  233.             if(GetPlayerMoney(playerid) < RentCar[carid][Mietpreis]) { SendClientMessage(playerid,Orange,"Du kannst dir dieses Fahrzeug nicht leisten!"); RemovePlayerFromVehicle(playerid); }
  234.             else {
  235.                 CreateVehicle(RentCar[carid][Modelid],RentCar[carid][sx],RentCar[carid][sy],RentCar[carid][sz],0.0,RentCar[carid][Color1],RentCar[carid][Color2],-1); GivePlayerMoney(playerid,-RentCar[carid][Mietpreis]); SendClientMessage(playerid,Gelb,"Fahrzeug erfolgreich gemietet. Es wurde dir auf der Map makiert!");
  236.                 SetPlayerCheckpoint(playerid,RentCar[carid][sx],RentCar[carid][sy],RentCar[carid][sz],5.0);  RemovePlayerFromVehicle(playerid); return 1;
  237.             }
  238.         }
  239.     }
  240.     return 1;
  241. }
  242.  
  243.  
  244. stock LoadRC()
  245. {
  246.     new query[256];
  247.     mysql_query("SELECT * FROM `RentCars`");
  248.     mysql_store_result();
  249.     for(new i; i<mysql_num_rows(); i++)
  250.     {
  251.         if(i>=MAX_RRCARS)break;
  252.         mysql_retrieve_row();
  253.         mysql_fetch_field_row(query,"id"); RentCar[i][cID] = strval(query);
  254.         mysql_fetch_field_row(query,"Modelid"); RentCar[i][Modelid] = strval(query);
  255.         mysql_fetch_field_row(query,"Mietpreis"); RentCar[i][Mietpreis] = strval(query);
  256.         mysql_fetch_field_row(query,"Color1"); RentCar[i][Color1] = strval(query);
  257.         mysql_fetch_field_row(query,"Color2"); RentCar[i][Color2] = strval(query);
  258.         mysql_fetch_field_row(query,"x"); RentCar[i][x] = floatstr(query);
  259.         mysql_fetch_field_row(query,"y"); RentCar[i][y] = floatstr(query);
  260.         mysql_fetch_field_row(query,"z"); RentCar[i][z] = floatstr(query);
  261.         mysql_fetch_field_row(query,"sx"); RentCar[i][sx] = floatstr(query);
  262.         mysql_fetch_field_row(query,"sy"); RentCar[i][sy] = floatstr(query);
  263.         mysql_fetch_field_row(query,"sz"); RentCar[i][sz] = floatstr(query);
  264.         RentVeh[i] = CreateVehicle(RentCar[i][Modelid],RentCar[i][x],RentCar[i][y],RentCar[i][z],0.0,RentCar[i][Color1],RentCar[i][Color2],-1);
  265.     }
  266.     mysql_free_result();
  267. }
  268.  
  269. stock mysql_CheckRC(carid)
  270. {
  271.     new query[128];
  272.     format(query,sizeof(query),"SELECT * FROM `RentCars` WHERE `id` = '%d'",carid);
  273.     mysql_query(query);
  274.     mysql_store_result();
  275.     return mysql_num_rows();
  276. }
  277.  
  278.  
  279. stock GetRCIndex(vid)
  280. {
  281.     for(new a; a<(sizeof(RentVeh)); a++)
  282.     {
  283.         if(RentVeh[a] != vid)continue;
  284.         {
  285.             return a;
  286.         }
  287.     }
  288.     return 0;
  289. }
  290.  
  291. stock IstRC(vehicleid)
  292. {
  293.     for(new a; a<(sizeof(RentVeh)); a++)
  294.     {
  295.         if(RentVeh[a] != vehicleid)continue;
  296.         {
  297.             return 1;
  298.         }
  299.     }
  300.     return 0;
  301. }
  302.  
  303.  
  304.  
  305. stock Connect_To_Database()
  306. {
  307.     mysql_connect(SQL_HOST, SQL_USER, SQL_DATA, SQL_PASS);
  308.     if(mysql_ping() == 1)
  309.     {
  310.         print("<-| [MYSQL] Verbindung zur Datenbank wurde erfolgreich hergestellt!");
  311.         return true;
  312.     }
  313.     else
  314.     {
  315.         print("<-| [MYSQL] Es konnte keine Verbindung zur Datenbank hergestellt werden!");
  316.         print("<-| [MYSQL] Es wird erneut versucht eine Verbindung zur Datenbank herzustellen!");
  317.         mysql_connect(SQL_HOST, SQL_USER, SQL_DATA, SQL_PASS);
  318.         if(mysql_ping() == 1)
  319.         {
  320.             print("<-| [MYSQL] Es konnte im 2 Versuch eine Verbindung hergestellt werden!");
  321.             return true;
  322.         }
  323.         else
  324.         {
  325.             print("<-| [MYSQL] Es konnte keine Verbindung zur Datenbank hergestellt werden!");
  326.             print("<-| [MYSQL] Der Server wird nun beendet!");
  327.             SendRconCommand("exit");
  328.             return true;
  329.         }
  330.     }
  331. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement