Skip to content

Commit

Permalink
Example of the REGISTER_PEDHEADSHOT native (#763)
Browse files Browse the repository at this point in the history
* Example of the REGISTER_PEDHEADSHOT native

I recently wanted to use this native, which originally had a forum post linked to it, so I just made an example out of it and I believe having it on the native page is better.

---------

Co-authored-by: ammonia-cfx <[email protected]>
  • Loading branch information
Panouklakos and 4mmonium authored Jan 18, 2024
1 parent 3be9128 commit c47690e
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions PED/RegisterPedheadshot.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
ns: PED
---

## REGISTER_PEDHEADSHOT

```c
Expand All @@ -13,10 +14,10 @@ gtaforums.com/topic/885580-ped-headshotmugshot-txd/
```
## Parameters
* **ped**:
* **ped**: The ped you want to take the "headshot" of.
## Return value
The Pedheadshot handle.
It returns a Pedheadshot handle, which can be used by natives such as [GET_PEDHEADSHOT_TXD_STRING](https://docs.fivem.net/natives/?_0xDB4EACD4AD0A5D6B)
## Examples
```lua
Expand All @@ -40,3 +41,32 @@ CreateThread(function()
UnregisterPedheadshot(handle)
end)
```

```js
// This function gets the ped headshot texture and returns an url which can be used in NUI (written in TypeScript)

export const GetPedHeadShotUrl = (ped: number): Promise<string> => {
// We return a Promise so we can async await it, because registering the ped headshot takes some time.

return new Promise(async res => {
const handle = RegisterPedheadshot(ped)

while (!IsPedheadshotReady(handle) || !IsPedheadshotValid(handle)) {
// This is a custom function, not a native, which just returns a promise that is resolved after the ms specified using the setTimeout function
await Delay(10)
}

const txdString = GetPedheadshotTxdString(handle)

// We "unload" the handle as we no longer need it
UnregisterPedheadshot(handle)

// From forum post: https://forum.cfx.re/t/ped-headshot-to-image/4813157/2

const pictureUrl = `https://nui-img/${txdString}/${txdString}?v=${Date.now()}`

// Finally we resolve the Promise!
res(pictureUrl)
})
}
```

0 comments on commit c47690e

Please sign in to comment.