Skip to content
Permalink
Browse files

Whoa, vehicle fixing independence

  • Loading branch information
thers committed Mar 10, 2017
1 parent a8648d2 commit c1cdf552420ae3b94345d6cb74a9007d1ea6e890
Showing with 1,271 additions and 1,092 deletions.
  1. +2 −1 .gitignore
  2. +95 −71 DevMenu.cs
  3. +66 −49 EntityDecoration.cs
  4. +416 −343 FRFuel.cs
  5. +1 −1 FRFuel.csproj
  6. +26 −0 FRFuel.sln
  7. +31 −29 GasStations.cs
  8. +177 −160 HUD.cs
  9. +87 −72 InLoopOutAnimation.cs
  10. +370 −366 VehiclesPetrolTanks.cs
@@ -1,2 +1,3 @@
bin
obj
obj
.vs
@@ -10,78 +10,102 @@
using System.Security;
using CitizenFX.Core.Native;

namespace FRFuel.Dev {
public class DevMenu {
protected MenuPool menuPool;
protected UIMenu mainMenu;

protected UIMenuItem position;
protected UIMenuItem vehicleModelId;
protected UIMenuItem vehicleFuelTank;
protected UIMenuItem knownVehicle;

protected UIMenuItem netVehicleId;
protected UIMenuItem netVehicleIdControl;
protected UIMenuItem decoration;

protected Text txt = new Text("", new PointF(600f, 100f), .5f);

public DevMenu() {
menuPool = new MenuPool();
mainMenu = new UIMenu("FRFuel dev menu", "things");

position = new UIMenuItem("Pos");
position.Enabled = false;

vehicleModelId = new UIMenuItem("Vehicle model ID");
vehicleModelId.Enabled = false;

knownVehicle = new UIMenuItem("Is known vehicle");
knownVehicle.Enabled = false;

vehicleFuelTank = new UIMenuItem("Vehicle fuel tank");

mainMenu.AddItem(position);
mainMenu.AddItem(knownVehicle);
mainMenu.AddItem(vehicleModelId);
mainMenu.AddItem(vehicleFuelTank);

mainMenu.OnItemSelect += (sende, item, index) => {
if (item == vehicleFuelTank && Game.PlayerPed.IsInVehicle()) {
BaseScript.TriggerServerEvent(
"frfuel:dev:saveFuel",
"{" + Game.PlayerPed.CurrentVehicle.Model.Hash.ToString() + ", " + Game.PlayerPed.CurrentVehicle.FuelLevel.ToString() + "f},"
);
Screen.ShowNotification("Fuel to model saved");
namespace FRFuel.Dev
{
public class DevMenu
{
protected MenuPool menuPool;
protected UIMenu mainMenu;

protected UIMenuItem position;
protected UIMenuItem deleteVehicle;

protected UIMenuItem vehicleModelId;
protected UIMenuItem vehicleFuelTank;
protected UIMenuItem knownVehicle;

protected UIMenuItem netVehicleId;
protected UIMenuItem netVehicleIdControl;
protected UIMenuItem decoration;

protected Text txt = new Text("", new PointF(600f, 100f), .5f);

public DevMenu()
{
menuPool = new MenuPool();
mainMenu = new UIMenu("FRFuel dev menu", "things");

position = new UIMenuItem("Pos");
position.Enabled = false;

deleteVehicle = new UIMenuItem("Delete last vehicle");

vehicleModelId = new UIMenuItem("Vehicle model ID");
vehicleModelId.Enabled = false;

knownVehicle = new UIMenuItem("Is known vehicle");
knownVehicle.Enabled = false;

vehicleFuelTank = new UIMenuItem("Vehicle fuel tank");

mainMenu.AddItem(position);
mainMenu.AddItem(deleteVehicle);
mainMenu.AddItem(knownVehicle);
mainMenu.AddItem(vehicleModelId);
mainMenu.AddItem(vehicleFuelTank);

mainMenu.OnItemSelect += (sende, item, index) =>
{
if (item == vehicleFuelTank && Game.PlayerPed.IsInVehicle())
{
BaseScript.TriggerServerEvent(
"frfuel:dev:saveFuel",
"{" + Game.PlayerPed.CurrentVehicle.Model.Hash.ToString() + ", " + Game.PlayerPed.CurrentVehicle.FuelLevel.ToString() + "f},"
);
Screen.ShowNotification("Fuel to model saved");
}

if (item == deleteVehicle)
{
if (Game.PlayerPed.LastVehicle != null)
{
Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, Game.PlayerPed.LastVehicle, false, false);
Game.PlayerPed.LastVehicle.Delete();
}
}
};

menuPool.Add(mainMenu);
menuPool.RefreshIndex();
}
};

menuPool.Add(mainMenu);
menuPool.RefreshIndex();
}

public void OnTick() {
position.Text = "Pos: " + Game.PlayerPed.Position.ToString();

if (Game.PlayerPed.IsInVehicle()) {
Vehicle vehicle = Game.PlayerPed.CurrentVehicle;

knownVehicle.SetRightLabel(VehiclesPetrolTanks.dict.ContainsKey(vehicle.Model.Hash) ? "Yes" : "No");
vehicleModelId.SetRightLabel(vehicle.DisplayName.ToString());
vehicleFuelTank.SetRightLabel(vehicle.FuelLevel.ToString());
} else {
vehicleModelId.SetRightLabel("ped or not driver");
vehicleFuelTank.SetRightLabel("ped or not driver");
}

mainMenu.MouseControlsEnabled = false;
menuPool.MouseEdgeEnabled = false;
menuPool.ControlDisablingEnabled = false;
menuPool.ProcessMenus();

if (Game.IsControlJustReleased(0, Control.InteractionMenu)) {
mainMenu.Visible = !mainMenu.Visible;
}
public void OnTick()
{
position.Text = "Pos: " + Game.PlayerPed.Position.ToString();

if (Game.PlayerPed.IsInVehicle())
{
Vehicle vehicle = Game.PlayerPed.CurrentVehicle;

knownVehicle.SetRightLabel(VehiclesPetrolTanks.dict.ContainsKey(vehicle.Model.Hash) ? "Yes" : "No");
vehicleModelId.SetRightLabel(vehicle.DisplayName.ToString());
vehicleFuelTank.SetRightLabel(vehicle.FuelLevel.ToString());
}
else
{
vehicleModelId.SetRightLabel("ped or not driver");
vehicleFuelTank.SetRightLabel("ped or not driver");
}

mainMenu.MouseControlsEnabled = false;
menuPool.MouseEdgeEnabled = false;
menuPool.ControlDisablingEnabled = false;
menuPool.ProcessMenus();

if (Game.IsControlJustReleased(0, Control.InteractionMenu))
{
mainMenu.Visible = !mainMenu.Visible;
}
}
}
}
}
@@ -2,61 +2,78 @@
using CitizenFX.Core;
using CitizenFX.Core.Native;

namespace FRFuel {
public enum DecorationType {
Float = 1,
Bool = 2,
Int = 3,
Time = 5
}

public class EntityDecoration {
protected static Type floatType = typeof(float);
protected static Type boolType = typeof(bool);
protected static Type intType = typeof(int);

public static bool ExistOn(Entity entity, string propertyName) {
return Function.Call<bool>(Hash.DECOR_EXIST_ON, entity.NativeValue, propertyName);
namespace FRFuel
{
public enum DecorationType
{
Float = 1,
Bool = 2,
Int = 3,
Time = 5
}

public static void RegisterProperty(string propertyName, DecorationType type) {
Function.Call(Hash.DECOR_REGISTER, propertyName, (int) type);
}
public class EntityDecoration
{
protected static Type floatType = typeof(float);
protected static Type boolType = typeof(bool);
protected static Type intType = typeof(int);

public static void Set(Entity entity, string propertyName, float floatValue) {
Function.Call(Hash._DECOR_SET_FLOAT, entity.NativeValue, propertyName, floatValue);
}
public static bool ExistOn(Entity entity, string propertyName)
{
return Function.Call<bool>(Hash.DECOR_EXIST_ON, entity.NativeValue, propertyName);
}

public static void Set(Entity entity, string propertyName, int intValue) {
Function.Call(Hash.DECOR_SET_INT, entity.NativeValue, propertyName, intValue);
}
public static void RegisterProperty(string propertyName, DecorationType type)
{
Function.Call(Hash.DECOR_REGISTER, propertyName, (int) type);
}

public static void Set(Entity entity, string propertyName, bool boolValue) {
Function.Call(Hash.DECOR_SET_BOOL, entity.NativeValue, propertyName, boolValue);
}
public static void Set(Entity entity, string propertyName, float floatValue)
{
Function.Call(Hash._DECOR_SET_FLOAT, entity.NativeValue, propertyName, floatValue);
}

public static void Set(Entity entity, string propertyName, int intValue)
{
Function.Call(Hash.DECOR_SET_INT, entity.NativeValue, propertyName, intValue);
}

public static void Set(Entity entity, string propertyName, bool boolValue)
{
Function.Call(Hash.DECOR_SET_BOOL, entity.NativeValue, propertyName, boolValue);
}

public static T Get<T>(Entity entity, string propertyName)
{
if (!ExistOn(entity, propertyName))
{
throw new EntityDecorationUnregisteredPropertyException();
}

Type genericType = typeof(T);
Hash nativeMethod;

if (genericType == floatType)
{
nativeMethod = Hash._DECOR_GET_FLOAT;
}
else if (genericType == intType)
{
nativeMethod = Hash.DECOR_GET_INT;
}
else if (genericType == boolType)
{
nativeMethod = Hash.DECOR_GET_BOOL;
}
else
{
throw new EntityDecorationUndefinedTypeException();
}

public static T Get<T>(Entity entity, string propertyName) {
if (!ExistOn(entity, propertyName)) {
throw new EntityDecorationUnregisteredPropertyException();
}

Type genericType = typeof(T);
Hash nativeMethod;

if (genericType == floatType) {
nativeMethod = Hash._DECOR_GET_FLOAT;
} else if (genericType == intType) {
nativeMethod = Hash.DECOR_GET_INT;
} else if (genericType == boolType) {
nativeMethod = Hash.DECOR_GET_BOOL;
} else {
throw new EntityDecorationUndefinedTypeException();
}

return (T) Function.Call<T>(nativeMethod, entity.NativeValue, propertyName);
return (T) Function.Call<T>(nativeMethod, entity.NativeValue, propertyName);
}
}
}

public class EntityDecorationUnregisteredPropertyException : Exception {}
public class EntityDecorationUndefinedTypeException : Exception {}
public class EntityDecorationUnregisteredPropertyException : Exception { }
public class EntityDecorationUndefinedTypeException : Exception { }
}

0 comments on commit c1cdf55

Please sign in to comment.
You can’t perform that action at this time.