DxDrawRectangleOnElement: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Useful Function}} __NOTOC__ This function draws 3D rectangles above the player.<br> * '''NOTE:''' The structure of the code was made based on the greenzone tag resource!. =...")
 
(Blanked the page)
Tag: Blanking
 
Line 1: Line 1:
{{Useful Function}}
__NOTOC__
This function draws 3D rectangles above the player.<br>
* '''NOTE:''' The structure of the code was made based on the greenzone tag resource!.


==Syntax==
<syntaxhighlight lang="lua">bool dxDrawRectangleOnPlayer ( float x, float y, float width, float height, int color )</syntaxhighlight>
===Required Arguments===
* '''X:''' The x position of the rectangle.
* '''Y:''' The y position of the rectangle.
* '''WIDTH:''' The width of the rectangle.
* '''HEIGHT:''' The width of the rectangle.
* '''COLOR:''' The color of the rectangle using tocolor.
===Returns===
Returns a ''true'' if the operation was successful, ''false'' otherwise.
==Code==
<section name="Clientside script" class="client" show="true">
<syntaxhighlight lang="lua">
function dxDrawRectangleOnPlayer(x, y, width, height, color)
  local players = getElementsByType("player", root, true)
  if players then
  local x, y, z = getElementPosition(localPlayer)
for _, v in ipairs(players) do
    if v and isElement(v) then
local px, py, pz = getElementPosition(v)
if getDistanceBetweenPoints3D(x, y, z, px, py, pz) <= 20 then
  local sx, sy = getScreenFromWorldPosition(px, py, pz + 1.3)
  if sx and sy then
  dxDrawRectangle(sx + x, sy + y/1.6, width, height, color, false)
                end
            end
        end
    end
end
end
</syntaxhighlight>
</section>
==Example==
This example draws 2 rectangles above the player
<syntaxhighlight lang="lua">
local sx, sy = guiGetScreenSize()
function t()
  dxDrawRectangleOnPlayer(sx * 0.5300, sy * 0.0500, sx * 0.0800, sy * 0.0600, tocolor(255, 0, 0, 255))
  dxDrawRectangleOnPlayer(sx * 1.0000, sy * 0.0500, sx * 0.0300, sy * 0.0600, tocolor(255, 167, 0, 255))
end
addEventHandler("onClientRender", root, t)
</syntaxhighlight>
Author: Hydra
==See Also==
{{Useful_Functions}}

Latest revision as of 19:34, 26 October 2021