Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Dynamic Server Cars - Tayab Soomro
- This script is proudly created by me (Tayab). I've initiated working on SA-MP Scripting nowadays, day by day
- I learn something new which I did not know yesterday. So much so that today I am able to create my own Dynamic
- Car Saving System.
- It's a SQLite based script which can easily be converted to almost any saving system out there. If having problem doing
- that, don't hesitate to contact me.
- CREDITS:
- Tayab Soomro - Developing Script
- Y_LESS - SSCANF
- BEN - General Help
- Unknown - ZCMD Command System
- Unknown - SQLite
- UPDATES:
- - Added /deleteveh command which allows you to delete the vehicle from the server.
- - Now you can get the name of the car by the ID /vehname.
- - Some minor changes throughout the script.
- */
- #define FILTERSCRIPT
- #include <a_samp>
- #include <zcmd>
- #include <sscanf2>
- #undef MAX_VEHICLES
- #define MAX_VEHICLES 200 // Put the desired amount of vehicles you want in game.
- #define USER_DB "example.db" // Put your exisiting SQLite Database
- #define MAX_INI_ENTRY_TEXT 80
- #define COLOR_GREY 0xCCCCCCFF
- #define COLOR_WHITE 0xFFFFFFFF
- #define COLOR_ORANGE 0xFF8800FF
- //NEWs
- new DB:Users;
- new query[256];
- new str[128];
- new data[128];
- new Vehicle[MAX_VEHICLES];
- public OnFilterScriptInit()
- {
- Users = db_open(USER_DB);
- print("==========================================================");
- print("==========================================================");
- print("==== SA-MP Dynamic Server Car Saving System - SQLite =====");
- print("=========== Developed by Tayab Soomro ===================");
- print("==========================================================");
- LoadCars(); // Loading cars, will work on it in a second.
- format(query,sizeof(query),"CREATE TABLE IF NOT EXISTS `cars` (id INTEGER PRIMARY KEY, name, modelid, carx, cary, carz, caranlge)");
- // Creates the table cars if it doesn't exist.
- db_query(Users,query);
- // Run the above query
- return 1;
- }
- public OnFilterScriptExit()
- {
- print("==========================================================");
- print("==========================================================");
- print("==== SA-MP Dynamic Server Car Saving System - SQLite =====");
- print("=========== Developed by Tayab Soomro ===================");
- print("==========================================================");
- for(new i = 0 ; i < MAX_VEHICLES; i++)
- DestroyVehicle(Vehicle[i]); // Destory all the vehicles.
- return 1;
- }
- CMD:saveveh(playerid,params[])
- {
- new Float:Pos[4];
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_GREY,"You're not autorized to use this command.");
- if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,COLOR_GREY,"This is a vehicle command.");
- new vID = GetPlayerVehicleID(playerid);
- GetVehiclePos(vID,Pos[0],Pos[1],Pos[2]);
- GetVehicleZAngle(vID,Pos[3]);
- new vModel = GetVehicleModel(vID);
- format(query,sizeof(query),"INSERT INTO `cars` (name,modelid,carx,cary,carz,carzangle) VALUES ('%s','%d','%f','%f','%f','%f')",GetVehicleName(vID),vModel,Pos[0],Pos[1],Pos[2],Pos[3]);
- db_query(Users,query);
- GameTextForPlayer(playerid,"~g~Adding Car",2000,3);
- LoadCars();
- SetTimer("Success",2000,false);
- return 1;
- }
- CMD:deleteveh(playerid,params[])
- {
- new id,DBResult:Result;
- if(sscanf(params,"d",id)) return SendClientMessage(playerid,COLOR_WHITE,"USAGE: /deleteveh [id]");
- format(query,sizeof(query),"SELECT `id` FROM `cars` WHERE `id` = '%d'",id);
- Result = db_query(Users,query);
- new rows = db_num_rows(Result);
- if(!rows) return SendClientMessage(playerid,COLOR_GREY,"No results found in database with that ID.");
- format(query,sizeof(query),"DELETE * FROM `cars` WHERE `id` = '%d'",id);
- db_query(Users,query);
- format(str,sizeof(str),"You've successfully deleted vehicle ID: %d",id);
- SendClientMessage(playerid,COLOR_ORANGE,str);
- for(new v = 0; v < MAX_VEHICLES; v++)
- SetVehicleToRespawn(v);
- return 1;
- }
- CMD:vehname(playerid,params[])
- {
- new id,DBResult:Result[2];
- if(sscanf(params,"d",id)) return SendClientMessage(playerid,COLOR_WHITE,"USAGE: /vehname [id]");
- format(query,sizeof(query),"SELECT `id` FROM `cars` WHERE `id` = '%d'",id);
- Result[0] = db_query(Users,query);
- new rows = db_num_rows(Result[0]);
- if(!rows) return print("Invalid vehicle ID in the stock GetVehicleNameByID");
- format(query,sizeof(query),"SELECT `name` FROM `cars` WHERE `id` = '%d'",id);
- Result[1] = db_query(Users,query);
- if(db_num_rows(Result[1]))
- {
- db_get_field(Result[1],0,data,sizeof(data));
- format(str,sizeof(str),"The vehicle name of ID: %d is {FFFFFF}%s",id,data);
- }
- SendClientMessage(playerid,COLOR_WHITE,str);
- return 1;
- }
- stock LoadCars() // A stock which loads the all the cars from the database to the server.
- {
- new id = 1;
- new DBResult: result;
- while(id < MAX_VEHICLES)
- {
- new modelid,Float:carx,Float:cary,Float:carz,Float:carzangle;
- format(query,sizeof(query),"SELECT * FROM `cars` WHERE `id` = '%d'",id);
- result = db_query(Users,query);
- if(db_num_rows(result))
- {
- db_get_field_assoc(result, "modelid",data,sizeof(data)); modelid = strval(data);
- db_get_field_assoc(result, "carx",data,sizeof(data)); carx = floatstr(data);
- db_get_field_assoc(result, "cary",data,sizeof(data)); cary = floatstr(data);
- db_get_field_assoc(result, "carz",data,sizeof(data)); carz = floatstr(data);
- db_get_field_assoc(result, "carzangle",data,sizeof(data)); carzangle = floatstr(data);
- Vehicle[id] = CreateVehicle(modelid,carx,cary,carz,carzangle,random(225),random(225),60);
- }
- db_free_result(result);
- id++;
- }
- return 1;
- }
- new VehicleNames[][] =
- {
- "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", "Boxville", "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", "Stratium",
- "Elegy", "Raindance", "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"
- };
- stock GetVehicleName(vehicleid) // Gets the vehicle name by it's ID
- {
- format(str,sizeof(str),"%s",VehicleNames[GetVehicleModel(vehicleid) - 400]);
- return str;
- }
- stock DB_Escape(text[])
- {
- new
- ret[MAX_INI_ENTRY_TEXT * 2],
- ch,
- i,
- j;
- while ((ch = text[i++]) && j < sizeof (ret))
- {
- if (ch == '\'')
- {
- if (j < sizeof (ret) - 2)
- {
- ret[j++] = '\'';
- ret[j++] = '\'';
- }
- }
- else if (j < sizeof (ret))
- {
- ret[j++] = ch;
- }
- else
- {
- j++;
- }
- }
- ret[sizeof (ret) - 1] = '\0';
- return ret;
- }
- forward Success();
- public Success()
- {
- for(new i = 0; i < MAX_PLAYERS; i++)
- {
- format(str,sizeof(str),"You've successfully added the vehicle!");
- SendClientMessage(i,COLOR_ORANGE,str);
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment