[How To] Using render targets

For people interested in drawing to tvs, billboards… the key here is using render targets.

function CreateNamedRenderTargetForModel(name, model)
	local handle = 0
	if not IsNamedRendertargetRegistered(name) then
		RegisterNamedRendertarget(name, 0)
	end
	if not IsNamedRendertargetLinked(model) then
		LinkNamedRendertarget(model)
	end
	if IsNamedRendertargetRegistered(name) then
		handle = GetNamedRendertargetRenderId(name)
	end

	return handle
end

-- TV in Jimmys room
Citizen.CreateThread(function ()
	local model = GetHashKey("des_tvsmash_start"); -- 2054093856
	local pos = { x = -810.59, y = 170.46, z = 77.25 };
	local entity = GetClosestObjectOfType(pos.x, pos.y, pos.z, 0.05, model, 0, 0, 0)
	local handle = CreateNamedRenderTargetForModel("tvscreen", model)
	while true do
		SetTextRenderId(handle) -- set render target
		Set_2dLayer(4)
		Citizen.InvokeNative(0xC6372ECD45D73BCD, 1)
			DrawRect(0.5, 0.5, 1.0, 0.5, 255, 0, 0, 255); -- WOAH!
		SetTextRenderId(GetDefaultScriptRendertargetRenderId()) -- reset
		Citizen.InvokeNative(0xC6372ECD45D73BCD, 0)
		Citizen.Wait(0)
	end
end)

I’ve put together a repo containing a few basic EXAMPLES to help devs get started.

I’d like to thank @davedumas1, who’s used them in his cinema and bunker scripts and has a provided a list of rendertargets.


cinscreen
npcphone
tvscreen
ex_tvscreen
gr_trailer_monitor_01
gr_trailer_monitor_02
gr_trailer_monitor_03
gr_trailerTV_01
gr_trailerTV_02
prop_clubhouse_laptop_01a
gr_bunker_laptop_01a
Prop_ImpExp_Lappy_01a
prop_ex_computer_screen
clubname_blackboard_01a
memorial_wall_president
memorial_wall_vice_president
memorial_wall_active_01
memorial_wall_active_02
memorial_wall_active_03
clubhouse_table
Prop_Screen_DCTL
prop_ex_computer_screen
prop_ex_office_text
clubhouse_Plan_01a
port_text
starb_text
stern_text
taxi
digiscanner
ECG
blimp_text
ID_Text
ID_Text_02

https://pastebin.com/TwWqDA9U
17 Likes

Why do only certain render target names work for specific objects?

You can usually find them by opening the model files in OpenIV.
So for example this first model uses ‘tvscreen’ as a render target.

This other one uses ‘cinscreen’.

And sometimes you can find some stuff buried in the txds as well.

Any time you draw to that target any other models linked with that name will also be drawn to.

A recent update added 20 separate versions of xm_prop_x17_tv_scrn. Let me know if you get them working.

You can also dig through the decompiled scripts, which can be a huge help. That’s about all I know. :cry:

1 Like

i tried what you did but its not working. I keep getting this error https://gyazo.com/8f8395fedd655795a9c43e4489b085cb

This would help me a lot if i can get the issue resolved

I’m having a lot of troubles with a specific scaleform in the bikers clubhouses…

I’m trying to display the map and missions on the wall but the scaleform doesn’t want to take the whole space!
I copied the way they do it in the decompiled scripts but I just can’t get it to work properly.

It’s appearing entirely but very small and stuck in the upper left corner:

SetTextRenderId(bikerPlanRenderID)
SetUiLayer(4)
N_0xc6372ecd45d73bcd(false)
DrawRect(0.5, 0.5, 1.0, 1.0, 255, 0, 0, 255)
DrawScaleformMovie(bikerPlanMovieID, 0.5, 0.5, 1.0, 1.0, 255, 255, 255, 255, 0)
SetTextRenderId(GetDefaultScriptRendertargetRenderId())

