/// <summary> /// Initializes the vehicle and prepares related objects. /// </summary> private void InitializeVehicle() { currentCar = new GasVehicle(p.CurrentVehicle); AddVehicle(currentCar); //DEBUGInitializeVehicle(); }
private void onKeyUp(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == CAN_REFUEL_CONTROL) { if (p.IsInVehicle() && currentCar != null) { //currentCar = new GasVehicle(p.CurrentVehicle); GTA.UI.Notification.Show(currentCar.GetFuelLevel().ToString() + "\n" + currentCar.GetActualFuelLevel().ToString() + "\n" + currentCar.GetCurrentFuelConsumption().ToString() + " MPG\n" + currentCar.distanceT.ToString()); } else if (readyForCanRefuel) { vehicleForRefuel.Refuel(FUEL.Jerry_Can); GTA.UI.Notification.Show("Vehicle refueled!"); vehicleForRefuel = null; p.Weapons.Remove(GTA.WeaponHash.PetrolCan); readyForCanRefuel = false; } } //Refuel vehicle else if (e.KeyCode == STATION_REFUEL_CONTROL) { if (refuelMenuEnabled) { if (IsAtGasStation()) { //Refill the vehicle and charge the player if ((int)refillPrice <= Game.Player.Money) { ChargePlayer(refillPrice); currentCar.Refuel(FUEL.Fuel_Pump); GTA.UI.Notification.Show("Vehicle refueled!"); justRefueled = true; elapsedTimeSinceLastRefuel = 0; refillPrice = 0; } else { GTA.UI.Notification.Show("You don\'t have enough cash to refuel your vehicle! "); //Add a random pity message } } } } }
/// <summary> /// DO NOT USE /// </summary> /// <param name="gV"></param> /// <returns></returns> private bool ContainsVehicle(GasVehicle gV) { foreach (var v in savedVehicles) { if (gV.GetVehicleInstance() == v.GetVehicleInstance()) { return(true); } } return(false); }
private void onTick(object sender, EventArgs e) { elapsedIntervalTime += REFRESH_INTERVAL; //If the player is in the vehicle if (p.IsInVehicle() && VehicleIsCar(p.CurrentVehicle)) { //If the player has just entered this vehicle (Keep the "!") if (!justEnteredCar) { justEnteredCar = true; //Initialize script and objects InitializeVehicle(); } //Run functions CheckFuelLevel(); ConsumeFuel(); DrawFuelGauge(); GasStationMenu(); FuelWarning(); //DrawDebugInfo(); } else { //Save the vehicle if (justEnteredCar) { SaveVehicle(); justEnteredCar = false; currentCar = null; } //RefuelMenu(); //GTA.Entity g; //GTA.Native.WeaponHash.PetrolCan; //p.Weapons.Current.Hash } RefuelMenu(); //Reset elapsedInterval Times ResetIntervals(); }
//VEHICLE LIST METHODS /// <summary> /// Adds a vehicle to the savedVehicles List. Checks if vehicle is already in list. /// </summary> /// <param name="gV"></param> private void AddVehicle(GasVehicle gV) { //Previously was "!SavedVehicles.Contains(gV)" if (!savedVehicles.Contains(gV)) { GTA.UI.Notification.Show("Adding gas vehicle to list..."); if (savedVehicles.Count >= MAX_SAVED_VEHICLES) { removeVehicle(0); } savedVehicles.Add(gV); } else { GTA.UI.Notification.Show("List of vehicles already contains this vehicle."); currentCar = savedVehicles.Find((GasVehicle gGV) => { return(gGV.Equals(gV)); }); GTA.UI.Notification.Show("Loaded vehicle from list. Current fuel level is: " + currentCar.GetFuelLevel()); } }
/// <summary> /// FOR DEBUGGING ONLY /// </summary> private void DEBUGInitializeVehicle() { currentCar = new GasVehicle(p.CurrentVehicle); AddVehicle(currentCar); //Check list for vehicle string vehicles = ""; foreach (var v in savedVehicles) { vehicles += (v.GetVehicleInstance().ToString() + "\n"); } GTA.UI.Notification.Show(vehicles); string vehicleHashes = ""; foreach (var v in savedVehicles) { vehicleHashes += (v.GetVehicleInstance().GetHashCode().ToString() + "\n"); } GTA.UI.Notification.Show(vehicleHashes); }
//MENU METHODS /// <summary> /// DO NOT USE CURRENTLY. TO DO: FIX /// Script stops running after this method has been called multiple times. /// </summary> private void RefuelMenu() { if (elapsedIntervalTime >= FUEL_CHECK_INTERVAL) { //GTA.UI.Notification.Show("Fuel check interval..."); if (!p.IsInVehicle()) { //GTA.UI.Notification.Show("Checking for player vicinity to vehicle"); //List<Vehicle> nearbyVehicles = new List<Vehicle>(World.GetNearbyVehicles(p,MIN_REFUEL_DISTANCE)); //vehicleForRefuel = savedVehicles.Find((GasVehicle gV) => //{ return p.Position.DistanceTo(gV.GetVehicleInstance().Position) <= MIN_REFUEL_DISTANCE; }); // GTA.UI.Notification.Show(vehicleForRefuel.GetFuelLevel().ToString()); if (vehicleForRefuel == null) { foreach (var gV in savedVehicles) { if (p.Position.DistanceTo(gV.GetVehicleInstance().Position) <= MIN_REFUEL_DISTANCE) { vehicleForRefuel = gV; break; } } } if (vehicleForRefuel != null && !inRangeForRefuel) { //GTA.UI.Notification.Show("In range for refuel!"); inRangeForRefuel = true; } if (inRangeForRefuel) { WeaponHash currentWeapon = p.Weapons.Current.Hash; //GTA.UI.Notification.Show("checking current wep"); //If the user is holding a jerry can if (currentWeapon == GTA.WeaponHash.PetrolCan) { readyForCanRefuel = true; GTA.UI.Notification.Show("Press Y to use the jerry can to refuel your vehicle."); } else { readyForCanRefuel = false; } } } else { inRangeForRefuel = false; readyForCanRefuel = false; if (vehicleForRefuel != null) { vehicleForRefuel = null; } } } }