Log in to reply
 

Any ideas how to get this nameplate to appear on ALL Pedestrians?



  • In this video, I wanted to assign unique names to the pedestrians in GTA5, and also, when in the line of sight, to flash that name over their head in a fashion similar to Worlds of Warcraft.

    I used "Scaleforms" along with Script Hook .net and C# to achieve the desired effect. While my first efforts involved trying to achieve the effect for ALL Pedestrians JUST LIKE Worlds of Warcraft or Everquest, there's an inbuilt limitation to the use of the Scaleform I used - SET_PLAYER_NAME, which only allows one to be displayed at any given time. Trying to create multiple scale forms leveraging this method resulted in a flickering effect with most of the peds names not visible.

    While the Proof of Concept works, it still needs tweaking with the sensitivity of the raycast picking up whoever (or whatever) is standing in front of my avatar.

    I found a web site that provided me a list of 4000 male and 4000 female names, which i then assign uniquely to each pedestrian based on an algorithm defined by the only way I have to uniquely identify each one - their handle....

    My goal is to get a solid name plate over EACH Pedestrian.....

    IF ANYONE has any ideas on how to resolve this issue or a different approach to an always on thing, please let me know!



  • @TimelordQ

    This will draw pString above every ped in debugPeds, can easily be modfied to achieve what you are after.

    foreach (Ped p in debugPeds.ToList())
                {
    
                    if (p != null && p.Exists())
                    {
                        if (p.IsOnScreen && p.IsVisible)
                        {
    
                            bool allowed = false;
                            if (!CheckIfPedUsed(p, true, true)) allowed = true;
                            string pString = SetPedDebugtext(p, allowed);
                            Vector2 tPos = World3DToScreen2d(new Vector3(p.GetBoneCoord(Bone.FB_Brow_Centre_000).X, p.GetBoneCoord(Bone.FB_Brow_Centre_000).Y, p.GetBoneCoord(Bone.FB_Brow_Centre_000).Z + 0.5f));
    
                            //Size size = Game.ScreenResolution;
                            tPos.X = 1280 * tPos.X;
                            tPos.Y = 720 * tPos.Y;
    
                            UIText pedInfo = new UIText(pString, new Point((int)tPos.X, (int)tPos.Y), 0.2f, Color.WhiteSmoke, 0, true, true, true);
                            pedInfo.Draw();
                        }
                    }
                    else
                    {
                        debugPeds.Remove(p);
                    }
                }
    

    You could adjust the scale based on distance from the player.
    Here is my World3DtoScreen function.

    public static Vector2 World3DToScreen2d(Vector3 pos)
            {
                OutputArgument x2dp = new OutputArgument();
                OutputArgument y2dp = new OutputArgument();
    
                Function.Call(Hash._0x34E82F05DF2974F5, pos.X, pos.Y, pos.Z, x2dp, y2dp); //GET_SCREEN_COORD_FROM_WORLD_COORD
                return new Vector2(x2dp.GetResult<float>(), y2dp.GetResult<float>());
            }
    

    I use it for debug purposes and i see no flickering with 100 or so peds. 1280x720 seems to be what r* use for drawing this type of text and scale it upto what ever resolution the game is running at. Any other numbers produces weird results.



  • Yeah. I've seen your approach on other web sites and I've also seen videos of this effect which are less than optimal. Between scaling issues and lag resulting in imperfect movement and 3D scaling of the text, I'm really not interested in that approach and prefer the projected approach into the 3D environment like I'm currently doing.

    Now If you have a true 3D method that aligns with my approach without relying on World 3D to screen 2D mathematics, I'd love to hear it!

    Thank you for the input though!


  • MODERATOR

    This might or might not be the answer to your question within your parameters at all, but you can use SET_DRAW_ORIGIN/CLEAR_DRAW_ORIGIN to draw 2D stuff at 3D coords.

    An example, code I use for some debugging stuff:

    void showDebugInfo3D(Vector3 location, float baseSize, const std::vector<std::string> &textLines, Color backgroundColor, Color fontColor) {
        Vector3 cameraPos = CAM::GET_GAMEPLAY_CAM_COORD();
        float distance = Distance(cameraPos, location);
        float totalMult = baseSize / (distance * (CAM::GET_GAMEPLAY_CAM_FOV() / 60.0f));
    
        float height = 0.0125f * totalMult;
    
        GRAPHICS::SET_DRAW_ORIGIN(location.x, location.y, location.z, 0);
        int i = 0;
    
        float szX = 0.000f;
        for (auto line : textLines) {
            float currWidth = getStringWidth(line, 0.2f* totalMult, 0);
            showText(0.0f, 0.0f + height * i, 0.2f * totalMult, line, 0, fontColor, true);
            if (currWidth > szX)
                szX = currWidth;
            i++;
        }
    
        float szY = height * i;
        GRAPHICS::DRAW_RECT(0.0f + szX/2.0f, (height * i) / 2.0f, szX, szY,
            backgroundColor.R, backgroundColor.G, backgroundColor.B, backgroundColor.A);
        GRAPHICS::CLEAR_DRAW_ORIGIN();
    }
    

    Where ShowText() and the rectangle draws are simply 2D on-screen draws - but using (0,0) within the SET_DRAW_ORIGIN block draws them at the desired coordinate (if on-screen) as if they're in 3D, though you'll have to scale the thing yourself to get it appear properly at distance and zoom levels.

    This can be called for many entities though you will run into the limitation of how much text can be drawn at a time.

    For the scaleform answer - I don't know. You could try looking at how some other mods (garage mods?) draw multiple vehicle info.


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.