Using a bigger scale, we clearly see the limits of the scaleform:

SetTextRenderId(bikerPlanRenderID)
SetUiLayer(4)
N_0xc6372ecd45d73bcd(false)
DrawRect(0.5, 0.5, 1.0, 1.0, 255, 0, 0, 255)
DrawScaleformMovie(bikerPlanMovieID, 2.0, 2.0, 4.0, 4.0, 255, 255, 255, 255, 0)
SetTextRenderId(GetDefaultScriptRendertargetRenderId())

What am I missing?
The bikerPlanRenderID seems good since I can draw the red rectangle that fits perfectly.
I guess the problem comes from the bikerPlanMovieID but I’m simply calling it as they do in the scripts:

bikerPlanMovieID = RequestScaleformMovie("BIKER_MISSION_WALL")

EDIT:
@throwarray told me to add this native call:
Citizen.InvokeNative(0x40332D115A898AF5, bikerPlanMovieID, true)

and it works now!
It appears that the native was called in the decompiled script but I didn’t see it…

So, writing:

SetTextRenderId(bikerPlanRenderID)
SetUiLayer(4)
N_0xc6372ecd45d73bcd(false)
DrawRect(0.5, 0.5, 1.0, 1.0, 255, 0, 0, 255)
DrawScaleformMovie(bikerPlanMovieID, 0.5, 0.5, 1.0, 1.0, 255, 255, 255, 255, 0)
SetTextRenderId(GetDefaultScriptRendertargetRenderId())

Gives:

2 Likes

From what I can tell the latest hash is N_0xe6a9f00d4240b519 for that one correct? It’s not documented in the nativedb, but it is on the fivem reference page.

That’s what surprised me!

In my decompiled scripts (v1493), it is 0xE6A9F00D4240B519.

Also,

Citizen.InvokeNative(0x40332D115A898AF5, bikerPlanMovieID, true) -- Works fine
Citizen.InvokeNative(0xE6A9F00D4240B519, bikerPlanMovieID, true) -- Works fine
N_0x40332d115a898af5(bikerPlanMovieID, true) -- Function does not exist
N_0xe6a9f00d4240b519(bikerPlanMovieID, true) -- Works fine

I don’t get why we can call what seems to be natives hash from different version?

afaik that’s because of scripthook or something like that. Without that any outdated mod/resource would break if the game updated, and the old natives wouldn’t be resolved to the new one.

Not all unamed natives have an N_… version i think. but i might be wrong about that.

Sadly N_0xe6a9f00d4240b519 does not have a known joaat/console hash so we can’t get the real name.

Oh I see, thanks a lot, it really was buzzing me :smiley:

That’s true. But before using a native, I like to check if it exists in natives_universal.lua. I prefer using its “real name” or at least its N_... name over using Citizen.InvokeNative()

I’m not sure how to actually add missing natives into the fivem source files. Natives reference page is easy if there’s any missing natives, but for the game: not sure. Probably an element that can help with that.

(these ones aren’t missing, but i’ve found a couple that are missing)

Just create a new .md file in the appropriate category with the argument definition.

1 Like

I love how do you know how to put a video youtube for example … :stuck_out_tongue:

how i can setup custom location for hypnonema

Hi, can I take source from CreateCam and put into render target TV?

Has anyone figured out the xm_prop_x17_tv_flat_02 render name?

i’m pretty sure it’s just “tv_flat_01” but not 100% sure

I tried with no luck, but it does mention above A recent update added 20 separate versions of xm_prop_x17_tv_scrn . Let me know if you get them working :thinking:

Friend of mine made a resource that disables static emitters while media is played and will render to your desired entity, rather than every model.

It also allows players to turn on a filter so it sounds like an old school radio, or you can turn on the visualizers and see the audio spectrum move on screen.

The great thing about this is, all of the known render targets have been added already for you.

q

1 Like