Server crashing using World3dToScreen2d in c# script


#1

when I call this function
float x = 0, y = 0;
bool toscreen = API.World3dToScreen2d(x1, y1, z1, ref x, ref y);
I’m sure it’s because I’m using the ref

Does anyone have any solution?


#2

Can anybody help me?


#3

are you sure that API.World3dToScreen2d(x1, y1, z1, ref x, ref y); returns a bool?


#4

yes

image


#5

it returns a bool and passes the values of x and y of the screen by ref


#6

Try using GetScreenCoordFromWorldCoord with the same arguments instead of World3dToScreen2d, the native reference seems to have a note about World3dToScreen2d being deprecated.

I.e.

float x = 0.0f;
float y = 0.0f;
bool onScreen = GetScreenCoordFromWorldCoord(posX, posY, posZ, ref y, ref x);

#7

Thanks for the help, but the problem continues.


#8

There’s also another method GetScreenCoordFromWorldCoord2 which does the same thing, have you given that a go?


#9

Not yet, I’m going to test now.


#10

by what I saw, the problem is in the arguments that use the ref


#11

It worked, but it’s not working as it should.
is returning the wrong x and y values
it works, but it’s as if the function had a sleep


#12

Use SetDrawOrigin and ClearDrawOrigin not World3dToScreen2d


#13

I’ve never worked with these two, can you give me an example?


#14

static void Texto3D(float x1, float y1,float z1,string text, int opacidade)
{
SetDrawOrigin(x1, y1, z1, 0);
SetTextScale(0.54f, 0.54f);
SetTextFont(4);
SetTextProportional(true);
SetTextColour(255, 255, 255, opacidade);
SetTextDropshadow(0, 0, 0, 0, opacidade);
SetTextEdge(2, 0, 0, 0, 150);
SetTextDropShadow();
SetTextOutline();
SetTextEntry(“STRING”);
SetTextCentre(true);
AddTextComponentString(text);
DrawText(0, 0);
ClearDrawOrigin();
}

I’m trying to use it this way.

GIF showing how it is


#15

private async Task OnTick()
{
	Render3DText(Game.PlayerPed.Position, "Hello", 0);
	await Delay(0);
}

static void Render3DText(Vector3 coords, string text, int opacidade)
{
	SetTextScale(0.54f, 0.54f);
	SetTextFont(4);
	SetTextProportional(true);
	SetTextColour(255, 255, 255, opacidade);
	SetTextDropshadow(0, 0, 0, 0, opacidade);
	SetTextEdge(2, 0, 0, 0, 150);
	SetTextDropShadow();
	SetTextOutline();
	SetTextCentre(true);

	SetDrawOrigin(coords.x, coords.y, coords.z, 0);
	BeginTextCommandDisplayText("STRING");
	AddTextComponentSubstringPlayerName(text) ;
	EndTextCommandDisplayText(0, 0);
	ClearDrawOrigin();
}

Try this?


#16

is working properly, but … it blinks like you have a sleep, is this normal in c#?

GIF


#17

I solved the problem, I created a loop inside the ontick, I thought this looping would be called several times, plus I was wrong, it was called only once.

I wanted to thank you for helping me, thank you.