Resource:DxDraw3DText: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 58: Line 58:




==Alternative Function==
===Alternative Function===
This alternative function is meant to be used directly with the eventHandler [[onClientRender]].
This alternative function is meant to be used directly with the eventHandler [[onClientRender]].


===Syntax===
===Syntax===
<syntaxhighlight lang="lua">element dxDraw3DText( string text, int x, int y, int z [, int scale = 2, string font = "default", int color = white, int maxDistance = 12, bool colorCoded = false ] )</syntaxhighlight>
<syntaxhighlight lang="lua">bool dxDraw3DText( string text, int x, int y, int z [, int scale = 2, string font = "default", int color = white, int maxDistance = 12, bool colorCoded = false ] )</syntaxhighlight>


===Returns===
===Returns===
The function displays a ''text'' if successfule, ''false'' otherwise.
The function return ''true'' and displays a ''text'' if successful, ''false'' otherwise.


===Required Arguments===
===Required Arguments===

Revision as of 22:04, 26 October 2017

This resource allowe you to draw 3D-DX texts any where in the game. You need to add a Text to display only once.


How it works

You only need to use the exported function from the resource dxDraw3DText and draw the text . ( To use the exported function use call function ) .


The dxDraw3DText function

Syntax

element dxDraw3DText( string text, int x, int y, int z [, int scale = 2, string font = "default", int r = 255, int g = 255, int b = 255, int maxDistance = 12 ] )

Required Arguments

  • text : A string representing the text you wish to draw .
  • x, y, z : Three integers representing the world coordinates of where you want the text to be .

Optional Arguments

  • scale : An int representing the size of the font .
  • font : A string representing the font type, This CAN'T be a DX font element, It can ONLY be :
    • "default": Tahoma
    • "default-bold": Tahoma Bold
    • "clear": Verdana
    • "arial": Arial
    • "sans": Microsoft Sans Serif
    • "pricedown": Pricedown (GTA's theme text)
    • "bankgothic": Bank Gothic Medium
    • "diploma": Diploma Regular
    • "beckett": Beckett Regular
    • "unifont": Unifont
  • r, g, b : Three integers representing the RGB Color codes for the text .
  • maxDistance : An int representing the max distance the text will show in .


Returns

The function returns a text element if successfule, false otherwise .

Example

This example will draw a 3D text near a player when the resource starts, And destroys it after 5 seconds .

local dxDraw3DText = exports.3D_DX_Texts:dxDraw3DText -- define the function

addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ),
	function( )
		local x, y, z = getElementPosition( getLocalPlayer( ) ) -- getting the player coordinates
		local playerName = getPlayerName( getLocalPlayer( ) ) -- getting the player name
		local theText = dxDraw3DText( "Welcome " .. playerName, x, y, z ) -- dtawing the text
		if theText then -- if it was drawn
			setTimer( destroyElement, 5000, 1, theText ) -- set a time to destroy it after 5 seconds
		end
	end
)

Notes

  • The dxDraw3DText function is client side only .
  • The dxDraw3DText function doesn't need the onClientRender event to work .
  • The dxDraw3DText function only creates a text element, The drawing and stuff is done in the resource, So it MUST be running so the texts show .


Download

You can download the resource, comment about it, rate it and report any bugs at the community page : [1]



Alternative Function

This alternative function is meant to be used directly with the eventHandler onClientRender.

Syntax

bool dxDraw3DText( string text, int x, int y, int z [, int scale = 2, string font = "default", int color = white, int maxDistance = 12, bool colorCoded = false ] )

Returns

The function return true and displays a text if successful, false otherwise.

Required Arguments

  • text : A string representing the text you wish to draw .
  • x, y, z : Three integers representing the world coordinates of where you want the text to be .

Optional Arguments

  • scale : An int representing the size of the font .
  • font : A string representing the font type, This CAN'T be a DX font element, It can ONLY be :
    • "default": Tahoma
    • "default-bold": Tahoma Bold
    • "clear": Verdana
    • "arial": Arial
    • "sans": Microsoft Sans Serif
    • "pricedown": Pricedown (GTA's theme text)
    • "bankgothic": Bank Gothic Medium
    • "diploma": Diploma Regular
    • "beckett": Beckett Regular
    • "unifont": Unifont
  • color: the color of the text, a value produced by tocolor or 0xAARRGGBB (AA = alpha, RR = red, GG = green, BB = blue).
  • maxDistance : An int representing the max distance the text will show in .
  • colorCoded : Set to true to enable embedded #FFFFFF color codes. Note: clip and wordBreak are forced false if this is set.

Code

Click to collapse [-]
Client
function dxDraw3DText(text, x, y, z, scale, font, color, maxDistance, colorCoded)
	if not (x and y and z) then
		outputDebugString("dxDraw3DText: One of the world coordinates is missing", 1)
		return false;
	end

	if not (scale) then
		scale = 2;
	end
	
	if not (font) then
		font = "default";
	end
	
	if not (color) then
		color = tocolor(255, 255, 255, 255);
	end
	
	if not (maxDistance) then
		maxDistance = 12;
	end
	
	if not (colorCoded) then
		colorCoded = false;
	end
	
	local pX, pY, pZ = getElementPosition( localPlayer );	
	local distance = getDistanceBetweenPoints3D(pX, pY, pZ, x, y, z);
	
	if (distance <= maxDistance) then
		local x, y = getScreenFromWorldPosition(x, y, z);
		
		if (x and y) then
			dxDrawText( text, x, y, _, _, color, scale, font, "center", "center", false, false, false, colorCoded);
		end
	end
end

By: Ceeser