Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <SII>
- #include <zcmd>
- #define COLOR_WHITE 0xFFFFFFFF
- #define COLOR_GREY 0xAFAFAFFF
- #define COLOR_YELLOW 0xFFFF00FF
- #define COLOR_LIGHTBLUE 0x33CCFFFF
- #define COLOR_ORANGE 0xFF8300FF
- #define MAX_RENTALS 10
- #define MAX_RENTABLE_CARS 2
- enum rEnum
- {
- rName[32],
- rOwner[24],
- rPrice,
- rId,
- rOwned,
- Text3D:rLabel,
- Float:rPos_x,
- Float:rPos_y,
- Float:rPos_z,
- Float:rRadius,
- rProfit
- };
- enum vEnum
- {
- vRental,
- vModel,
- vPrice,
- Float:vPos[5],
- Text3D:vLabel,
- vOnRent
- };
- new VehicleInfo[MAX_VEHICLES][vEnum];
- new RentalInfo[MAX_RENTALS][rEnum];
- new bool:rentOwned[MAX_RENTALS];
- new owner[MAX_VEHICLES][MAX_PLAYER_NAME];
- new rentingvehicle[MAX_PLAYERS];
- forward CheckCarAmount();
- forward OnCarStreamIn();
- new vehName[][] =
- {
- "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", "SWAT Truck", "Willard", "Forklift", "Tractor", "Combine", "Feltzer", "Remington", "Slamvan",
- "Blade", "Streak", "Freight", "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", "LSPD Car", "SFPD Car", "LVPD Car",
- "Police Rancher", "Picador", "S.W.A.T", "Alpha", "Phoenix", "Glendale", "Sadler", "Luggage", "Luggage", "Stairs",
- "Boxville", "Tiller", "Utility Trailer"
- };
- stock frename(oldname[], newname[])
- {
- if(!fexist(oldname)) return 0;
- new string[255], File:oldfile, File:newfile;
- oldfile = fopen(oldname, io_read);
- newfile = fopen(newname, io_write);
- while(fread(oldfile, string))
- {
- format(string,sizeof(string), "%s", string);
- fwrite(newfile, string);
- }
- fclose(oldfile);
- fclose(newfile);
- fremove(oldname);
- return 1;
- }
- stock CheckForFile(file[])
- {
- if(!fexist(file)) return printf("WARNING: Missing %s in scriptfiles folder.\nYour server may NOT function properly without the file.\n", file);
- return 1;
- }
- public OnFilterScriptInit()
- {
- CheckForFile("rentals/vehicles/");
- SetTimer("OnCarStreamIn", 200, true);
- LoadRentals();
- LoadRentalCars();
- return 1;
- }
- public OnFilterScriptExit()
- {
- for(new i = 1; i < MAX_RENTALS; i++)
- {
- if(rentOwned[i] == true)
- {
- SaveRental(i);
- for(new v = 1; v < MAX_VEHICLES; v++)
- {
- if(VehicleInfo[v][vRental] == i)
- {
- VehicleInfo[v][vRental] = 0;
- VehicleInfo[v][vModel] = 0;
- VehicleInfo[v][vPrice] = 0;
- VehicleInfo[v][vPos][1] = 0.0;
- VehicleInfo[v][vPos][2] = 0.0;
- VehicleInfo[v][vPos][3] = 0.0;
- VehicleInfo[v][vPos][4] = 0.0;
- VehicleInfo[v][vOnRent] = 0;
- Delete3DTextLabel(VehicleInfo[v][vLabel]);
- DestroyVehicle(v);
- }
- }
- strmid(RentalInfo[i][rName], "None", 0, strlen("None"), 255);
- strmid(RentalInfo[i][rOwner], "No-one", 0, strlen("No-one"), 255);
- RentalInfo[i][rPrice] = 0;
- RentalInfo[i][rOwned] = 0;
- RentalInfo[i][rPos_x] = 0.0;
- RentalInfo[i][rPos_y] = 0.0;
- RentalInfo[i][rPos_z] = 0.0;
- RentalInfo[i][rRadius] = 0.0;
- RentalInfo[i][rProfit] = 0;
- rentOwned[i] = false;
- Delete3DTextLabel(RentalInfo[i][rLabel]);
- DestroyPickup(RentalInfo[i][rId]);
- }
- }
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- new
- playername[24];
- GetPlayerName(playerid, playername, sizeof(playername));
- if(strcmp(RentalInfo[GetPVarInt(playerid, "HasRental")][rOwner], playername, true) == 0) { }
- else { SetPVarInt(playerid, "HasRental", 0); }
- return 1;
- }
- public OnPlayerDisconnect(playerid)
- {
- return 1;
- }
- stock LoadRentalCars()
- {
- new
- file[100],
- file2[100],
- string[128],
- vehicle;
- for(new i = 1; i < MAX_VEHICLES; i++)
- {
- format(file, sizeof(file), "rentals/vehicles/%d.cfg", i);
- if(!fexist(file)) continue;
- if(fexist(file) && INI_Open(file))
- {
- if(GetVehicleModel(i) > 399)
- {
- for (new v = 1; v < MAX_VEHICLES; v ++)
- {
- if (GetVehicleModel(v) == 0)
- {
- i = v;
- break;
- }
- }
- format(file2, sizeof(file2), "rentals/vehicles/%d.cfg", i);
- frename(file, file2);
- }
- VehicleInfo[i][vRental] = INI_ReadInt("vRental");
- VehicleInfo[i][vModel] = INI_ReadInt("vModel");
- VehicleInfo[i][vPrice] = INI_ReadInt("vPrice");
- VehicleInfo[i][vPos][1] = INI_ReadFloat("vehicle_x");
- VehicleInfo[i][vPos][2] = INI_ReadFloat("vehicle_y");
- VehicleInfo[i][vPos][3] = INI_ReadFloat("vehicle_z");
- VehicleInfo[i][vPos][4] = INI_ReadFloat("vehicle_angle");
- VehicleInfo[i][vOnRent] = INI_ReadInt("vOnRent");
- vehicle = CreateVehicle(VehicleInfo[i][vModel], VehicleInfo[i][vPos][1], VehicleInfo[i][vPos][2], VehicleInfo[i][vPos][3], VehicleInfo[i][vPos][4], 0, 0, -1);
- format(string, sizeof(string), "%s For Rent - Price: $%d", GetVehicleName(vehicle), VehicleInfo[i][vPrice]);
- VehicleInfo[i][vLabel] = Create3DTextLabel(string, COLOR_ORANGE, VehicleInfo[i][vPos][1], VehicleInfo[i][vPos][2], VehicleInfo[i][vPos][3], 10.0, 0);
- INI_Close();
- }
- }
- return 1;
- }
- stock LoadRentals()
- {
- new file[100], string[256], name[32], ownr[24];
- for(new i = 1; i < MAX_RENTALS; i++)
- {
- format(file, sizeof(file), "rentals/%d.cfg", i);
- if(fexist(file) && INI_Open(file))
- {
- INI_ReadString(name, "rName");
- INI_ReadString(ownr, "rOwner");
- strmid(RentalInfo[i][rName], name, 0, strlen(name), 255);
- strmid(RentalInfo[i][rOwner], ownr, 0, strlen(ownr), 255);
- RentalInfo[i][rPrice] = INI_ReadInt("rPrice");
- RentalInfo[i][rOwned] = INI_ReadInt("rOwned");
- RentalInfo[i][rPos_x] = INI_ReadFloat("rPos_x");
- RentalInfo[i][rPos_y] = INI_ReadFloat("rPos_y");
- RentalInfo[i][rPos_z] = INI_ReadFloat("rPos_z");
- RentalInfo[i][rRadius] = INI_ReadFloat("rRadius");
- RentalInfo[i][rProfit] = INI_ReadInt("rProfit");
- switch(RentalInfo[i][rOwned])
- {
- 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]); }
- case 1: { format(string, sizeof(string), "{FF6347}%s{FFFFFF}\n\n{FF6347}Owner:{FFFFFF} %s", RentalInfo[i][rName], RentalInfo[i][rOwner]); }
- }
- RentalInfo[i][rLabel] = Create3DTextLabel(string, COLOR_WHITE, RentalInfo[i][rPos_x], RentalInfo[i][rPos_y], RentalInfo[i][rPos_z], 10.0, 0);
- CreatePickup(1274, 23, RentalInfo[i][rPos_x], RentalInfo[i][rPos_y], RentalInfo[i][rPos_z]);
- rentOwned[i] = true;
- INI_Close();
- }
- }
- return 1;
- }
- stock SaveRental(rentalid)
- {
- new file[100];
- if(rentOwned[rentalid] == true)
- {
- format(file, sizeof(file), "rentals/%d.cfg", rentalid);
- if(INI_Open(file))
- {
- INI_WriteString("rName", RentalInfo[rentalid][rName]);
- INI_WriteString("rOwner", RentalInfo[rentalid][rOwner]);
- INI_WriteInt("rPrice", RentalInfo[rentalid][rPrice]);
- INI_WriteInt("rOwned", RentalInfo[rentalid][rOwned]);
- INI_WriteFloat("rPos_x", RentalInfo[rentalid][rPos_x]);
- INI_WriteFloat("rPos_y", RentalInfo[rentalid][rPos_y]);
- INI_WriteFloat("rPos_z", RentalInfo[rentalid][rPos_z]);
- INI_WriteFloat("rRadius", RentalInfo[rentalid][rRadius]);
- INI_WriteInt("rProfit", RentalInfo[rentalid][rProfit]);
- INI_Save();
- INI_Close();
- }
- }
- for(new i = 1; i < MAX_VEHICLES; i++)
- {
- if(VehicleInfo[i][vRental] == rentalid)
- {
- format(file, sizeof(file), "rentals/vehicles/%d.cfg", i);
- if(INI_Open(file))
- {
- INI_WriteInt("vRental", VehicleInfo[i][vRental]);
- INI_WriteInt("vModel", VehicleInfo[i][vModel]);
- INI_WriteInt("vPrice", VehicleInfo[i][vPrice]);
- INI_WriteFloat("vehicle_x", VehicleInfo[i][vPos][1]);
- INI_WriteFloat("vehicle_y", VehicleInfo[i][vPos][2]);
- INI_WriteFloat("vehicle_z", VehicleInfo[i][vPos][3]);
- INI_WriteFloat("vehicle_angle", VehicleInfo[i][vPos][4]);
- INI_WriteInt("vOnRent", VehicleInfo[i][vOnRent]);
- INI_Save();
- INI_Close();
- }
- }
- }
- return 1;
- }
- CMD:rentalhelp(playerid, params[])
- {
- SendClientMessage(playerid, COLOR_ORANGE, "=====Player Commands=====");
- SendClientMessage(playerid, -1, "/av - Accept to rent a vehicle");
- SendClientMessage(playerid, -1, "/dv - Decline to rent a vehicle");
- SendClientMessage(playerid, COLOR_ORANGE, "=====Administrator Commands=====");
- SendClientMessage(playerid, -1, "/createrental - Create a rental place");
- SendClientMessage(playerid, -1, "/destroyrental - Destroy a rental place");
- SendClientMessage(playerid, COLOR_ORANGE, "=====Owner Commands=====");
- SendClientMessage(playerid, -1, "/buyrental - Buys a nearby rental place");
- SendClientMessage(playerid, -1, "/createcar - Creates a rental care");
- SendClientMessage(playerid, -1, "/profit - View your earnings");
- SendClientMessage(playerid, -1, "/collectearnings - Collect your earnings");
- SendClientMessage(playerid, -1, "/selldealership - Sells your owned dealership");
- return 1;
- }
- CMD:av(playerid, params[])
- {
- if(rentingvehicle[playerid] == 1)
- {
- new
- vehicleid = GetPlayerVehicleID(playerid),
- model = GetVehicleModel(vehicleid),
- price = VehicleInfo[vehicleid][vPrice],
- Float:position[5],
- string[128],
- rentalid = -1,
- var[32],
- playername[24];
- GetPlayerName(playerid, playername, sizeof(playername));
- GetPlayerPos(playerid, position[1], position[2], position[3]);
- GetPlayerFacingAngle(playerid, position[4]);
- 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;
- if(GetPlayerMoney(playerid) < price) return SendClientMessage(playerid, COLOR_GREY, " You can't afford that !"), RemovePlayerFromVehicle(playerid); TogglePlayerControllable(playerid, 1); rentingvehicle[playerid] = 0;
- for(new i = 1; i < MAX_RENTALS; i++)
- {
- if(IsPlayerInRangeOfPoint(playerid, RentalInfo[i][rRadius], RentalInfo[i][rPos_x], RentalInfo[i][rPos_y], RentalInfo[i][rPos_z]))
- {
- rentalid = i;
- break;
- }
- }
- RentalInfo[rentalid][rProfit] += price;
- GivePlayerMoney(playerid, -price);
- RemovePlayerFromVehicle(playerid);
- 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);
- format(string, sizeof(string), "[CASHIER:] Thank you for renting at %s, we hope to see you again!", RentalInfo[rentalid][rName]);
- SendClientMessage(playerid, COLOR_WHITE, string);
- SendClientMessage(playerid, COLOR_WHITE, "Your vehicle has been spawned in front of you.");
- SetPVarInt(playerid, "AmountOfCars", GetPVarInt(playerid, "AmountOfCars") + 1);
- format(var, sizeof(var), "Model_%d", GetPVarInt(playerid, "AmountOfCars"));
- SetPVarInt(playerid, var, model);
- format(var, sizeof(var), "X_%d", GetPVarInt(playerid, "AmountOfCars"));
- SetPVarFloat(playerid, var, (position[1] + (7.5 * floatsin(-position[4], degrees))));
- format(var, sizeof(var), "Y_%d", GetPVarInt(playerid, "AmountOfCars"));
- SetPVarFloat(playerid, var, (position[2] + (7.5 * floatcos(position[4], degrees))));
- format(var, sizeof(var), "Z_%d", GetPVarInt(playerid, "AmountOfCars"));
- SetPVarFloat(playerid, var, position[3]);
- format(var, sizeof(var), "Angle_%d", GetPVarInt(playerid, "AmountOfCars"));
- SetPVarFloat(playerid, var, position[4]);
- format(var, sizeof(var), "Carkey_%d", GetPVarInt(playerid, "AmountOfCars"));
- SetPVarInt(playerid, var, vehicleid);
- format(var, sizeof(var), "Paintjob_%d", GetPVarInt(playerid, "AmountOfCars"));
- SetPVarInt(playerid, var, -1);
- strmid(owner[vehicleid], playername, 0, strlen(playername), 255);
- TogglePlayerControllable(playerid, 1);
- rentingvehicle[playerid] = 0;
- }
- return 1;
- }
- CMD:dv(playerid, params[])
- {
- if(rentingvehicle[playerid] == 1)
- {
- new string[180], veh, rentalid;
- rentalid = -1;
- veh = GetPlayerVehicleID(playerid);
- for(new i = 1; i < MAX_RENTALS; i++)
- {
- if(IsPlayerInRangeOfPoint(playerid, RentalInfo[i][rRadius], RentalInfo[i][rPos_x], RentalInfo[i][rPos_y], RentalInfo[i][rPos_z]))
- {
- rentalid = i;
- break;
- }
- }
- format(string, sizeof(string), "You have declined renting a/an %s in %s", GetVehicleName(veh), RentalInfo[rentalid][rName]);
- SendClientMessage(playerid, COLOR_GREY, string);
- RemovePlayerFromVehicle(playerid);
- TogglePlayerControllable(playerid, 1);
- rentingvehicle[playerid] = 0;
- }
- return 1;
- }
- CMD:createrental(playerid, params[])
- {
- new
- price,
- rentalname[32],
- Float:radius,
- rentalid = -1,
- bool:assigned = false,
- string[256],
- Float:x,
- Float:y,
- Float:z;
- GetPlayerPos(playerid, x, y, z);
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GREY, " You are not authorized to use this command !");
- if(sscanf(params, "dfs", price, radius, rentalname))
- return SendClientMessage(playerid, COLOR_WHITE, "* [Usage]: /createrental [price] [radius] [name of rental]");
- for(new i = 1; i < MAX_RENTALS; i++)
- {
- if(rentOwned[i] == false)
- {
- rentalid = i;
- assigned = true;
- break;
- }
- }
- if(assigned == false) return SendClientMessage(playerid, COLOR_GREY, " Something went wrong while creating the rental !");
- strmid(RentalInfo[rentalid][rName], rentalname, 0, strlen(rentalname), 255);
- strmid(RentalInfo[rentalid][rOwner], "No-one", 0, strlen("No-one"), 255);
- RentalInfo[rentalid][rPrice] = price;
- RentalInfo[rentalid][rOwned] = 0;
- RentalInfo[rentalid][rPos_x] = x;
- RentalInfo[rentalid][rPos_y] = y;
- RentalInfo[rentalid][rPos_z] = z;
- RentalInfo[rentalid][rRadius] = radius;
- RentalInfo[rentalid][rId] = CreatePickup(1274, 23, x, y, z);
- 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);
- RentalInfo[rentalid][rLabel] = Create3DTextLabel(string, COLOR_WHITE, x, y, z, 10.0, 0);
- format(string, sizeof(string), " Rental %d created.", rentalid);
- SendClientMessage(playerid, COLOR_GREY, string);
- rentOwned[rentalid] = true;
- SaveRental(rentalid);
- return 1;
- }
- CMD:destroyrental(playerid, params[])
- {
- new
- id,
- file[100];
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_GREY, " You are not authorized to use this command !");
- if(sscanf(params, "d", id))
- return SendClientMessage(playerid, COLOR_WHITE, "* [Usage]: /destroyrental [rentalid]");
- if(id < 1 || id > MAX_RENTALS) return SendClientMessage(playerid, COLOR_GREY, " Invalid rental ID !");
- if(rentOwned[id] == true)
- {
- format(file, sizeof(file), "rentals/%d.cfg", id);
- if(fexist(file)) { fremove(file); }
- for(new i = 1; i < MAX_VEHICLES; i++)
- {
- if(VehicleInfo[i][vRental] == id)
- {
- format(file, sizeof(file), "rentals/vehicles/%d.cfg", i);
- if(fexist(file)) { fremove(file); }
- VehicleInfo[i][vRental] = 0;
- VehicleInfo[i][vModel] = 0;
- VehicleInfo[i][vPrice] = 0;
- VehicleInfo[i][vPos][1] = 0.0;
- VehicleInfo[i][vPos][2] = 0.0;
- VehicleInfo[i][vPos][3] = 0.0;
- VehicleInfo[i][vPos][4] = 0.0;
- VehicleInfo[i][vOnRent] = 0;
- Delete3DTextLabel(VehicleInfo[i][vLabel]);
- DestroyVehicle(i);
- }
- }
- strmid(RentalInfo[id][rName], "None", 0, strlen("None"), 255);
- strmid(RentalInfo[id][rOwner], "No-one", 0, strlen("No-one"), 255);
- RentalInfo[id][rPrice] = 0;
- RentalInfo[id][rOwned] = 0;
- RentalInfo[id][rPos_x] = 0.0;
- RentalInfo[id][rPos_y] = 0.0;
- RentalInfo[id][rPos_z] = 0.0;
- RentalInfo[id][rRadius] = 0.0;
- RentalInfo[id][rProfit] = 0;
- rentOwned[id] = false;
- Delete3DTextLabel(RentalInfo[id][rLabel]);
- DestroyPickup(RentalInfo[id][rId]);
- return 1;
- }
- else { SendClientMessage(playerid, COLOR_GREY, " Rental ID not found !"); }
- return 1;
- }
- CMD:buyrental(playerid, params[])
- {
- params[0] = 0;
- new
- rentalid = -1,
- string[256],
- playername[24],
- bool:isnear = false;
- GetPlayerName(playerid, playername, sizeof(playername));
- if(GetPVarInt(playerid, "HasRental") != 0) return SendClientMessage(playerid, COLOR_GREY, " You already have a rental !");
- for(new i = 1; i < MAX_RENTALS; i++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 2.0, RentalInfo[i][rPos_x], RentalInfo[i][rPos_y], RentalInfo[i][rPos_z]))
- {
- rentalid = i;
- isnear = true;
- break;
- }
- }
- if(isnear == false) return SendClientMessage(playerid, COLOR_GREY, " You are not near a rental!");
- if(RentalInfo[rentalid][rOwned] == 0)
- {
- if(GetPlayerMoney(playerid) >= RentalInfo[rentalid][rPrice])
- {
- format(string, sizeof(string), "{FF6347}%s{FFFFFF}\n\n{FF6347}Owner:{FFFFFF} %s", RentalInfo[rentalid][rName], playername);
- Delete3DTextLabel(RentalInfo[rentalid][rLabel]);
- RentalInfo[rentalid][rLabel] = Create3DTextLabel(string, COLOR_WHITE, RentalInfo[rentalid][rPos_x], RentalInfo[rentalid][rPos_y], RentalInfo[rentalid][rPos_z], 10.0, 0);
- RentalInfo[rentalid][rOwned] = 1;
- strmid(RentalInfo[rentalid][rOwner], playername, 0, strlen(playername), 255);
- GivePlayerMoney(playerid, -RentalInfo[rentalid][rPrice]);
- 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]);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- SetPVarInt(playerid, "HasRental", rentalid);
- SaveRental(rentalid);
- return 1;
- }
- else return SendClientMessage(playerid, COLOR_GREY, " You can't afford this !");
- }
- else { SendClientMessage(playerid, COLOR_GREY, " This rental is already owned !"); }
- return 1;
- }
- CMD:createcar(playerid, params[])
- {
- new
- model,
- price,
- rentalid = GetPVarInt(playerid, "HasRental");
- if(GetPVarInt(playerid, "HasRental") != 0)
- {
- if(!IsPlayerInRangeOfPoint(playerid, RentalInfo[rentalid][rRadius], RentalInfo[rentalid][rPos_x], RentalInfo[rentalid][rPos_y], RentalInfo[rentalid][rPos_z]))
- return SendClientMessage(playerid, COLOR_GREY, " You are not near your rental !");
- new Float:x, Float:y, Float:z, Float:angle;
- GetPlayerPos(playerid, x, y, z); GetPlayerFacingAngle(playerid, angle);
- if(sscanf(params, "dd", model, price)) return SendClientMessage(playerid, COLOR_WHITE, "* [Usage]: /createcar [model] [price]");
- CreateRentalVehicle(playerid, model, price, x, y, z, angle);
- return 1;
- }
- else { SendClientMessage(playerid, COLOR_GREY, " You don't own a rental !"); }
- return 1;
- }
- CMD:profit(playerid, params[])
- {
- params[0] = 0;
- new
- rentalid = GetPVarInt(playerid, "HasRental"),
- string[64];
- if(GetPVarInt(playerid, "HasRental") != 0)
- {
- format(string, sizeof(string), "{FF8300}Profit:{FFFFFF} $%d", RentalInfo[rentalid][rProfit]);
- SendClientMessage(playerid, COLOR_WHITE, string);
- return 1;
- }
- else { SendClientMessage(playerid, COLOR_GREY, " You don't own a rental !"); }
- return 1;
- }
- CMD:collectprofit(playerid, params[])
- {
- params[0] = 0;
- new
- string[128],
- rentalid = GetPVarInt(playerid, "HasRental");
- if(GetPVarInt(playerid, "HasRental") != 0)
- {
- if(!IsPlayerInRangeOfPoint(playerid, 2.0, RentalInfo[rentalid][rPos_x], RentalInfo[rentalid][rPos_y], RentalInfo[rentalid][rPos_z]))
- return SendClientMessage(playerid, COLOR_GREY, " You are not near your rental !");
- if(!RentalInfo[rentalid][rProfit])
- return SendClientMessage(playerid, COLOR_GREY, " You have no profit to collect !");
- format(string, sizeof(string), "* You've collected $%d from your rental's profit.", RentalInfo[rentalid][rProfit]);
- SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
- GivePlayerMoney(playerid, RentalInfo[rentalid][rProfit]);
- RentalInfo[rentalid][rProfit] = 0;
- return 1;
- }
- else { SendClientMessage(playerid, COLOR_GREY, " You don't own a rental !"); }
- return 1;
- }
- CMD:sellrental(playerid, params[])
- {
- new
- rentalid = GetPVarInt(playerid, "HasRental"),
- string[128];
- if(GetPVarInt(playerid, "HasRental") != 0)
- {
- if(!IsPlayerInRangeOfPoint(playerid, 2.0, RentalInfo[rentalid][rPos_x], RentalInfo[rentalid][rPos_y], RentalInfo[rentalid][rPos_z]))
- return SendClientMessage(playerid, COLOR_GREY, " You are not near your rental !");
- if(!params[0])
- return SendClientMessage(playerid, COLOR_WHITE, "* [Usage]: /sellrental [confirm]");
- if(strcmp(params, "confirm", true) == 0)
- {
- new
- price = RentalInfo[rentalid][rPrice];
- GivePlayerMoney(playerid, price);
- 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]);
- Delete3DTextLabel(RentalInfo[rentalid][rLabel]);
- RentalInfo[rentalid][rLabel] = Create3DTextLabel(string, COLOR_WHITE, RentalInfo[rentalid][rPos_x], RentalInfo[rentalid][rPos_y], RentalInfo[rentalid][rPos_z], 10.0, 0);
- RentalInfo[rentalid][rOwned] = 0;
- strmid(RentalInfo[rentalid][rOwner], "No-one", 0, strlen("No-one"), 255);
- format(string, sizeof(string), "You've sold your rental back to the market for $%d.", RentalInfo[rentalid][rPrice]);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- SetPVarInt(playerid, "HasRental", 0);
- SaveRental(rentalid);
- return 1;
- }
- }
- else { SendClientMessage(playerid, COLOR_GREY, " You don't own a rental !"); }
- return 1;
- }
- stock CreateRentalVehicle(creator, model, price, Float:carx, Float:cary, Float:carz, Float:carangle)
- {
- new
- vehicleid,
- string[256];
- vehicleid = CreateVehicle(model, carx, cary, carz, carangle, 0, 0, -1);
- if(vehicleid == INVALID_VEHICLE_ID) return SendClientMessage(creator, COLOR_GREY, " The car couldn't be created !");
- VehicleInfo[vehicleid][vRental] = GetPVarInt(creator, "HasRental");
- VehicleInfo[vehicleid][vModel] = model;
- VehicleInfo[vehicleid][vPrice] = price;
- VehicleInfo[vehicleid][vPos][1] = carx;
- VehicleInfo[vehicleid][vPos][2] = cary;
- VehicleInfo[vehicleid][vPos][3] = carz;
- VehicleInfo[vehicleid][vPos][4] = carangle;
- VehicleInfo[vehicleid][vOnRent] = 1;
- format(string, sizeof(string), "%s For Sale - Price: $%d", GetVehicleName(vehicleid), price);
- VehicleInfo[vehicleid][vLabel] = Create3DTextLabel(string, COLOR_ORANGE, carx, cary, carz, 10.0, 0);
- SaveRental(GetPVarInt(creator, "HasRental"));
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- if(newstate == PLAYER_STATE_DRIVER)
- {
- new
- vehicleid = GetPlayerVehicleID(playerid),
- string[128];
- if(VehicleInfo[vehicleid][vOnRent] == 1)
- {
- rentingvehicle[playerid] = 0;
- 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]);
- SendClientMessage(playerid, COLOR_GREY, string);
- rentingvehicle[playerid] = 1;
- TogglePlayerControllable(playerid, 0);
- return 1;
- }
- }
- return 1;
- }
- GetVehicleName(vehicleid)
- {
- new
- vehiclename[64] = "None";
- if(!vehicleid) return vehiclename;
- format(vehiclename, sizeof(vehiclename), "%s", vehName[( GetVehicleModel(vehicleid) - 400 )]);
- return vehiclename;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- return 0;
- }
- stock sscanf(string[], format[], {Float,_}:...)
- {
- #if defined isnull
- if (isnull(string))
- #else
- if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
- #endif
- {
- return format[0];
- }
- #pragma tabsize 4
- new
- formatPos = 0,
- stringPos = 0,
- paramPos = 2,
- paramCount = numargs(),
- delim = ' ';
- while (string[stringPos] && string[stringPos] <= ' ')
- {
- stringPos++;
- }
- while (paramPos < paramCount && string[stringPos])
- {
- switch (format[formatPos++])
- {
- case '\0':
- {
- return 0;
- }
- case 'i', 'd':
- {
- new
- neg = 1,
- num = 0,
- ch = string[stringPos];
- if (ch == '-')
- {
- neg = -1;
- ch = string[++stringPos];
- }
- do
- {
- stringPos++;
- if ('0' <= ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return -1;
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num * neg);
- }
- case 'h', 'x':
- {
- new
- num = 0,
- ch = string[stringPos];
- do
- {
- stringPos++;
- switch (ch)
- {
- case 'x', 'X':
- {
- num = 0;
- continue;
- }
- case '0' .. '9':
- {
- num = (num << 4) | (ch - '0');
- }
- case 'a' .. 'f':
- {
- num = (num << 4) | (ch - ('a' - 10));
- }
- case 'A' .. 'F':
- {
- num = (num << 4) | (ch - ('A' - 10));
- }
- default:
- {
- return -1;
- }
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num);
- }
- case 'c':
- {
- setarg(paramPos, 0, string[stringPos++]);
- }
- case 'f':
- {
- new changestr[16], changepos = 0, strpos = stringPos;
- while(changepos < 16 && string[strpos] && string[strpos] != delim)
- {
- changestr[changepos++] = string[strpos++];
- }
- changestr[changepos] = '\0';
- setarg(paramPos,0,_:floatstr(changestr));
- }
- case 'p':
- {
- delim = format[formatPos++];
- continue;
- }
- case '\'':
- {
- new
- end = formatPos - 1,
- ch;
- while ((ch = format[++end]) && ch != '\'') {}
- if (!ch)
- {
- return -1;
- }
- format[end] = '\0';
- if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
- {
- if (format[end + 1])
- {
- return -1;
- }
- return 0;
- }
- format[end] = '\'';
- stringPos = ch + (end - formatPos);
- formatPos = end + 1;
- }
- case 'u':
- {
- new
- end = stringPos - 1,
- id = 0,
- bool:num = true,
- ch;
- while ((ch = string[++end]) && ch != delim)
- {
- if (num)
- {
- if ('0' <= ch <= '9')
- {
- id = (id * 10) + (ch - '0');
- }
- else
- {
- num = false;
- }
- }
- }
- if (num && IsPlayerConnected(id))
- {
- setarg(paramPos, 0, id);
- }
- else
- {
- #if !defined foreach
- #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
- #define __SSCANF_FOREACH__
- #endif
- string[end] = '\0';
- num = false;
- new
- name[MAX_PLAYER_NAME];
- id = end - stringPos;
- foreach (Player, playerid)
- {
- GetPlayerName(playerid, name, sizeof (name));
- if (!strcmp(name, string[stringPos], true, id))
- {
- setarg(paramPos, 0, playerid);
- num = true;
- break;
- }
- }
- if (!num)
- {
- setarg(paramPos, 0, INVALID_PLAYER_ID);
- }
- string[end] = ch;
- #if defined __SSCANF_FOREACH__
- #undef foreach
- #undef __SSCANF_FOREACH__
- #endif
- }
- stringPos = end;
- }
- case 's', 'z':
- {
- new
- i = 0,
- ch;
- if (format[formatPos])
- {
- while ((ch = string[stringPos++]) && ch != delim)
- {
- setarg(paramPos, i++, ch);
- }
- if (!i)
- {
- return -1;
- }
- }
- else
- {
- while ((ch = string[stringPos++]))
- {
- setarg(paramPos, i++, ch);
- }
- }
- stringPos--;
- setarg(paramPos, i, '\0');
- }
- default:
- {
- continue;
- }
- }
- while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
- {
- stringPos++;
- }
- while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
- {
- stringPos++;
- }
- paramPos++;
- }
- do
- {
- if ((delim = format[formatPos++]) > ' ')
- {
- if (delim == '\'')
- {
- while ((delim = format[formatPos++]) && delim != '\'') {}
- }
- else if (delim != 'z')
- {
- return delim;
- }
- }
- }
- while (delim > ' ');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment