public void CMD_CreateDealership(Client player, string name) { if (!player.IsAdmin()) { player.sendChatMessage("~r~ERRO: ~w~Você não tem permissão."); return; } Dealership new_dealership = new Dealership(Main.GetGuid(), player.position, name); new_dealership.Save(); Main.Dealerships.Add(new_dealership); API.sendChatMessageToPlayer(player, $"~g~SUCESSO: ~s~Você criou uma concessionária com o nome: ~g~{name}~s~."); }
public void Dealership_Init() { // load settings if (API.hasSetting("dealershipDirName")) { DEALERSHIP_SAVE_DIR = API.getSetting <string>("dealershipDirName"); } DEALERSHIP_SAVE_DIR = API.getResourceFolder() + Path.DirectorySeparatorChar + DEALERSHIP_SAVE_DIR; if (!Directory.Exists(DEALERSHIP_SAVE_DIR)) { Directory.CreateDirectory(DEALERSHIP_SAVE_DIR); } if (API.hasSetting("playerDealershipLimit")) { PLAYER_DEALERSHIP_LIMIT = API.getSetting <int>("playerDealershipLimit"); } if (API.hasSetting("dealershipMoneyLimit")) { DEALERSHIP_MONEY_LIMIT = API.getSetting <int>("dealershipMoneyLimit"); } if (API.hasSetting("saveInterval")) { SAVE_INTERVAL = API.getSetting <int>("saveInterval"); } API.consoleOutput("-> Player Dealership Limit: {0}", ((PLAYER_DEALERSHIP_LIMIT == 0) ? "Disabled" : PLAYER_DEALERSHIP_LIMIT.ToString())); API.consoleOutput("-> Dealership Safe Limit: ${0:n0}", DEALERSHIP_MONEY_LIMIT); API.consoleOutput("-> Save Interval: {0}", TimeSpan.FromSeconds(SAVE_INTERVAL).ToString(@"hh\:mm\:ss")); // load dealerships foreach (string file in Directory.EnumerateFiles(DEALERSHIP_SAVE_DIR, "*.json")) { Dealership dealership = JsonConvert.DeserializeObject <Dealership>(File.ReadAllText(file)); Dealerships.Add(dealership); // vehicles foreach (DealershipVehicle vehicle in dealership.Vehicles) { vehicle.Create(); } } API.consoleOutput("Loaded {0} dealerships.", Dealerships.Count); }
public void Dealership_ClientEvent(Client player, string event_name, params object[] args) { switch (event_name) { case "RequestDealershipBuyMenu": { if (!player.hasData("DealershipVehicle_ID")) { return; } DealershipVehicle vehicle = player.getData("DealershipVehicle_ID"); player.triggerEvent("Dealership_PurchaseMenu", API.toJson(new { vehicle.Price })); break; } case "VehiclePurchase": { if (!player.hasData("DealershipVehicle_ID")) { return; } int color1 = (int)args[0]; int color2 = (int)args[1]; Dealership dealership = player.getData("Dealership_ID"); DealershipVehicle vehicle = player.getData("DealershipVehicle_ID"); if (Player.Data.Character[player].Vehicles.Count >= 3) { API.sendChatMessageToPlayer(player, $"~r~ERRO: ~s~Você pode ter apenas 3 veículos."); return; } else if (vehicle.Price > Player.Data.Character[player].Money) { API.sendChatMessageToPlayer(player, $"~r~ERRO: ~s~Você não tem dinheiro suficiente."); return; } var veh = API.shared.createVehicle(vehicle.Model, new Vector3(dealership.VehicleSpawn.X, dealership.VehicleSpawn.Y, dealership.VehicleSpawn.Z), new Vector3(0.0, 0.0, 0.0), color1, color2); veh.engineStatus = false; API.shared.setPlayerIntoVehicle(player, veh, -1); player.resetData("Dealership_ID"); player.resetData("DealershipVehicle_ID"); player.triggerEvent("OnExitDealershipVehicle"); player.giveMoney(-vehicle.Price); player.sendNotification("", $"Você comprou um ~g~{veh.displayName}~s~."); CharacterVehicle characterVehicle = new CharacterVehicle { Character = Player.Data.Character[player], Vehicle = veh, Price = vehicle.Price, Model = vehicle.Model, Color1 = color1, Color2 = color2, Fuel = 100, PositionX = veh.position.X, PositionY = veh.position.Y, PositionZ = veh.position.Z, RotationX = 0.0f, RotationY = 0.0f, RotationZ = 0.0f, CreatedAt = DateTime.Now }; Player.Data.Character[player].Vehicles.Add(characterVehicle); break; } } }