How do can i display text anywhere on my screen?
-
I wanted to display some text at the bottom right of my screen but i cannot find a function that does this. What do i do?
-
@M8T try this
https://gtaforums.com/topic/966883-c-gtauiworldtoscreen-replacement-needed-past-net-v3/
-
@JohnFromGWN Thats for sprite only i believe
-
@JohnFromGWN this
public void Draw2D(Vector3 position, float size)
{
if (IsDisplay2DOnly)
{
Function.Call(Hash.SET_DRAW_ORIGIN, position.X, position.Y, position.Z, 0);
InfoDisplay2D.Scale = size;
InfoDisplay2D.Caption = "Take";
InfoDisplay2D.Position = new Point(0, 0);
InfoDisplay2D.Draw();
Function.Call(Hash.CLEAR_DRAW_ORIGIN);
}
}
crashes my script on the line that says InfoDisplay2D.Scale = size;
This is how i used it.
Draw2D(new Vector3(2f, 3f, 3f), 1f);
-
@M8T i think the world to screen function is for 2d text as well. Did you look at all the examples in the thread?
-
@JohnFromGWN I think i found it its just it crashes and i dont know how to fix
-
@M8T im sorry I've never had to draw text before but please share your solution when you figure it out. Having said, you are aware there are 3 functions that can display text messages or notifications on the screen with a timer, but AFAIK you can't position them.
https://gtaforums.com/topic/875524-c-display-text-on-screen/
-
@JohnFromGWN and you've read the documentation ?
https://github.com/crosire/scripthookvdotnet/blob/main/source/scripting_v3/GTA.UI/TextElement.cs
-
@M8T I don't know if you figured it out or not, but I found some old code from @ikt which works. Have fun. There is probably a SHVDN way, but this will do the job. Which out for rgb comments, forum stripped out the *.
Function.Call(Hash.SET_TEXT_FONT, 0);
Function.Call(Hash.SET_TEXT_SCALE, 0.0, 0.5f);
Function.Call(Hash.SET_TEXT_COLOUR, 0/r/, 25/g/, 70/b/, 255 /a/);
Function.Call(Hash.SET_TEXT_CENTRE, false);
Function.Call(Hash.SET_TEXT_OUTLINE, true);
Function.Call(Hash.BEGIN_TEXT_COMMAND_DISPLAY_TEXT, "CELL_EMAIL_BCON"); //Used to be known as _SET_TEXT_ENTRY
Function.Call(Hash.ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME, "This is where the text goes on the screen");
Function.Call(Hash.END_TEXT_COMMAND_DISPLAY_TEXT, 0.3, 0.2); //Used to be known as _DRAW_TEXT
-
@JohnFromGWN no worries i found out how but thanks!
-
@M8T Can you please share your code, given nobody else here will help?
-
@JohnFromGWN
var pos = new Point(1100, 689);
testText = new UIText("TAKE", pos, 0.4f, Color.White, GTA.Font.ChaletLondon, true, true, true);
testText.Enabled = true;
testText.Draw();
-
@M8T Wonderful. Much easier to understand than the native functions and more compact. I'll try it and change to DN3 if necessary.
-
@M8T You do realize that SHVDN3 is the current version right? Better to switch now rather than later. Up to you.
DN3 version, last 2 parameters (for anyone interested) are shadow and outline for text.
There is also one last element, which i left out, which is wrapwidth.var pos = new Point(1100, 689);
var testText = new GTA.UI.TextElement("TAKE", pos, 0.4f, Color.White, GTA.UI.Font.ChaletLondon, GTA.UI.Alignment.Center,true,true);
testText.Enabled = true;
testText.Draw();
-
@M8T This worked but the text only lasts like milliseconds then disappeared, any ideas?
-
@nightmareexe You have to use this on loop.
-
@M8T Thanks man!