public void CMD_RemovePlayerFromGameMode(Client client, uint gmId, string playerFirstName, string playerSecondName = "") { Client player = ServerUtilities.GetPlayerIfExists(client, playerFirstName, playerSecondName); if (player == null) { return; } try { BaseGameMode gameMode = GameModeHandler.Instance.GetGameModeById(gmId); gameMode.RemovePlayer(player); Main.Logger.LogClient(gameMode.GetGameModeData().EventHost, $"{client.Name} joined the event ({gameMode.GetGameModeData().Id}) {gameMode.GetGameModeData().Name}."); Main.Logger.LogClient(player, $"You were added to the event ({gameMode.GetGameModeData().Id}) {gameMode.GetGameModeData().Name} by {client.Name}."); } catch (Exception e) { Main.Logger.LogClient(client, e.Message); } }
public async void CMD_TakeOwnershipOfVehicle(Client client, string targetFirstName, string targetSurname = "") { if (await ServerUtilities.CanUseCommand(client, COMMAND_VEHICLE_SET_OWNER) == false) { return; } Client owner = ServerUtilities.GetPlayerIfExists(client, targetFirstName, targetSurname); if (owner == null) { return; } Vehicle vehicle = NAPI.Player.GetPlayerVehicle(owner); if (vehicle == null) { Main.Logger.LogClient(client, "You are not in a vehicle!"); return; } CharacterData newOwnerCharacterData = owner.GetData(CharacterData.CHARACTER_DATA_KEY); if (newOwnerCharacterData == null) { return; } CharacterData clientCharacterData = client.GetData(CharacterData.CHARACTER_DATA_KEY); //Owner is Client bool isClientOwner = false; if (clientCharacterData != null && clientCharacterData.Id == newOwnerCharacterData.Id) { isClientOwner = true; } VehicleData vehicleData = vehicle.GetData(VehicleData.VEHICLE_DATA_KEY); if (vehicleData != null) { if (vehicleData.OwnerId == newOwnerCharacterData.Id) { if (isClientOwner) { Main.Logger.LogClient(client, $"You already own ({vehicleData.Id}) {vehicle.DisplayName}."); } else { Main.Logger.LogClient(client, $"{newOwnerCharacterData.Name} already owns ({vehicleData.Id}) {vehicle.DisplayName}."); } return; } else { vehicleData.OwnerId = newOwnerCharacterData.Id; VehicleDatabase.SaveVehicle(vehicleData); } } else { vehicleData = new VehicleData() { VehicleName = ((VehicleHash)vehicle.Model).ToString(), Color1 = vehicle.PrimaryColor, Color2 = vehicle.SecondaryColor, Heading = vehicle.Heading, OwnerId = newOwnerCharacterData.Id }; vehicleData.SetPosition(vehicle.Position); vehicleData = await VehicleDatabase.CreateVehicle(vehicleData); vehicle.SetData(VehicleData.VEHICLE_DATA_KEY, vehicleData); } Main.Logger.LogClient(client, $"Gave {newOwnerCharacterData.Name} ownership of {vehicle.DisplayName}."); Main.Logger.LogClient(owner, $"{clientCharacterData.Name} gave you ownership of {vehicle.DisplayName}."); }