Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Contract
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

[C#] Help - check if vehicle is fully electric/hybrid


SYNTHES1SE
 Share

Recommended Posts

I've checked through the natives, and the source of sripthookvdotnet, and there doesnt seem to be a way of checking for this, So before i attempt to gather a list of vehicles that are electric or a hybrid, and check against that list, does anyone have a better way of doing this?

 

This is for my mod Advanced Fuel mod, Im looking to use less fuel for hybrids and no fuel for pure electric vehicles, and then also display a 'charge' bar for vehicles that require it.

Edited by SYNTHES1SE
Link to comment
Share on other sites

I'm 99% sure there won't be a native for that. But, I may be wrong, as I'm not home and can't research.

Link to comment
Share on other sites

yeah, my research didnt show a native for it, to be fair though, i only did a ctrl+F on 'electric' and 'hybrid' - not sure what else it would be under. Thanks anyway.

Link to comment
Share on other sites

I've read into most of the decompiled scripts & the native DB but I'm afraid I have not run across a native that checks the fuel-type. List would be your best option

Link to comment
Share on other sites

thanks, I just had a look through all the vehicle natives and found a lot of cool stuff, but nothing to do with electric vehicles, Seems ill be sticking with a list, at least there are only a small number of cars atm that would be effected.

 

Thanks again :)

Link to comment
Share on other sites

DennisStanistan

thanks, I just had a look through all the vehicle natives and found a lot of cool stuff, but nothing to do with electric vehicles, Seems ill be sticking with a list, at least there are only a small number of cars atm that would be effected.

 

Thanks again :)

You can always take all of the electric vehicle hashes and make a check.

public bool IsVehicleElectric(Vehicle veh){        if (veh.Model == VehicleHash.Voltic)            return true;        else if (veh.Model == VehicleHash.Khamelion)            return true;        else if (veh.Model == VehicleHash.Airtug)            return true;        else return false;}

Same can be done for hybrid cars

public bool IsVehicleHybrid(Vehicle veh){        if (veh.Model == VehicleHash.Zentorno)            return true;        else if (veh.Model == VehicleHash.Turismor)            return true;        else if (veh.Model == VehicleHash.Khamelion)            return true;        else if (veh.Model == VehicleHash.Dilettante)            return true;        else return false;}

Usage:

if(IsVehicleElectric(Game.Player.Character.CurrentVehicle) == true){           // Do something}else if (IsVehicleHybrid(Game.Player.Character.CurrentVehicle) == true){          // Do something}

Have fun.

Edited by DennisStanistan
Link to comment
Share on other sites

DennisStanistan

@Dennis

I would suggest using switch cases instead of if/else ifs. :)

Switch cases, if statements, lists.. whatever it is, It's good for me as long as it works and causes no trouble. :)

Have fun.

Edited by DennisStanistan
Link to comment
Share on other sites

I'd probably initialise a list of vehicles that are hybrids, and a list that are pure electric, so they are super easy to update and then loop through them:

private boolean isElectric(Vehicle currentVehicle){	foreach(VehicleHash hash in electricVehicles)	{			if(currentVehicle.Model == hash)		{			return true;		}	}	return false;}private boolean isHybrid(Vehicle currentVehicle){	foreach(VehicleHash hash in hybridVehicles)	{			if(currentVehicle.Model == hash)		{			return true;		}	}	return false;}

But yeah, looks like theres no native for this. oh well ¯\_(ツ)_/¯

Link to comment
Share on other sites

i doubt there is such native.. however there are not many electric/hybrid vehicles in game, so creating your own list shouldn't be that much of a pain in the a** :-)

 

Anyways, to your code in #9 you will need to break out of the loop else you will always return false.

Link to comment
Share on other sites

 

@Dennis

I would suggest using switch cases instead of if/else ifs. :)

Switch cases, if statements, lists.. whatever it is, It's good for me as long as it works and causes no trouble. :)

Have fun.

It is faster, it does jump instead of comparing.

 

All the best,

Paul.

Link to comment
Share on other sites

DennisStanistan

 

 

@Dennis

I would suggest using switch cases instead of if/else ifs. :)

Switch cases, if statements, lists.. whatever it is, It's good for me as long as it works and causes no trouble. :)

Have fun.

It is faster, it does jump instead of comparing.

 

All the best,

Paul.

 

Yeah I agree.

Link to comment
Share on other sites

i doubt there is such native.. however there are not many electric/hybrid vehicles in game, so creating your own list shouldn't be that much of a pain in the a** :-)

 

Anyways, to your code in #9 you will need to break out of the loop else you will always return false.

 

Actually, if it finds a matching hash in the list, it will return true and exit the function

 

 

 

 

@Dennis
I would suggest using switch cases instead of if/else ifs. :)

Switch cases, if statements, lists.. whatever it is, It's good for me as long as it works and causes no trouble. :)
Have fun.
It is faster, it does jump instead of comparing.

All the best,
Paul.

 

The compiler should optimize this, and a switch statement still compares if the list there is under 5 cases, otherwise the compiler makes a hash table. Either way, any performance hit would not be noticeable.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.