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#] GTA.UI.WorldToScreen replacement needed past .NET V3


THEAETIK
 Share

Recommended Posts

I'm trying to find an alternative for the GTA.UI.WorldToScreen function that was removed a while back. This function immediately crashes my mod on newer versions of .NET past v2.10.10; forcing my users to use this specific .NET version only

 

Quote

"V3.0.0 Removed GTA.UI.WorldToScreen from v2. (impossible to implement due to how the new loader works) Scripts using this method won't work unfortunately."

 

Any pointers appreciated.
Usage: I'm using this function to render UI.DrawTexture over Peds / Vehicles.


 

Edited by THEAETIK
Link to comment
Share on other sites

3 hours ago, THEAETIK said:

I'm trying to find an alternative for the GTA.UI.WorldToScreen function that was removed a while back. This function immediately crashes my mod on newer versions of .NET past v2.10.10; forcing my users to use this specific .NET version only

 

 

Any pointers appreciated.
Usage: I'm using this function to render UI.DrawTexture over Peds / Vehicles.


 

 

You can still wrap this Native with your own function, the Native hasn't been removed, only SHVDN's function. (As far as I know anyway... I still use 2.10.10 so I might be wrong on that)

BOOL GET_SCREEN_COORD_FROM_WORLD_COORD(float worldX, float worldY, float worldZ, float* screenX, float* screenY)

 

Or you can use this as a replacement.

SET_DRAW_ORIGIN(float x, float y, float z, Any p3)

 

This is an example posted by Camxxcore in another thread.

Vector3 boneCoord = somePed.GetBoneCoord(Bone.SKEL_Head);
Function.Call(Hash.SET_DRAW_ORIGIN, boneCoord.X, boneCoord.Y, boneCoord.Z, 0);
Function.Call(Hash.DRAW_SPRITE, "helicopterhud", "hud_corner", -0.01, -0.015, 0.013, 0.013, 0.0, 255, 0, 0, 200);
Function.Call(Hash.DRAW_SPRITE, "helicopterhud", "hud_corner", 0.01, -0.015, 0.013, 0.013, 90.0, 255, 0, 0, 200);
Function.Call(Hash.DRAW_SPRITE, "helicopterhud", "hud_corner", -0.01, 0.015, 0.013, 0.013, 270.0, 255, 0, 0, 200);
Function.Call(Hash.DRAW_SPRITE, "helicopterhud", "hud_corner", 0.01, 0.015, 0.013, 0.013, 180.0, 255, 0, 0, 200);
Function.Call(Hash.CLEAR_DRAW_ORIGIN);

 

Edited by LeeC22
Link to comment
Share on other sites

I assume Draw Origin only works for the native sprites (IE like SET_TEXT_COLOUR). I'd use it in a heartbeat if I wasn't using UI.DrawTexture.
I'm also on 2.10.10, in the V3 update this is what happened:

https://github.com/crosire/scripthookvdotnet/issues/903

 

Quote

Yes. It was impossible to implement that after porting the codebase to C#. So it is the one and only function that had to go. Fortunately there are very little scripts that make use of it.

 

I assume "GET_SCREEN_COORD_FROM_WORLD_COORD" is the derivative.

Not going to lie, I find it baffling that only a few mods are using such and useful function, it appears most people are using GTA's native draw system then.
So then, some whacky hack would be to somehow obtain the DRAWSPRITE 2-point location to use for UI.DrawTexture. :(


Worst case scenario, Is there an online library for all of GTA's sprite textures with images (other than this one)? I know only of the Blips IDs

Edited by THEAETIK
Link to comment
Share on other sites

3 hours ago, THEAETIK said:

I assume Draw Origin only works for the native sprites (IE like SET_TEXT_COLOUR). I'd use it in a heartbeat if I wasn't using UI.DrawTexture.
I'm also on 2.10.10, in the V3 update this is what happened:

 

It works for anything, I use it for UI.Drawtexture, UIText, UIRectangle etc... it simply sets the draw position to 0,0 at that 3D coordinate on the screen. It actually makes things much easier because you are always drawing at a position relative to the size of the thing you are drawing. So a 40 x 20 rectangle is centered by drawing it at -20, -10.

 

I have an info system that can either be 3D which uses a scaleform, or 2D which uses a UIText. This is the 2D code. InfoDisplay2D is a UIText.

 

public void Draw2D(Vector3 position, float size)
{
    if (IsDisplay2DOnly)
    {
        Function.Call(Hash.SET_DRAW_ORIGIN, position.X, position.Y, position.Z, 0);
        InfoDisplay2D.Scale = size;
        InfoDisplay2D.Caption = Text;
        InfoDisplay2D.Position = new Point(0, 0);
        InfoDisplay2D.Draw();
        Function.Call(Hash.CLEAR_DRAW_ORIGIN);
    }
}

 

Not sure about the online library, I simply exported all the images from script_txds.rpf into folders. This is an rpf you can also add your own ytd file to and then draw the sprites with either the Native sprite functions, or the SHVDN UISprite class.

 

Edit: Crap... I was sure I had used this for UI.Drawtexture() but it doesn't seem to work. Really sorry about that, I should have re-checked before I said so. :blush:

 

Edit: This works with SHVDN 3.0 as a V2.0 script function:

 

private unsafe Point GetScreenCoordFromWorldCoord(Vector3 worldCoord)
{
    float x;
    float y;

    // GET_SCREEN_COORD_FROM_WORLD_COORD
    Function.Call((Hash)0x34E82F05DF2974F5, worldCoord.X, worldCoord.Y, worldCoord.Z, &x, &y);

    return new Point((int)(UI.WIDTH * x), (int)(UI.HEIGHT * y));
}

 

That was in a test script built against 2.10.10 running with 2.10.13 in release 3.0.4

Edited by LeeC22
Link to comment
Share on other sites

Just been tinkering with the source for the latest SHVDN. I have a build that puts V2 back to .Net 4.5.2 as a test to try some of my mods against it. All my mods are built against 4.5.2 and when you have close to 300 mods, many of them library or shared function mods, you don't just rebuild everything because of a .net change for no good reason. I don't care about v3, I will never use it. But I digress...

 

What shocked me was that not only did they remove that function but they didn't do the seemingly obvious solution of moving it into a different Namespace to ensure it was still available. I have just added a version of the function above into the World namespace, which means you can do World.GetScreenCoordFromWorldCoord(coord) and it quite happily returns a PointF with the screen ratios. Why didn't they do that? If I add a couple of consts for WIDTH and HEIGHT, it could return a Point with the actual screen coords instead, I just did a simple test to check if it worked.

 

Yes that would still result in broken mods but it would only require a simple namespace change to get them working again. Instead people have to create their own function to do it and then build that into an extension class if they want it in several mods.

 

I have re-wrapped a lot of the SHVDN functionality now and just use SHVDN as a simple Function.Call library. I can guarantee things work by doing that.

Edited by LeeC22
Link to comment
Share on other sites

  • 2 weeks later...

Thanks for your help, LeeC22
 

You are correct, the replacement works perfectly well on V2 from V3,

But I'm extremely baffled. I wouldn't say I have the largest mod but I do use many function. I've noticed all kinds of weirdness. While the code compiles properly and everything without a single error; the Hydra landing gear function is suddenly broken, but more importantly, my enemies are dying in one hit, I was starting to grab my hair hoping it was just V2 from V3.

So, compile from V2, and Compile using V2 on V3... every enemy dies in one hit. I revert my GTA scripthook to v2.10.10 and the weirdness goes away.

I'm so out of this at this point. Too bad. Makes me wish they had stopped development at v2.10.10 honestly.

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.