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

    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
      4. Frontier Pursuits
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Diamond Casino & Resort
      2. DLC
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA IV Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA SA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA VC Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA III Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

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

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

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

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

    2. Forum Support

    3. Site Suggestions

Sign in to follow this  
SYNTHES1SE

[C#] problem getting model dimensions

Recommended Posts

SYNTHES1SE

Hi All,

 

I've written a function that returns a vehicles dimensions as follows:

public GTA.Math.Vector3 getModelSize(bool getMaxSize){    Hash modelHash = Function.Call<Hash>(Hash.GET_ENTITY_MODEL, vehicle);    GTA.Math.Vector3 maxSize = new GTA.Math.Vector3();    GTA.Math.Vector3 minSize = new GTA.Math.Vector3();    Function.Call(Hash.GET_MODEL_DIMENSIONS, modelHash, minSize, maxSize);                if(getMaxSize)    {         return maxSize;    }    return minSize;}

However, Visual Studio is telling me:

 

The best overloaded method match for 'GTA.Native.Function.Call(GTA.Native.Hash, params GTA.Native.InputArgument[])' has some invalid arguments

 

according to the native DB the function is to be used as follows:

void GET_MODEL_DIMENSIONS(Hash modelHash, Vector3 *minimum, Vector3 *maximum)

I don't see why its complaining. Can anybody see what im doing wrong?

Share this post


Link to post
Share on other sites
Jitnaught
public GTA.Math.Vector3 getModelSize(bool getMaxSize)        {            Hash modelHash = Function.Call<Hash>(Hash.GET_ENTITY_MODEL, vehicle);            OutputArgument maxSize = new OutputArgument();            OutputArgument minSize = new OutputArgument();            Function.Call(Hash.GET_MODEL_DIMENSIONS, (int)modelHash, minSize, maxSize);            if (getMaxSize) return maxSize.GetResult<Vector3>();            return minSize.GetResult<Vector3>();        }

Hash can't be converted to InputArgument so you need to cast it as an int first.

For variables that will be outputted you need to use OutputArgument and then get the result after.

Share this post


Link to post
Share on other sites
frodzet

why would you use native functions to get model dimensions when there is a build in function for it in ScriptHookVDotNet:

 

Vector3 vehicleDimensions = vehicle.Model.GetDimensions();

Share this post


Link to post
Share on other sites
SYNTHES1SE
public GTA.Math.Vector3 getModelSize(bool getMaxSize)        {            Hash modelHash = Function.Call<Hash>(Hash.GET_ENTITY_MODEL, vehicle);            OutputArgument maxSize = new OutputArgument();            OutputArgument minSize = new OutputArgument();            Function.Call(Hash.GET_MODEL_DIMENSIONS, (int)modelHash, minSize, maxSize);            if (getMaxSize) return maxSize.GetResult<Vector3>();            return minSize.GetResult<Vector3>();        }

Hash can't be converted to InputArgument so you need to cast it as an int first.

For variables that will be outputted you need to use OutputArgument and then get the result after.

 

 

Thank you so much! I love this community and how much im constantly learning!

 

 

why would you use native functions to get model dimensions when there is a build in function for it in ScriptHookVDotNet:

 

Vector3 vehicleDimensions = vehicle.Model.GetDimensions();

Oh, i guess i missed that :p, not sure if this gets max dimensions, min dimensions or current dimesnions though. Thanks anyway, next time ill be sure to check the built in functions :)

Share this post


Link to post
Share on other sites
Jitnaught

This is the what the GetDimensions() function does

// GTA.Modelpublic Vector3 GetDimensions(){	Vector3 right = default(Vector3);	Vector3 left = default(Vector3);	this.GetDimensions(ref right, ref left);	return Vector3.Subtract(left, right);}

the "right" variable is the minimum, the "left" variable is the maximum.

Share this post


Link to post
Share on other sites
SYNTHES1SE

This is the what the GetDimensions() function does

// GTA.Modelpublic Vector3 GetDimensions(){	Vector3 right = default(Vector3);	Vector3 left = default(Vector3);	this.GetDimensions(ref right, ref left);	return Vector3.Subtract(left, right);}

the "right" variable is the minimum, the "left" variable is the maximum.

 

So it just gets the difference between the smallest and biggest size of the model? Thats interesting, not massively useful. What is massively useful however is the source to scripthookvdotnet. I didnt know it was open, that helps a ton! Thanks :)

Share this post


Link to post
Share on other sites
SYNTHES1SE
public GTA.Math.Vector3 getModelSize(bool getMaxSize)        {            Hash modelHash = Function.Call<Hash>(Hash.GET_ENTITY_MODEL, vehicle);            OutputArgument maxSize = new OutputArgument();            OutputArgument minSize = new OutputArgument();            Function.Call(Hash.GET_MODEL_DIMENSIONS, (int)modelHash, minSize, maxSize);            if (getMaxSize) return maxSize.GetResult<Vector3>();            return minSize.GetResult<Vector3>();        }

Hash can't be converted to InputArgument so you need to cast it as an int first.

For variables that will be outputted you need to use OutputArgument and then get the result after.

 

 

Tried it out, Doesnt seem to work. Getting the following error:

[22:03:48] [ERROR] Caught fatal unhandled exception:System.InvalidCastException: Unable to cast native value to object of type 'GTA.Native.Hash'   at GTA.Native.GetResult(Type type, UInt64* value)   at GTA.Native.Function.Call[T](UInt64 hash, InputArgument[] arguments)   at Advanced_Fuel_Mod.FuelledVehicle.getModelSize(Boolean getMaxSize)   at Advanced_Fuel_Mod.AdvancedFuelMod.OnTick(Object sender, EventArgs e)   at GTA.Script.MainLoop()

Investigating the issue, but if you know what the problem is, id love some help :)

Share this post


Link to post
Share on other sites
Jitnaught

Try this instead

public GTA.Math.Vector3 getModelSize(bool getMaxSize)        {            VehicleHash modelHash = Function.Call<VehicleHash>(Hash.GET_ENTITY_MODEL, vehicle);            OutputArgument maxSize = new OutputArgument();            OutputArgument minSize = new OutputArgument();            Function.Call(Hash.GET_MODEL_DIMENSIONS, (uint)modelHash, minSize, maxSize);            if (getMaxSize) return maxSize.GetResult<Vector3>();            return minSize.GetResult<Vector3>();        }

Share this post


Link to post
Share on other sites
SYNTHES1SE

 

Try this instead

public GTA.Math.Vector3 getModelSize(bool getMaxSize)        {            VehicleHash modelHash = Function.Call<VehicleHash>(Hash.GET_ENTITY_MODEL, vehicle);            OutputArgument maxSize = new OutputArgument();            OutputArgument minSize = new OutputArgument();            Function.Call(Hash.GET_MODEL_DIMENSIONS, (uint)modelHash, minSize, maxSize);            if (getMaxSize) return maxSize.GetResult<Vector3>();            return minSize.GetResult<Vector3>();        }

Thanks :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • 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.