NealPeteros

Rental System v1.0

Dec 12th, 2017
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 30.00 KB | None | 0 0
  1. #include <a_samp>
  2. #include <SII>
  3. #include <zcmd>
  4.  
  5. #define COLOR_WHITE         0xFFFFFFFF
  6. #define COLOR_GREY          0xAFAFAFFF
  7. #define COLOR_YELLOW        0xFFFF00FF
  8. #define COLOR_LIGHTBLUE     0x33CCFFFF
  9. #define COLOR_ORANGE        0xFF8300FF
  10.  
  11. #define MAX_RENTALS     10
  12. #define MAX_RENTABLE_CARS 2
  13.  
  14. enum rEnum
  15. {
  16.     rName[32],
  17.     rOwner[24],
  18.     rPrice,
  19.     rId,
  20.     rOwned,
  21.     Text3D:rLabel,
  22.     Float:rPos_x,
  23.     Float:rPos_y,
  24.     Float:rPos_z,
  25.     Float:rRadius,
  26.     rProfit
  27. };
  28.  
  29. enum vEnum
  30. {
  31.     vRental,
  32.     vModel,
  33.     vPrice,
  34.     Float:vPos[5],
  35.     Text3D:vLabel,
  36.     vOnRent
  37. };
  38.  
  39. new VehicleInfo[MAX_VEHICLES][vEnum];
  40. new RentalInfo[MAX_RENTALS][rEnum];
  41.  
  42. new bool:rentOwned[MAX_RENTALS];
  43.  
  44. new owner[MAX_VEHICLES][MAX_PLAYER_NAME];
  45.  
  46. new rentingvehicle[MAX_PLAYERS];
  47.  
  48. forward CheckCarAmount();
  49. forward OnCarStreamIn();
  50.  
  51. new vehName[][] =
  52. {
  53.     "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "Sentinel", "Dumper", "Firetruck", "Trashmaster",
  54.     "Stretch", "Manana", "Infernus", "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam",
  55.     "Esperanto", "Taxi", "Washington", "Bobcat", "Whoopee", "BF Injection", "Hunter", "Premier", "Enforcer",
  56.     "Securicar", "Banshee", "Predator", "Bus", "Rhino", "Barracks", "Hotknife", "Trailer", "Previon", "Coach",
  57.     "Cabbie", "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral", "Squalo", "Seasparrow",
  58.     "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder", "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy", "Solair",
  59.     "Berkley's RC Van", "Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale", "Oceanic",
  60.     "Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy", "Hermes", "Sabre", "Rustler", "ZR-350", "Walton",
  61.     "Regina", "Comet", "BMX", "Burrito", "Camper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper", "Rancher",
  62.     "FBI Rancher", "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking", "Blista Compact", "Police Maverick",
  63.     "Boxville", "Benson", "Mesa", "RC Goblin", "Hotring Racer A", "Hotring Racer B", "Bloodring Banger", "Rancher",
  64.     "Super GT", "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropduster", "Stunt", "Tanker", "Roadtrain",
  65.     "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra", "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck",
  66.     "Fortune", "Cadrona", "SWAT Truck", "Willard", "Forklift", "Tractor", "Combine", "Feltzer", "Remington", "Slamvan",
  67.     "Blade", "Streak", "Freight", "Vortex", "Vincent", "Bullet", "Clover", "Sadler", "Firetruck", "Hustler", "Intruder",
  68.     "Primo", "Cargobob", "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite", "Windsor", "Monster", "Monster",
  69.     "Uranus", "Jester", "Sultan", "Stratium", "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna", "Bandito",
  70.     "Freight Flat", "Streak Carriage", "Kart", "Mower", "Dune", "Sweeper", "Broadway", "Tornado", "AT-400", "DFT-30",
  71.     "Huntley", "Stafford", "BF-400", "News Van", "Tug", "Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club",
  72.     "Freight Box", "Trailer", "Andromada", "Dodo", "RC Cam", "Launch", "LSPD Car", "SFPD Car", "LVPD Car",
  73.     "Police Rancher", "Picador", "S.W.A.T", "Alpha", "Phoenix", "Glendale", "Sadler", "Luggage", "Luggage", "Stairs",
  74.     "Boxville", "Tiller", "Utility Trailer"
  75. };
  76.  
  77. stock frename(oldname[], newname[])
  78. {
  79.     if(!fexist(oldname)) return 0;
  80.     new string[255], File:oldfile, File:newfile;
  81.     oldfile = fopen(oldname, io_read);
  82.     newfile = fopen(newname, io_write);
  83.     while(fread(oldfile, string))
  84.     {
  85.         format(string,sizeof(string), "%s", string);
  86.         fwrite(newfile, string);
  87.     }
  88.     fclose(oldfile);
  89.     fclose(newfile);
  90.     fremove(oldname);
  91.     return 1;
  92. }
  93.  
  94.  
  95. stock CheckForFile(file[])
  96. {
  97.     if(!fexist(file)) return printf("WARNING: Missing %s in scriptfiles folder.\nYour server may NOT function properly without the file.\n", file);
  98.     return 1;
  99. }
  100.  
  101. public OnFilterScriptInit()
  102. {
  103.     CheckForFile("rentals/vehicles/");
  104.     SetTimer("OnCarStreamIn", 200, true);
  105.     LoadRentals();
  106.     LoadRentalCars();
  107.     return 1;
  108. }
  109.  
  110. public OnFilterScriptExit()
  111. {
  112.     for(new i = 1; i < MAX_RENTALS; i++)
  113.     {
  114.         if(rentOwned[i] == true)
  115.         {
  116.             SaveRental(i);
  117.             for(new v = 1; v < MAX_VEHICLES; v++)
  118.             {
  119.                 if(VehicleInfo[v][vRental] == i)
  120.                 {
  121.                     VehicleInfo[v][vRental] = 0;
  122.                     VehicleInfo[v][vModel] = 0;
  123.                     VehicleInfo[v][vPrice] = 0;
  124.                     VehicleInfo[v][vPos][1] = 0.0;
  125.                     VehicleInfo[v][vPos][2] = 0.0;
  126.                     VehicleInfo[v][vPos][3] = 0.0;
  127.                     VehicleInfo[v][vPos][4] = 0.0;
  128.                     VehicleInfo[v][vOnRent] = 0;
  129.                     Delete3DTextLabel(VehicleInfo[v][vLabel]);
  130.                     DestroyVehicle(v);
  131.                 }
  132.             }
  133.             strmid(RentalInfo[i][rName], "None", 0, strlen("None"), 255);
  134.             strmid(RentalInfo[i][rOwner], "No-one", 0, strlen("No-one"), 255);
  135.             RentalInfo[i][rPrice] = 0;
  136.             RentalInfo[i][rOwned] = 0;
  137.             RentalInfo[i][rPos_x] = 0.0;
  138.             RentalInfo[i][rPos_y] = 0.0;
  139.             RentalInfo[i][rPos_z] = 0.0;
  140.             RentalInfo[i][rRadius] = 0.0;
  141.             RentalInfo[i][rProfit] = 0;
  142.             rentOwned[i] = false;
  143.             Delete3DTextLabel(RentalInfo[i][rLabel]);
  144.             DestroyPickup(RentalInfo[i][rId]);
  145.         }
  146.     }
  147.     return 1;
  148. }
  149.  
  150. public OnPlayerSpawn(playerid)
  151. {
  152.     new
  153.         playername[24];
  154.  
  155.     GetPlayerName(playerid, playername, sizeof(playername));
  156.  
  157.     if(strcmp(RentalInfo[GetPVarInt(playerid, "HasRental")][rOwner], playername, true) == 0) { }
  158.     else { SetPVarInt(playerid, "HasRental", 0); }
  159.     return 1;
  160. }
  161.  
  162. public OnPlayerDisconnect(playerid)
  163. {
  164.     return 1;
  165. }
  166.  
  167. stock LoadRentalCars()
  168. {
  169.     new
  170.         file[100],
  171.         file2[100],
  172.         string[128],
  173.         vehicle;
  174.  
  175.     for(new i = 1; i < MAX_VEHICLES; i++)
  176.     {
  177.         format(file, sizeof(file), "rentals/vehicles/%d.cfg", i);
  178.         if(!fexist(file)) continue;
  179.         if(fexist(file) && INI_Open(file))
  180.         {
  181.             if(GetVehicleModel(i) > 399)
  182.             {
  183.                 for (new v = 1; v < MAX_VEHICLES; v ++)
  184.                 {
  185.                     if (GetVehicleModel(v) == 0)
  186.                     {
  187.                         i = v;
  188.                         break;
  189.                     }
  190.                 }
  191.                 format(file2, sizeof(file2), "rentals/vehicles/%d.cfg", i);
  192.                 frename(file, file2);
  193.             }
  194.            
  195.             VehicleInfo[i][vRental] = INI_ReadInt("vRental");
  196.             VehicleInfo[i][vModel] = INI_ReadInt("vModel");
  197.             VehicleInfo[i][vPrice] = INI_ReadInt("vPrice");
  198.             VehicleInfo[i][vPos][1] = INI_ReadFloat("vehicle_x");
  199.             VehicleInfo[i][vPos][2] = INI_ReadFloat("vehicle_y");
  200.             VehicleInfo[i][vPos][3] = INI_ReadFloat("vehicle_z");
  201.             VehicleInfo[i][vPos][4] = INI_ReadFloat("vehicle_angle");
  202.             VehicleInfo[i][vOnRent] = INI_ReadInt("vOnRent");
  203.             vehicle = CreateVehicle(VehicleInfo[i][vModel], VehicleInfo[i][vPos][1], VehicleInfo[i][vPos][2], VehicleInfo[i][vPos][3], VehicleInfo[i][vPos][4], 0, 0, -1);
  204.             format(string, sizeof(string), "%s For Rent - Price: $%d", GetVehicleName(vehicle), VehicleInfo[i][vPrice]);
  205.             VehicleInfo[i][vLabel] = Create3DTextLabel(string, COLOR_ORANGE, VehicleInfo[i][vPos][1], VehicleInfo[i][vPos][2], VehicleInfo[i][vPos][3], 10.0, 0);
  206.             INI_Close();
  207.         }
  208.     }
  209.     return 1;
  210. }
  211.  
  212. stock LoadRentals()
  213. {
  214.     new file[100], string[256], name[32], ownr[24];
  215.     for(new i = 1; i < MAX_RENTALS; i++)
  216.     {
  217.         format(file, sizeof(file), "rentals/%d.cfg", i);
  218.         if(fexist(file) && INI_Open(file))
  219.         {
  220.             INI_ReadString(name, "rName");
  221.             INI_ReadString(ownr, "rOwner");
  222.             strmid(RentalInfo[i][rName], name, 0, strlen(name), 255);
  223.             strmid(RentalInfo[i][rOwner], ownr, 0, strlen(ownr), 255);
  224.             RentalInfo[i][rPrice] = INI_ReadInt("rPrice");
  225.             RentalInfo[i][rOwned] = INI_ReadInt("rOwned");
  226.             RentalInfo[i][rPos_x] = INI_ReadFloat("rPos_x");
  227.             RentalInfo[i][rPos_y] = INI_ReadFloat("rPos_y");
  228.             RentalInfo[i][rPos_z] = INI_ReadFloat("rPos_z");
  229.             RentalInfo[i][rRadius] = INI_ReadFloat("rRadius");
  230.             RentalInfo[i][rProfit] = INI_ReadInt("rProfit");
  231.             switch(RentalInfo[i][rOwned])
  232.             {
  233.                 case 0: { format(string, sizeof(string), "{FF6347}%s{FFFFFF} is for sale!\n\n{FF6347}Price:{FFFFFF} $%d\n\nTo purchase this rental, type /buyrent.", RentalInfo[i][rName], RentalInfo[i][rPrice]); }
  234.                 case 1: { format(string, sizeof(string), "{FF6347}%s{FFFFFF}\n\n{FF6347}Owner:{FFFFFF} %s", RentalInfo[i][rName], RentalInfo[i][rOwner]); }
  235.             }
  236.             RentalInfo[i][rLabel] = Create3DTextLabel(string, COLOR_WHITE, RentalInfo[i][rPos_x], RentalInfo[i][rPos_y], RentalInfo[i][rPos_z], 10.0, 0);
  237.             CreatePickup(1274, 23, RentalInfo[i][rPos_x], RentalInfo[i][rPos_y], RentalInfo[i][rPos_z]);
  238.             rentOwned[i] = true;
  239.             INI_Close();
  240.         }
  241.     }
  242.     return 1;
  243. }
  244.  
  245. stock SaveRental(rentalid)
  246. {
  247.     new file[100];
  248.     if(rentOwned[rentalid] == true)
  249.     {
  250.         format(file, sizeof(file), "rentals/%d.cfg", rentalid);
  251.         if(INI_Open(file))
  252.         {
  253.             INI_WriteString("rName", RentalInfo[rentalid][rName]);
  254.             INI_WriteString("rOwner", RentalInfo[rentalid][rOwner]);
  255.             INI_WriteInt("rPrice", RentalInfo[rentalid][rPrice]);
  256.             INI_WriteInt("rOwned", RentalInfo[rentalid][rOwned]);
  257.             INI_WriteFloat("rPos_x", RentalInfo[rentalid][rPos_x]);
  258.             INI_WriteFloat("rPos_y", RentalInfo[rentalid][rPos_y]);
  259.             INI_WriteFloat("rPos_z", RentalInfo[rentalid][rPos_z]);
  260.             INI_WriteFloat("rRadius", RentalInfo[rentalid][rRadius]);
  261.             INI_WriteInt("rProfit", RentalInfo[rentalid][rProfit]);
  262.  
  263.             INI_Save();
  264.             INI_Close();
  265.         }
  266.     }
  267.     for(new i = 1; i < MAX_VEHICLES; i++)
  268.     {
  269.         if(VehicleInfo[i][vRental] == rentalid)
  270.         {
  271.             format(file, sizeof(file), "rentals/vehicles/%d.cfg", i);
  272.             if(INI_Open(file))
  273.             {
  274.                 INI_WriteInt("vRental", VehicleInfo[i][vRental]);
  275.                 INI_WriteInt("vModel", VehicleInfo[i][vModel]);
  276.                 INI_WriteInt("vPrice", VehicleInfo[i][vPrice]);
  277.                 INI_WriteFloat("vehicle_x", VehicleInfo[i][vPos][1]);
  278.                 INI_WriteFloat("vehicle_y", VehicleInfo[i][vPos][2]);
  279.                 INI_WriteFloat("vehicle_z", VehicleInfo[i][vPos][3]);
  280.                 INI_WriteFloat("vehicle_angle", VehicleInfo[i][vPos][4]);
  281.                 INI_WriteInt("vOnRent", VehicleInfo[i][vOnRent]);
  282.  
  283.                 INI_Save();
  284.                 INI_Close();
  285.             }
  286.         }
  287.     }
  288.     return 1;
  289. }
  290.  
  291. CMD:rentalhelp(playerid, params[])
  292. {
  293.     SendClientMessage(playerid, COLOR_ORANGE, "=====Player Commands=====");
  294.     SendClientMessage(playerid, -1, "/av - Accept to rent a vehicle");
  295.     SendClientMessage(playerid, -1, "/dv - Decline to rent a vehicle");
  296.  
  297.     SendClientMessage(playerid, COLOR_ORANGE, "=====Administrator Commands=====")
  298.     SendClientMessage(playerid, -1, "/createrental - Create a rental place");
  299.     SendClientMessage(playerid, -1, "/destroyrental - Destroy a rental place");
  300.  
  301.     SendClientMessage(playerid, COLOR_ORANGE, "=====Owner Commands=====");
  302.     SendClientMessage(playerid, -1, "/buyrental - Buys a nearby rental place");
  303.     SendClientMessage(playerid, -1, "/createcar - Creates a rental care");
  304.     SendClientMessage(playerid, -1, "/profit - View your earnings");
  305.     SendClientMessage(playerid, -1, "/collectearnings - Collect your earnings");
  306.     SendClientMessage(playerid, -1, "/selldealership - Sells your owned dealership");
  307.     return 1;
  308. }
  309.  
  310. CMD:av(playerid, params[])
  311. {
  312.     if(rentingvehicle[playerid] == 1)
  313.     {
  314.         new
  315.             vehicleid = GetPlayerVehicleID(playerid),
  316.             model = GetVehicleModel(vehicleid),
  317.             price = VehicleInfo[vehicleid][vPrice],
  318.             Float:position[5],
  319.             string[128],
  320.             rentalid = -1,
  321.             var[32],
  322.             playername[24];
  323.  
  324.         GetPlayerName(playerid, playername, sizeof(playername));
  325.         GetPlayerPos(playerid, position[1], position[2], position[3]);
  326.         GetPlayerFacingAngle(playerid, position[4]);
  327.  
  328.         if(GetPVarInt(playerid, "AmountOfCars") >= MAX_RENTABLE_CARS) return SendClientMessage(playerid, COLOR_GREY, "  You have already rented the maximum amount of vehicles !"), RemovePlayerFromVehicle(playerid)TogglePlayerControllable(playerid, 1);  rentingvehicle[playerid] = 0;
  329.  
  330.         if(GetPlayerMoney(playerid) < price) return SendClientMessage(playerid, COLOR_GREY, "   You can't afford that !"), RemovePlayerFromVehicle(playerid); TogglePlayerControllable(playerid, 1); rentingvehicle[playerid] = 0;
  331.  
  332.         for(new i = 1; i < MAX_RENTALS; i++)
  333.         {
  334.             if(IsPlayerInRangeOfPoint(playerid, RentalInfo[i][rRadius], RentalInfo[i][rPos_x], RentalInfo[i][rPos_y], RentalInfo[i][rPos_z]))
  335.             {
  336.                 rentalid = i;
  337.                 break;
  338.             }
  339.         }
  340.  
  341.         RentalInfo[rentalid][rProfit] += price;
  342.  
  343.         GivePlayerMoney(playerid, -price);
  344.  
  345.         RemovePlayerFromVehicle(playerid);
  346.         vehicleid = CreateVehicle(model, (position[1] + (7.5 * floatsin(-position[4], degrees))), (position[2] + (7.5 * floatcos(position[4], degrees))), position[3], position[4], 0, 0, -1);
  347.         format(string, sizeof(string), "[CASHIER:] Thank you for renting at %s, we hope to see you again!", RentalInfo[rentalid][rName]);
  348.         SendClientMessage(playerid, COLOR_WHITE, string);
  349.         SendClientMessage(playerid, COLOR_WHITE, "Your vehicle has been spawned in front of you.");
  350.  
  351.         SetPVarInt(playerid, "AmountOfCars", GetPVarInt(playerid, "AmountOfCars") + 1);
  352.  
  353.         format(var, sizeof(var), "Model_%d", GetPVarInt(playerid, "AmountOfCars"));
  354.         SetPVarInt(playerid, var, model);
  355.  
  356.         format(var, sizeof(var), "X_%d", GetPVarInt(playerid, "AmountOfCars"));
  357.         SetPVarFloat(playerid, var, (position[1] + (7.5 * floatsin(-position[4], degrees))));
  358.  
  359.         format(var, sizeof(var), "Y_%d", GetPVarInt(playerid, "AmountOfCars"));
  360.         SetPVarFloat(playerid, var, (position[2] + (7.5 * floatcos(position[4], degrees))));
  361.  
  362.         format(var, sizeof(var), "Z_%d", GetPVarInt(playerid, "AmountOfCars"));
  363.         SetPVarFloat(playerid, var, position[3]);
  364.  
  365.         format(var, sizeof(var), "Angle_%d", GetPVarInt(playerid, "AmountOfCars"));
  366.         SetPVarFloat(playerid, var, position[4]);
  367.  
  368.         format(var, sizeof(var), "Carkey_%d", GetPVarInt(playerid, "AmountOfCars"));
  369.         SetPVarInt(playerid, var, vehicleid);
  370.  
  371.         format(var, sizeof(var), "Paintjob_%d", GetPVarInt(playerid, "AmountOfCars"));
  372.         SetPVarInt(playerid, var, -1);
  373.  
  374.         strmid(owner[vehicleid], playername, 0, strlen(playername), 255);
  375.         TogglePlayerControllable(playerid, 1);
  376.         rentingvehicle[playerid] = 0;
  377.     }
  378.     return 1;
  379. }
  380.  
  381. CMD:dv(playerid, params[])
  382. {
  383.     if(rentingvehicle[playerid] == 1)
  384.     {
  385.         new string[180], veh, rentalid;
  386.         rentalid = -1;
  387.         veh = GetPlayerVehicleID(playerid);
  388.         for(new i = 1; i < MAX_RENTALS; i++)
  389.         {
  390.             if(IsPlayerInRangeOfPoint(playerid, RentalInfo[i][rRadius], RentalInfo[i][rPos_x], RentalInfo[i][rPos_y], RentalInfo[i][rPos_z]))
  391.             {
  392.                 rentalid = i;
  393.                 break;
  394.             }
  395.         }
  396.         format(string, sizeof(string), "You have declined renting a/an %s in %s", GetVehicleName(veh), RentalInfo[rentalid][rName]);
  397.         SendClientMessage(playerid, COLOR_GREY, string);
  398.         RemovePlayerFromVehicle(playerid);
  399.         TogglePlayerControllable(playerid, 1);
  400.         rentingvehicle[playerid] = 0;
  401.     }
  402.     return 1;
  403. }
  404.  
  405. CMD:createrental(playerid, params[])
  406. {
  407.     new
  408.         price,
  409.         rentalname[32],
  410.         Float:radius,
  411.         rentalid = -1,
  412.         bool:assigned = false,
  413.         string[256],
  414.         Float:x,
  415.         Float:y,
  416.         Float:z;
  417.  
  418.     GetPlayerPos(playerid, x, y, z);
  419.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GREY, "    You are not authorized to use this command !");
  420.  
  421.     if(sscanf(params, "dfs", price, radius, rentalname))
  422.         return SendClientMessage(playerid, COLOR_WHITE, "* [Usage]: /createrental [price] [radius] [name of rental]");
  423.  
  424.     for(new i = 1; i < MAX_RENTALS; i++)
  425.     {
  426.         if(rentOwned[i] == false)
  427.         {
  428.             rentalid = i;
  429.             assigned = true;
  430.             break;
  431.         }
  432.     }
  433.     if(assigned == false) return SendClientMessage(playerid, COLOR_GREY, "    Something went wrong while creating the rental !");
  434.     strmid(RentalInfo[rentalid][rName], rentalname, 0, strlen(rentalname), 255);
  435.     strmid(RentalInfo[rentalid][rOwner], "No-one", 0, strlen("No-one"), 255);
  436.     RentalInfo[rentalid][rPrice] = price;
  437.     RentalInfo[rentalid][rOwned] = 0;
  438.     RentalInfo[rentalid][rPos_x] = x;
  439.     RentalInfo[rentalid][rPos_y] = y;
  440.     RentalInfo[rentalid][rPos_z] = z;
  441.     RentalInfo[rentalid][rRadius] = radius;
  442.     RentalInfo[rentalid][rId] = CreatePickup(1274, 23, x, y, z);
  443.     format(string, sizeof(string), "{FF6347}%s{FFFFFF} is for sale!\n\n{FF6347}Price:{FFFFFF} $%d\n\nTo purchase this rental, type /buyrental.", rentalname, price);
  444.     RentalInfo[rentalid][rLabel] = Create3DTextLabel(string, COLOR_WHITE, x, y, z, 10.0, 0);
  445.     format(string, sizeof(string), " Rental %d created.", rentalid);
  446.     SendClientMessage(playerid, COLOR_GREY, string);
  447.     rentOwned[rentalid] = true;
  448.     SaveRental(rentalid);
  449.     return 1;
  450. }
  451.  
  452. CMD:destroyrental(playerid, params[])
  453. {
  454.     new
  455.         id,
  456.         file[100];
  457.  
  458.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GREY, "    You are not authorized to use this command !");
  459.     if(sscanf(params, "d", id))
  460.         return SendClientMessage(playerid, COLOR_WHITE, "* [Usage]: /destroyrental [rentalid]");
  461.  
  462.     if(id < 1 || id > MAX_RENTALS) return SendClientMessage(playerid, COLOR_GREY, "    Invalid rental ID !");
  463.     if(rentOwned[id] == true)
  464.     {
  465.         format(file, sizeof(file), "rentals/%d.cfg", id);
  466.         if(fexist(file)) { fremove(file); }
  467.         for(new i = 1; i < MAX_VEHICLES; i++)
  468.         {
  469.             if(VehicleInfo[i][vRental] == id)
  470.             {
  471.                 format(file, sizeof(file), "rentals/vehicles/%d.cfg", i);
  472.                 if(fexist(file)) { fremove(file); }
  473.                 VehicleInfo[i][vRental] = 0;
  474.                 VehicleInfo[i][vModel] = 0;
  475.                 VehicleInfo[i][vPrice] = 0;
  476.                 VehicleInfo[i][vPos][1] = 0.0;
  477.                 VehicleInfo[i][vPos][2] = 0.0;
  478.                 VehicleInfo[i][vPos][3] = 0.0;
  479.                 VehicleInfo[i][vPos][4] = 0.0;
  480.                 VehicleInfo[i][vOnRent] = 0;
  481.                 Delete3DTextLabel(VehicleInfo[i][vLabel]);
  482.                 DestroyVehicle(i);
  483.             }
  484.         }
  485.         strmid(RentalInfo[id][rName], "None", 0, strlen("None"), 255);
  486.         strmid(RentalInfo[id][rOwner], "No-one", 0, strlen("No-one"), 255);
  487.         RentalInfo[id][rPrice] = 0;
  488.         RentalInfo[id][rOwned] = 0;
  489.         RentalInfo[id][rPos_x] = 0.0;
  490.         RentalInfo[id][rPos_y] = 0.0;
  491.         RentalInfo[id][rPos_z] = 0.0;
  492.         RentalInfo[id][rRadius] = 0.0;
  493.         RentalInfo[id][rProfit] = 0;
  494.         rentOwned[id] = false;
  495.         Delete3DTextLabel(RentalInfo[id][rLabel]);
  496.         DestroyPickup(RentalInfo[id][rId]);
  497.         return 1;
  498.     }
  499.     else { SendClientMessage(playerid, COLOR_GREY, "    Rental ID not found !"); }
  500.     return 1;
  501. }
  502.  
  503. CMD:buyrental(playerid, params[])
  504. {
  505.     params[0] = 0;
  506.     new
  507.         rentalid = -1,
  508.         string[256],
  509.         playername[24],
  510.         bool:isnear = false;
  511.  
  512.     GetPlayerName(playerid, playername, sizeof(playername));
  513.     if(GetPVarInt(playerid, "HasRental") != 0) return SendClientMessage(playerid, COLOR_GREY, "    You already have a rental !");
  514.     for(new i = 1; i < MAX_RENTALS; i++)
  515.     {
  516.         if(IsPlayerInRangeOfPoint(playerid, 2.0, RentalInfo[i][rPos_x], RentalInfo[i][rPos_y], RentalInfo[i][rPos_z]))
  517.         {
  518.             rentalid = i;
  519.             isnear = true;
  520.             break;
  521.         }
  522.     }
  523.     if(isnear == false) return SendClientMessage(playerid, COLOR_GREY, "    You are not near a rental!");
  524.     if(RentalInfo[rentalid][rOwned] == 0)
  525.     {
  526.         if(GetPlayerMoney(playerid) >= RentalInfo[rentalid][rPrice])
  527.         {
  528.             format(string, sizeof(string), "{FF6347}%s{FFFFFF}\n\n{FF6347}Owner:{FFFFFF} %s", RentalInfo[rentalid][rName], playername);
  529.             Delete3DTextLabel(RentalInfo[rentalid][rLabel]);
  530.             RentalInfo[rentalid][rLabel] = Create3DTextLabel(string, COLOR_WHITE, RentalInfo[rentalid][rPos_x], RentalInfo[rentalid][rPos_y], RentalInfo[rentalid][rPos_z], 10.0, 0);
  531.             RentalInfo[rentalid][rOwned] = 1;
  532.             strmid(RentalInfo[rentalid][rOwner], playername, 0, strlen(playername), 255);
  533.             GivePlayerMoney(playerid, -RentalInfo[rentalid][rPrice]);
  534.             format(string, sizeof(string), "Congratulations, you've purchased %s for $%d, for a list of new commands, type /rentalhelp.", RentalInfo[rentalid][rName], RentalInfo[rentalid][rPrice]);
  535.             SendClientMessage(playerid, COLOR_YELLOW, string);
  536.             SetPVarInt(playerid, "HasRental", rentalid);
  537.             SaveRental(rentalid);
  538.             return 1;
  539.         }
  540.         else return SendClientMessage(playerid, COLOR_GREY, "   You can't afford this !");
  541.     }
  542.     else { SendClientMessage(playerid, COLOR_GREY, "    This rental is already owned !"); }
  543.     return 1;
  544. }
  545.  
  546. CMD:createcar(playerid, params[])
  547. {
  548.     new
  549.         model,
  550.         price,
  551.         rentalid = GetPVarInt(playerid, "HasRental");
  552.  
  553.     if(GetPVarInt(playerid, "HasRental") != 0)
  554.     {
  555.         if(!IsPlayerInRangeOfPoint(playerid, RentalInfo[rentalid][rRadius], RentalInfo[rentalid][rPos_x], RentalInfo[rentalid][rPos_y], RentalInfo[rentalid][rPos_z]))
  556.             return SendClientMessage(playerid, COLOR_GREY, "    You are not near your rental !");
  557.  
  558.         new Float:x, Float:y, Float:z, Float:angle;
  559.         GetPlayerPos(playerid, x, y, z); GetPlayerFacingAngle(playerid, angle);
  560.         if(sscanf(params, "dd", model, price)) return SendClientMessage(playerid, COLOR_WHITE, "* [Usage]: /createcar [model] [price]");
  561.         CreateRentalVehicle(playerid, model, price, x, y, z, angle);
  562.         return 1;
  563.     }
  564.     else { SendClientMessage(playerid, COLOR_GREY, "    You don't own a rental !"); }
  565.     return 1;
  566. }
  567.  
  568. CMD:profit(playerid, params[])
  569. {
  570.     params[0] = 0;
  571.  
  572.     new
  573.         rentalid = GetPVarInt(playerid, "HasRental"),
  574.         string[64];
  575.        
  576.     if(GetPVarInt(playerid, "HasRental") != 0)
  577.     {
  578.         format(string, sizeof(string), "{FF8300}Profit:{FFFFFF} $%d", RentalInfo[rentalid][rProfit]);
  579.         SendClientMessage(playerid, COLOR_WHITE, string);
  580.         return 1;
  581.     }
  582.     else { SendClientMessage(playerid, COLOR_GREY, "    You don't own a rental !"); }
  583.     return 1;
  584. }
  585.  
  586. CMD:collectprofit(playerid, params[])
  587. {
  588.     params[0] = 0;
  589.     new
  590.         string[128],
  591.         rentalid = GetPVarInt(playerid, "HasRental");
  592.  
  593.     if(GetPVarInt(playerid, "HasRental") != 0)
  594.     {
  595.         if(!IsPlayerInRangeOfPoint(playerid, 2.0, RentalInfo[rentalid][rPos_x], RentalInfo[rentalid][rPos_y], RentalInfo[rentalid][rPos_z]))
  596.             return SendClientMessage(playerid, COLOR_GREY, "    You are not near your rental !");
  597.  
  598.         if(!RentalInfo[rentalid][rProfit])
  599.             return SendClientMessage(playerid, COLOR_GREY, "    You have no profit to collect !");
  600.  
  601.         format(string, sizeof(string), "* You've collected $%d from your rental's profit.", RentalInfo[rentalid][rProfit]);
  602.         SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
  603.  
  604.         GivePlayerMoney(playerid, RentalInfo[rentalid][rProfit]);
  605.         RentalInfo[rentalid][rProfit] = 0;
  606.         return 1;
  607.     }
  608.     else { SendClientMessage(playerid, COLOR_GREY, "    You don't own a rental !"); }
  609.     return 1;
  610. }
  611.  
  612. CMD:sellrental(playerid, params[])
  613. {
  614.     new
  615.         rentalid = GetPVarInt(playerid, "HasRental"),
  616.         string[128];
  617.  
  618.     if(GetPVarInt(playerid, "HasRental") != 0)
  619.     {
  620.         if(!IsPlayerInRangeOfPoint(playerid, 2.0, RentalInfo[rentalid][rPos_x], RentalInfo[rentalid][rPos_y], RentalInfo[rentalid][rPos_z]))
  621.             return SendClientMessage(playerid, COLOR_GREY, "    You are not near your rental !");
  622.            
  623.         if(!params[0])
  624.             return SendClientMessage(playerid, COLOR_WHITE, "* [Usage]: /sellrental [confirm]");
  625.        
  626.         if(strcmp(params, "confirm", true) == 0)
  627.         {
  628.             new
  629.                 price = RentalInfo[rentalid][rPrice];
  630.                
  631.             GivePlayerMoney(playerid, price);
  632.             format(string, sizeof(string), "{FF6347}%s{FFFFFF} is for sale!\n\n{FF6347}Price:{FFFFFF} $%d\n\nTo purchase this rental, type /buyrental.", RentalInfo[rentalid][rName], RentalInfo[rentalid][rPrice]);
  633.             Delete3DTextLabel(RentalInfo[rentalid][rLabel]);
  634.             RentalInfo[rentalid][rLabel] = Create3DTextLabel(string, COLOR_WHITE, RentalInfo[rentalid][rPos_x], RentalInfo[rentalid][rPos_y], RentalInfo[rentalid][rPos_z], 10.0, 0);
  635.             RentalInfo[rentalid][rOwned] = 0;
  636.             strmid(RentalInfo[rentalid][rOwner], "No-one", 0, strlen("No-one"), 255);
  637.             format(string, sizeof(string), "You've sold your rental back to the market for $%d.", RentalInfo[rentalid][rPrice]);
  638.             SendClientMessage(playerid, COLOR_YELLOW, string);
  639.             SetPVarInt(playerid, "HasRental", 0);
  640.             SaveRental(rentalid);
  641.             return 1;
  642.         }
  643.     }
  644.     else { SendClientMessage(playerid, COLOR_GREY, "    You don't own a rental !"); }
  645.     return 1;
  646. }
  647.  
  648. stock CreateRentalVehicle(creator, model, price, Float:carx, Float:cary, Float:carz, Float:carangle)
  649. {
  650.     new
  651.         vehicleid,
  652.         string[256];
  653.  
  654.     vehicleid = CreateVehicle(model, carx, cary, carz, carangle, 0, 0, -1);
  655.     if(vehicleid == INVALID_VEHICLE_ID) return SendClientMessage(creator, COLOR_GREY, "    The car couldn't be created !");
  656.     VehicleInfo[vehicleid][vRental] = GetPVarInt(creator, "HasRental");
  657.     VehicleInfo[vehicleid][vModel] = model;
  658.     VehicleInfo[vehicleid][vPrice] = price;
  659.     VehicleInfo[vehicleid][vPos][1] = carx;
  660.     VehicleInfo[vehicleid][vPos][2] = cary;
  661.     VehicleInfo[vehicleid][vPos][3] = carz;
  662.     VehicleInfo[vehicleid][vPos][4] = carangle;
  663.     VehicleInfo[vehicleid][vOnRent] = 1;
  664.     format(string, sizeof(string), "%s For Sale - Price: $%d", GetVehicleName(vehicleid), price);
  665.     VehicleInfo[vehicleid][vLabel] = Create3DTextLabel(string, COLOR_ORANGE, carx, cary, carz, 10.0, 0);
  666.     SaveRental(GetPVarInt(creator, "HasRental"));
  667.     return 1;
  668. }
  669.  
  670. public OnPlayerStateChange(playerid, newstate, oldstate)
  671. {
  672.     if(newstate == PLAYER_STATE_DRIVER)
  673.     {
  674.         new
  675.             vehicleid = GetPlayerVehicleID(playerid),
  676.             string[128];
  677.  
  678.         if(VehicleInfo[vehicleid][vOnRent] == 1)
  679.         {
  680.             rentingvehicle[playerid] = 0;
  681.             format(string, sizeof(string), "Would you like to rent this %s costing $%d (/a(ccept)v(ehicle) or /d(ecline)v(ehicle))?", GetVehicleName(vehicleid), VehicleInfo[vehicleid][vPrice]);
  682.             SendClientMessage(playerid, COLOR_GREY, string);
  683.             rentingvehicle[playerid] = 1;
  684.             TogglePlayerControllable(playerid, 0);
  685.             return 1;
  686.         }
  687.     }
  688.     return 1;
  689. }
  690.  
  691. GetVehicleName(vehicleid)
  692. {
  693.     new
  694.         vehiclename[64] = "None";
  695.        
  696.     if(!vehicleid) return vehiclename;
  697.     format(vehiclename, sizeof(vehiclename), "%s", vehName[( GetVehicleModel(vehicleid) - 400 )]);
  698.     return vehiclename;
  699. }
  700.  
  701. public OnPlayerCommandText(playerid, cmdtext[])
  702. {
  703.     return 0;
  704. }
  705.  
  706. stock sscanf(string[], format[], {Float,_}:...)
  707. {
  708.     #if defined isnull
  709.         if (isnull(string))
  710.     #else
  711.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  712.     #endif
  713.         {
  714.             return format[0];
  715.         }
  716.     #pragma tabsize 4
  717.     new
  718.         formatPos = 0,
  719.         stringPos = 0,
  720.         paramPos = 2,
  721.         paramCount = numargs(),
  722.         delim = ' ';
  723.     while (string[stringPos] && string[stringPos] <= ' ')
  724.     {
  725.         stringPos++;
  726.     }
  727.     while (paramPos < paramCount && string[stringPos])
  728.     {
  729.         switch (format[formatPos++])
  730.         {
  731.             case '\0':
  732.             {
  733.                 return 0;
  734.             }
  735.             case 'i', 'd':
  736.             {
  737.                 new
  738.                     neg = 1,
  739.                     num = 0,
  740.                     ch = string[stringPos];
  741.                 if (ch == '-')
  742.                 {
  743.                     neg = -1;
  744.                     ch = string[++stringPos];
  745.                 }
  746.                 do
  747.                 {
  748.                     stringPos++;
  749.                     if ('0' <= ch <= '9')
  750.                     {
  751.                         num = (num * 10) + (ch - '0');
  752.                     }
  753.                     else
  754.                     {
  755.                         return -1;
  756.                     }
  757.                 }
  758.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  759.                 setarg(paramPos, 0, num * neg);
  760.             }
  761.             case 'h', 'x':
  762.             {
  763.                 new
  764.                     num = 0,
  765.                     ch = string[stringPos];
  766.                 do
  767.                 {
  768.                     stringPos++;
  769.                     switch (ch)
  770.                     {
  771.                         case 'x', 'X':
  772.                         {
  773.                             num = 0;
  774.                             continue;
  775.                         }
  776.                         case '0' .. '9':
  777.                         {
  778.                             num = (num << 4) | (ch - '0');
  779.                         }
  780.                         case 'a' .. 'f':
  781.                         {
  782.                             num = (num << 4) | (ch - ('a' - 10));
  783.                         }
  784.                         case 'A' .. 'F':
  785.                         {
  786.                             num = (num << 4) | (ch - ('A' - 10));
  787.                         }
  788.                         default:
  789.                         {
  790.                             return -1;
  791.                         }
  792.                     }
  793.                 }
  794.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  795.                 setarg(paramPos, 0, num);
  796.             }
  797.             case 'c':
  798.             {
  799.                 setarg(paramPos, 0, string[stringPos++]);
  800.             }
  801.             case 'f':
  802.             {
  803.  
  804.                 new changestr[16], changepos = 0, strpos = stringPos;
  805.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  806.                 {
  807.                     changestr[changepos++] = string[strpos++];
  808.                     }
  809.                 changestr[changepos] = '\0';
  810.                 setarg(paramPos,0,_:floatstr(changestr));
  811.             }
  812.             case 'p':
  813.             {
  814.                 delim = format[formatPos++];
  815.                 continue;
  816.             }
  817.             case '\'':
  818.             {
  819.                 new
  820.                     end = formatPos - 1,
  821.                     ch;
  822.                 while ((ch = format[++end]) && ch != '\'') {}
  823.                 if (!ch)
  824.                 {
  825.                     return -1;
  826.                 }
  827.                 format[end] = '\0';
  828.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  829.                 {
  830.                     if (format[end + 1])
  831.                     {
  832.                         return -1;
  833.                     }
  834.                     return 0;
  835.                 }
  836.                 format[end] = '\'';
  837.                 stringPos = ch + (end - formatPos);
  838.                 formatPos = end + 1;
  839.             }
  840.             case 'u':
  841.             {
  842.                 new
  843.                     end = stringPos - 1,
  844.                     id = 0,
  845.                     bool:num = true,
  846.                     ch;
  847.                 while ((ch = string[++end]) && ch != delim)
  848.                 {
  849.                     if (num)
  850.                     {
  851.                         if ('0' <= ch <= '9')
  852.                         {
  853.                             id = (id * 10) + (ch - '0');
  854.                         }
  855.                         else
  856.                         {
  857.                             num = false;
  858.                         }
  859.                     }
  860.                 }
  861.                 if (num && IsPlayerConnected(id))
  862.                 {
  863.                     setarg(paramPos, 0, id);
  864.                 }
  865.                 else
  866.                 {
  867.                     #if !defined foreach
  868.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  869.                         #define __SSCANF_FOREACH__
  870.                     #endif
  871.                     string[end] = '\0';
  872.                     num = false;
  873.                     new
  874.                         name[MAX_PLAYER_NAME];
  875.                     id = end - stringPos;
  876.                     foreach (Player, playerid)
  877.                     {
  878.                         GetPlayerName(playerid, name, sizeof (name));
  879.                         if (!strcmp(name, string[stringPos], true, id))
  880.                         {
  881.                             setarg(paramPos, 0, playerid);
  882.                             num = true;
  883.                             break;
  884.                         }
  885.                     }
  886.                     if (!num)
  887.                     {
  888.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  889.                     }
  890.                     string[end] = ch;
  891.                     #if defined __SSCANF_FOREACH__
  892.                         #undef foreach
  893.                         #undef __SSCANF_FOREACH__
  894.                     #endif
  895.                 }
  896.                 stringPos = end;
  897.             }
  898.             case 's', 'z':
  899.             {
  900.                 new
  901.                     i = 0,
  902.                     ch;
  903.                 if (format[formatPos])
  904.                 {
  905.                     while ((ch = string[stringPos++]) && ch != delim)
  906.                     {
  907.                         setarg(paramPos, i++, ch);
  908.                     }
  909.                     if (!i)
  910.                     {
  911.                         return -1;
  912.                     }
  913.                 }
  914.                 else
  915.                 {
  916.                     while ((ch = string[stringPos++]))
  917.                     {
  918.                         setarg(paramPos, i++, ch);
  919.                     }
  920.                 }
  921.                 stringPos--;
  922.                 setarg(paramPos, i, '\0');
  923.             }
  924.             default:
  925.             {
  926.                 continue;
  927.             }
  928.         }
  929.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  930.         {
  931.             stringPos++;
  932.         }
  933.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  934.         {
  935.             stringPos++;
  936.         }
  937.         paramPos++;
  938.     }
  939.     do
  940.     {
  941.         if ((delim = format[formatPos++]) > ' ')
  942.         {
  943.             if (delim == '\'')
  944.             {
  945.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  946.             }
  947.             else if (delim != 'z')
  948.             {
  949.                 return delim;
  950.             }
  951.         }
  952.     }
  953.     while (delim > ' ');
  954.     return 0;
  955. }
Advertisement
Add Comment
Please, Sign In to add comment