Ped HeadShot to image

Hi All!

Currently, I am running a script of mine in which I have a NUI page, (HTML page) where I have a lot of data displayed about a user in-game. I would like to add a Ped headshot. Currently, I am able to get the ped headshot from my client-sided script however, this is a near-impossible task to style and configure as it renders under the HTML container.

Therefore, I would like to return this headshot from the client-side to JQuery and return the ped headshot as an image which I can then attach to a “div”.

The current issues I am facing right now are :

  • Sending the Ped Headshot to the JQuery side to return as an image.
  • Rendering the Ped Headshot until the menu is closed in JQuery.

I’m sorry if this is all a bit confusing, please let me know of any questions you have and I would be more than happy to answer them. Thanks for your help in advance!

1 Like

use base64 images.

I have already taken at look at this reposotory. Not quite sure how it all works. Especially creating a Imgur Client :frowning_face:

You don’t need Imgur. Here is what we use:

Client Script:

internal async Task<string> GetHeadshot(Ped ped)
{
    string texture;
    int timeout = 10;
    int headShot = API.RegisterPedheadshot(ped.Handle);

    while (timeout > 0 && (!API.IsPedheadshotReady(headShot) || !API.IsPedheadshotValid(headShot)))
    {
        timeout--;

        await Delay(200);
    }

    texture = API.GetPedheadshotTxdString(headShot);

    API.UnregisterPedheadshot(headShot);

    return texture;
}

Then pass texture to your NUI through SendNuiMessage().

NUI:

const pictureURL = `https://nui-img/${event.data.texture}/${event.data.texture}?v=${Date.now()}`;

We then use a Canvas, but you can likely just slap the URL into an img tag. Note I’ve cut out the part where we check if texture is an empty string, which means the script could not create a headshot, so you should add a check for that.

1 Like

I see your using c#, I’m working with lua but I think I have a sense of what is going on

Hi, im using this code but the “handle” variable value is always 0

    local playerPed = GetPlayerPed()
    local handle = RegisterPedheadshotTransparent(playerPed)
    if handle == nil or handle == 0 then
        handle = RegisterPedheadshot(playerPed) 
        end
    while not IsPedheadshotReady(handle) do
        Wait(200)
    end
    local txd = GetPedheadshotTxdString(handle)

What should i do?

You need to move your while above your if handle == 0, since the handle will always be 0 right after.

1 Like

Maybe try using PlayerPedId() instead

2 Likes