Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////// ========================= ///////////////////////
- /*
- Dynamic RentaCar System by K3VIN ( http://adf.ly/WpKIm )
- */
- ////////////////////////////////////////////////////////////////////
- #include <a_samp>
- #include <zcmd>
- #include <a_mysql>
- #define Weiss 0xFFFFFFFF
- #define Gelb 0xFFE600FF
- #define Orange 0xFF9C00FF
- #define MAX_RRCARS 100
- #define KEY_N 131072
- #define SQL_HOST "127.0.0.1"
- #define SQL_USER "root"
- #define SQL_PASS "" // müsst ihr ausfüllen
- #define SQL_DATA "" // müsst ihr ausfüllen
- new SaveRCarPos[MAX_PLAYERS],
- RentVeh[MAX_RRCARS],
- FahrzeugNamen[][] =
- {
- "Landstalker","Bravura","Buffalo","Linerunner","Perrenial","Sentinel",
- "Dumper","Firetruck","Trashmaster","Stretch","Manana","Infernus",
- "Voodoo","Pony","Mule","Cheetah","Ambulance","Leviathan","Moonbeam",
- "Esperanto","Taxi","Washington","Bobcat","Whoopee","BF Injection",
- "Hunter","Premier","Enforcer","Securicar","Banshee","Predator","Bus",
- "Rhino","Barracks","Hotknife","Trailer","Previon","Coach","Cabbie",
- "Stallion","Rumpo","RC Bandit","Romero","Packer","Monster","Admiral",
- "Squalo","Seasparrow","Pizzaboy","Tram","Trailer","Turismo","Speeder",
- "Reefer","Tropic","Flatbed","Yankee","Caddy","Solair","Berkley's RC Van",
- "Skimmer","PCJ-600","Faggio","Freeway","RC Baron","RC Raider","Glendale",
- "Oceanic","Sanchez","Sparrow","Patriot","Quad","Coastguard","Dinghy",
- "Hermes","Sabre","Rustler","ZR-350","Walton","Regina","Comet","BMX",
- "Burrito","Camper","Marquis","Baggage","Dozer","Maverick","News Chopper",
- "Rancher","FBI Rancher","Virgo","Greenwood","Jetmax","Hotring","Sandking",
- "Blista Compact","Police Maverick","Boxvillde","Benson","Mesa","RC Goblin",
- "Hotring Racer A","Hotring Racer B","Bloodring Banger","Rancher","Super GT",
- "Elegant","Journey","Bike","Mountain Bike","Beagle","Cropduster","Stunt",
- "Tanker","Roadtrain","Nebula","Majestic","Buccaneer","Shamal","Hydra",
- "FCR-900","NRG-500","HPV1000","Cement Truck","Tow Truck","Fortune",
- "Cadrona","FBI Truck","Willard","Forklift","Tractor","Combine","Feltzer",
- "Remington","Slamvan","Blade","Freight","Streak","Vortex","Vincent",
- "Bullet","Clover","Sadler","Firetruck","Hustler","Intruder","Primo",
- "Cargobob","Tampa","Sunrise","Merit","Utility","Nevada","Yosemite",
- "Windsor","Monster","Monster","Uranus","Jester","Sultan","Stratum",
- "Elegy","Blackhawk","RC Tiger","Flash","Tahoma","Savanna","Bandito",
- "Freight Flat","Streak Carriage","Kart","Mower","Dune","Sweeper",
- "Broadway","Tornado","AT-400","DFT-30","Huntley","Stafford","BF-400",
- "News Van","Tug","Trailer","Emperor","Wayfarer","Euros","Hotdog","Club",
- "Freight Box","Trailer","Andromada","Dodo","RC Cam","Launch","Police Car",
- "Police Car","Police Car","Police Ranger","Picador","S.W.A.T","Alpha",
- "Phoenix","Glendale","Sadler","Luggage","Luggage","Stairs","Boxville",
- "Tiller","Utility Trailer"
- };
- main()
- {
- print("\n----------------------------------");
- print("\tRent a Car by K3VIN");
- print("----------------------------------\n");
- }
- enum
- {
- DIALOG_CREATECAR,
- DIALOG_MODELID,
- DIALOG_RENTPREIS,
- DIALOG_COLOR1,
- DIALOG_COLOR2,
- DIALOG_SPAWNPOS,
- DIALOG_CREATERC,
- DIALOG_RENTCAR
- }
- enum RRCars
- {
- cID,
- Modelid,
- Mietpreis,
- Color1,
- Color2,
- Float:x,
- Float:y,
- Float:z,
- Float:sx,
- Float:sy,
- Float:sz
- }
- new RentCar[MAX_RRCARS][RRCars];
- public OnFilterScriptInit()
- {
- Connect_To_Database();
- 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;");
- LoadRC();
- return 1;
- }
- public OnFilterScriptExit()
- {
- mysql_close();
- return 1;
- }
- COMMAND:createrentcar(playerid,params[])
- {
- 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");
- return 1;
- }
- public OnPlayerEnterCheckpoint(playerid)
- {
- DisablePlayerCheckpoint(playerid);
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- new vehicleid = GetPlayerVehicleID(playerid);
- if(newstate == PLAYER_STATE_DRIVER && IstRC(vehicleid))
- {
- new string[128],carid = GetRCIndex(vehicleid),model = RentCar[carid][Modelid];
- SetPVarInt(playerid,"CARID",carid);
- 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]);
- ShowPlayerDialog(playerid,DIALOG_RENTCAR,DIALOG_STYLE_MSGBOX,"Rent a Car",string,"mieten","verlassen"); return 1;
- }
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(newkeys & KEY_N)
- {
- if(SaveRCarPos[playerid] == 1)
- {
- 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);
- 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?",
- 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"));
- ShowPlayerDialog(playerid,DIALOG_CREATERC,DIALOG_STYLE_MSGBOX,"Rent a Car erstellen",string,"erstellen","abbrechen"); SaveRCarPos[playerid] = 0; return 1;
- }
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- new string[256];
- if(dialogid==DIALOG_CREATECAR)
- {
- if(response) {
- new carid = strval(inputtext),Float:px,Float:py,Float:pz;
- GetPlayerPos(playerid,px,py,pz);
- 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"); }
- 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; }
- }
- }
- if(dialogid==DIALOG_MODELID)
- {
- if(!response) { SetPVarInt(playerid,"CARID",0); SetPVarFloat(playerid,"PX",0.0); SetPVarFloat(playerid,"PY",0.0); SetPVarFloat(playerid,"PZ",0.0); }
- if(response) {
- new modelid = strval(inputtext);
- 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");
- 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");
- 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;
- }
- }
- if(dialogid==DIALOG_RENTPREIS)
- {
- 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); }
- if(response) {
- new mietpreis = strval(inputtext);
- 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");
- 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;
- }
- }
- if(dialogid==DIALOG_COLOR1)
- {
- 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); }
- if(response)
- {
- new c1 = strval(inputtext);
- 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");
- 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");
- 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;
- }
- }
- if(dialogid==DIALOG_COLOR2)
- {
- 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); }
- if(response) {
- new c2 = strval(inputtext);
- 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");
- 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");
- 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;
- }
- }
- if(dialogid==DIALOG_CREATERC)
- {
- 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); }
- if(response) {
- new carid = GetPVarInt(playerid,"CARID");
- RentCar[carid][cID] = carid;
- RentCar[carid][Modelid] = GetPVarInt(playerid,"MODELID");
- RentCar[carid][Mietpreis] = GetPVarInt(playerid,"MIETPREIS");
- RentCar[carid][Color1] = GetPVarInt(playerid,"COLOR1");
- RentCar[carid][Color2] = GetPVarInt(playerid,"COLOR2");
- RentCar[carid][x] = GetPVarFloat(playerid,"PX");
- RentCar[carid][y] = GetPVarFloat(playerid,"PY");
- RentCar[carid][z] = GetPVarFloat(playerid,"PZ");
- RentCar[carid][sx] = GetPVarFloat(playerid,"SPX");
- RentCar[carid][sy] = GetPVarFloat(playerid,"SPY");
- RentCar[carid][sz] = GetPVarFloat(playerid,"SPZ");
- 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')",
- 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]);
- mysql_query(string);
- RentVeh[carid] = CreateVehicle(RentCar[carid][Modelid],RentCar[carid][x],RentCar[carid][y],RentCar[carid][z],0.0,RentCar[carid][Color1],RentCar[carid][Color2],-1);
- }
- }
- if(dialogid==DIALOG_RENTCAR)
- {
- if(!response) { RemovePlayerFromVehicle(playerid); }
- if(response) {
- new carid = GetPVarInt(playerid,"CARID");
- if(GetPlayerMoney(playerid) < RentCar[carid][Mietpreis]) { SendClientMessage(playerid,Orange,"Du kannst dir dieses Fahrzeug nicht leisten!"); RemovePlayerFromVehicle(playerid); }
- else {
- 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!");
- SetPlayerCheckpoint(playerid,RentCar[carid][sx],RentCar[carid][sy],RentCar[carid][sz],5.0); RemovePlayerFromVehicle(playerid); return 1;
- }
- }
- }
- return 1;
- }
- stock LoadRC()
- {
- new query[256];
- mysql_query("SELECT * FROM `RentCars`");
- mysql_store_result();
- for(new i; i<mysql_num_rows(); i++)
- {
- if(i>=MAX_RRCARS)break;
- mysql_retrieve_row();
- mysql_fetch_field_row(query,"id"); RentCar[i][cID] = strval(query);
- mysql_fetch_field_row(query,"Modelid"); RentCar[i][Modelid] = strval(query);
- mysql_fetch_field_row(query,"Mietpreis"); RentCar[i][Mietpreis] = strval(query);
- mysql_fetch_field_row(query,"Color1"); RentCar[i][Color1] = strval(query);
- mysql_fetch_field_row(query,"Color2"); RentCar[i][Color2] = strval(query);
- mysql_fetch_field_row(query,"x"); RentCar[i][x] = floatstr(query);
- mysql_fetch_field_row(query,"y"); RentCar[i][y] = floatstr(query);
- mysql_fetch_field_row(query,"z"); RentCar[i][z] = floatstr(query);
- mysql_fetch_field_row(query,"sx"); RentCar[i][sx] = floatstr(query);
- mysql_fetch_field_row(query,"sy"); RentCar[i][sy] = floatstr(query);
- mysql_fetch_field_row(query,"sz"); RentCar[i][sz] = floatstr(query);
- RentVeh[i] = CreateVehicle(RentCar[i][Modelid],RentCar[i][x],RentCar[i][y],RentCar[i][z],0.0,RentCar[i][Color1],RentCar[i][Color2],-1);
- }
- mysql_free_result();
- }
- stock mysql_CheckRC(carid)
- {
- new query[128];
- format(query,sizeof(query),"SELECT * FROM `RentCars` WHERE `id` = '%d'",carid);
- mysql_query(query);
- mysql_store_result();
- return mysql_num_rows();
- }
- stock GetRCIndex(vid)
- {
- for(new a; a<(sizeof(RentVeh)); a++)
- {
- if(RentVeh[a] != vid)continue;
- {
- return a;
- }
- }
- return 0;
- }
- stock IstRC(vehicleid)
- {
- for(new a; a<(sizeof(RentVeh)); a++)
- {
- if(RentVeh[a] != vehicleid)continue;
- {
- return 1;
- }
- }
- return 0;
- }
- stock Connect_To_Database()
- {
- mysql_connect(SQL_HOST, SQL_USER, SQL_DATA, SQL_PASS);
- if(mysql_ping() == 1)
- {
- print("<-| [MYSQL] Verbindung zur Datenbank wurde erfolgreich hergestellt!");
- return true;
- }
- else
- {
- print("<-| [MYSQL] Es konnte keine Verbindung zur Datenbank hergestellt werden!");
- print("<-| [MYSQL] Es wird erneut versucht eine Verbindung zur Datenbank herzustellen!");
- mysql_connect(SQL_HOST, SQL_USER, SQL_DATA, SQL_PASS);
- if(mysql_ping() == 1)
- {
- print("<-| [MYSQL] Es konnte im 2 Versuch eine Verbindung hergestellt werden!");
- return true;
- }
- else
- {
- print("<-| [MYSQL] Es konnte keine Verbindung zur Datenbank hergestellt werden!");
- print("<-| [MYSQL] Der Server wird nun beendet!");
- SendRconCommand("exit");
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement