lito
March 25, 2018, 2:27pm
1
CitizenFX.Core.Vehicle has these defined:
public static VehicleHash[] GetAllModels();
public static VehicleHash[] GetAllModelsOfClass(VehicleClass vehicleClass);
Yet i can’t use them, i get a Nullreferenceexception when i try to. Does anyone know why this is?
You said on discord that other people had this issue as well.
Could you make a small reproduction for us? To see if it actually is a bug or not
1 Like
lito
March 25, 2018, 3:33pm
3
This should do it:
class Test : BaseScript
{
private bool firstTick = true;
public Test() {
Tick += OnTick;
}
private async Task OnTick() {
await Delay(0);
if (firstTick) {
firstTick = false;
VehicleHash[] hashArr = Vehicle.GetAllModelsOfClass(VehicleClass.Emergency);
VehicleHash[] hashArr2 = Vehicle.GetAllModels();
}
}
}
This is clearly not working… seems like MemoryAccess.VehicleModels
does not get populated.
I don’t how this is suppose to be assigned, I see multiple pieces of code use it without it actually being assigned
1 Like
Seems like these method should not exist at all, should’ve been removed when porting over scripthook. As I was told by an element
Case closed I guess.
1 Like
lito
March 25, 2018, 4:22pm
7
Ok thanks. You wouldn’t happen to know if there is some other convenient way to get a list of the available vehicles?
lito
March 25, 2018, 8:22pm
8
In the future if someone is looking for this, below is a bit of code one can use to get all the vehicle hashes organized by type:
static Dictionary<VehicleClass, List<VehicleHash>> dict = new Dictionary<VehicleClass, List<VehicleHash>>();
static void BuildDict() {
foreach (VehicleHash vehicleHash in Enum.GetValues(typeof(VehicleHash)))
{
//Debug.WriteLine( vehicleHash +":" + (int)vehicleHash);
Model model = new Model(vehicleHash);
VehicleClass vehicleClass = Vehicle.GetModelClass(model);
List<VehicleHash> list;
if ( dict.TryGetValue(vehicleClass, out list))
{
list.Add(vehicleHash);
}
else {
var newList = new List<VehicleHash>();
newList.Add(vehicleHash);
dict.Add(vehicleClass, newList);
}
}
}
I’m not really sure sure, but I don’t think that hashes list has every vehicle.
lito
March 26, 2018, 2:53pm
10
That is very possible, i wouldn’t know. Do you know of a better way of doing it?
Not really a better way, but in vMenu ive made a list of all vehicles per vehicle class. It’s in the Vehicles.cs source file if you want to grab it.