Resource:DxDraw3DText: Difference between revisions
Jump to navigation
Jump to search
OpenIDUser52 (talk | contribs) (Created page with "{{Resource page}} This resource allowe you to draw 3D-DX texts any where in the game . ==How it works== You only need to use the exported function from the resource '''dxDraw3...") |
(Grammar) |
||
(8 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{Client function}} | ||
This resource | This resource allow you to draw 3D-DX texts any where in the game. You need to add a Text to display only once. | ||
==How it works== | ==How it works== | ||
You | You need to use the exported function called '''dxDraw3DText''' to draw a text in the 3D world. (Use the exported function like this: exports.3d_dx_texts:dxDraw3DText) | ||
==The dxDraw3DText function== | ==The dxDraw3DText function== | ||
Line 31: | Line 30: | ||
===Example=== | ===Example=== | ||
This example will draw a 3D text | This example will draw a 3D text near a player when the resource starts, And destroys it after 5 seconds . | ||
<syntaxhighlight lang="lua">local dxDraw3DText = exports.3D_DX_Texts:dxDraw3DText -- define the function | <syntaxhighlight lang="lua">local dxDraw3DText = exports.3D_DX_Texts:dxDraw3DText -- define the function | ||
Line 45: | Line 44: | ||
end | end | ||
)</syntaxhighlight> | )</syntaxhighlight> | ||
==Notes== | ==Notes== | ||
Line 55: | Line 53: | ||
==Download== | ==Download== | ||
You can download the resource, comment about it, rate it and report any bugs at the community page : [https://community.multitheftauto.com/index.php?p=resources&s=details&id=7613] | You can download the resource, comment about it, rate it and report any bugs at the community page : [https://community.multitheftauto.com/index.php?p=resources&s=details&id=7613] | ||
==Alternative Function== | |||
This alternative function is meant to be used directly with the eventHandler [[onClientRender]]. | |||
===Syntax=== | |||
<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=== | |||
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 : | |||
{{DxFonts}} | |||
*'''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=== | |||
<section name="Client" class="client" show="true"> | |||
<syntaxhighlight lang="lua"> | |||
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); | |||
return true; | |||
end | |||
end | |||
end | |||
</syntaxhighlight> | |||
By: Ceeser | |||
</section> |
Latest revision as of 22:42, 9 January 2018
This resource allow 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 need to use the exported function called dxDraw3DText to draw a text in the 3D world. (Use the exported function like this: exports.3d_dx_texts:dxDraw3DText)
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 [-]
Clientfunction 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); return true; end end end
By: Ceeser