Jump to content

[Question]Triggering DX elements on marker hit


kieran

Recommended Posts

Hello, I am creating a simple script to show a DX rectangle and text when a player hits a marker, it is for a vehicle system but I can do all but keep the DX box showing.

It flashes up when you hit the marker then it just vanishes...  I don't know why and I am struggling to understand why it just stays for a second then goes away, the code is below. :)

Server

--Make the markers
	CarSpawn = createMarker (1682.8740234375, -2326.5634765625, 12.5, "cylinder", 1.5, 0, 50, 150, 200)
--When the player hits the marker trigger an event to create a GUI
function FreeCars (hitElement, matchingDimension)
	if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension and isPedOnGround ( hitElement ) then
		triggerClientEvent("showfreecar", hitElement)--This shows, then vanishes... 
	else
		outputChatBox("You need to be on foot", hitElement, 230, 102, 103)
	end
end

addEventHandler("onMarkerHit", CarSpawn, FreeCars)
--still to make all the spawn stuff and system to check spawned vehicles, but this is relatively easy.

Client


function FreeCarGUI()
    dxDrawLine(307 - 1, 458 - 1, 307 - 1, 590, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine(493, 458 - 1, 307 - 1, 458 - 1, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine(307 - 1, 590, 493, 590, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine(493, 590, 493, 458 - 1, tocolor(0, 0, 0, 255), 1, false)
    dxDrawRectangle(307, 458, 186, 132, tocolor(12, 49, 206, 152), false)
    dxDrawText("1. Sanchez", 323 - 1, 473 - 1, 476 - 1, 510 - 1, tocolor(234, 242, 18, 111), 2.50, "default", "left", "top", false, false, false, false, false)
    dxDrawText("1. Sanchez", 323 + 1, 473 - 1, 476 + 1, 510 - 1, tocolor(234, 242, 18, 111), 2.50, "default", "left", "top", false, false, false, false, false)
    dxDrawText("1. Sanchez", 323 - 1, 473 + 1, 476 - 1, 510 + 1, tocolor(234, 242, 18, 111), 2.50, "default", "left", "top", false, false, false, false, false)
    dxDrawText("1. Sanchez", 323 + 1, 473 + 1, 476 + 1, 510 + 1, tocolor(234, 242, 18, 111), 2.50, "default", "left", "top", false, false, false, false, false)
    dxDrawText("1. Sanchez", 323, 473, 476, 510, tocolor(0, 0, 0, 172), 2.50, "default", "left", "top", false, false, false, false, false)
end
addEvent("showfreecar", true)
addEventHandler("showfreecar", root, FreeCarGUI)

Thank you for any help. :D  I used Remp's GUI editor for this, I am very bad with DX elements. :/

Edited by kieran
Link to comment
On 10/4/2017 at 14:26, IIYAMA said:

Please read the first sentence of the dx function page: https://wiki.multitheftauto.com/wiki/DxDrawLine

Thanks, but um...   The whole point is that it shows the panel then destroys it when you leave, I know how to destroy elements and set a GUI's visibility, but how can I destroy a Dx element...?

Here is updated code (change names so makes more sense)

Client

Spoiler

function Panel()
    dxDrawLine(307 - 1, 458 - 1, 307 - 1, 590, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine(493, 458 - 1, 307 - 1, 458 - 1, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine(307 - 1, 590, 493, 590, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine(493, 590, 493, 458 - 1, tocolor(0, 0, 0, 255), 1, false)
    dxDrawRectangle(307, 458, 186, 132, tocolor(12, 49, 206, 152), false)
    dxDrawText("1. Sanchez", 323 - 1, 473 - 1, 476 - 1, 510 - 1, tocolor(234, 242, 18, 111), 2.50, "default", "left", "top", false, false, false, false, false)
    dxDrawText("1. Sanchez", 323 + 1, 473 - 1, 476 + 1, 510 - 1, tocolor(234, 242, 18, 111), 2.50, "default", "left", "top", false, false, false, false, false)
    dxDrawText("1. Sanchez", 323 - 1, 473 + 1, 476 - 1, 510 + 1, tocolor(234, 242, 18, 111), 2.50, "default", "left", "top", false, false, false, false, false)
    dxDrawText("1. Sanchez", 323 + 1, 473 + 1, 476 + 1, 510 + 1, tocolor(234, 242, 18, 111), 2.50, "default", "left", "top", false, false, false, false, false)
    dxDrawText("1. Sanchez", 323, 473, 476, 510, tocolor(0, 0, 0, 172), 2.50, "default", "left", "top", false, false, false, false, false)
end


function ShowPanel ( )
    addEventHandler ( "onClientRender", root, Panel )
end

addEvent("showmenu", true)
addEventHandler("showmenu", root, ShowPanel)

function HidePanel ( )
    --How can I delete the Dx elements?
end

addEvent("hidemenu", true)
addEventHandler("hidemenu", root, HidePanel)

 

Server

Spoiler

Spawn = createMarker (1682.8740234375, -2326.5634765625, 12.5, "cylinder", 1.5, 0, 50, 150, 200)

function ShowPanel (hitElement, matchingDimension)
	if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension and isPedOnGround ( hitElement ) then
		triggerClientEvent("showmenu", hitElement)
	else
		outputChatBox("You need to be on foot", hitElement, 230, 102, 103)
	end
end

addEventHandler("onMarkerHit", Spawn, ShowPanel)


function DestroyPanel (hitElement, matchingDimension)
	if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension and isPedOnGround ( hitElement ) then
		triggerClientEvent("hidemenu", hitElement)
	end
end

addEventHandler("onMarkerLeave", Spawn, DestroyPanel)

 

Thanks for help

Link to comment
  • Discord Moderators

DX are not elements like the GUI elements which you create and destroy. Instead you call a function to draw something for 1 frame. 1 frame is not a very long time when you have 60 frames per second, so you use the event onClientRender to call the DX function every frame.

In your code, use removeEventHandler to stop calling this function every frame.

function HidePanel ( )
    removeEventHandler ( "onClientRender", root, Panel )
end

 

Link to comment
10 minutes ago, Zango said:

DX are not elements like the GUI elements which you create and destroy. Instead you call a function to draw something for 1 frame. 1 frame is not a very long time when you have 60 frames per second, so you use the event onClientRender to call the DX function every frame.

In your code, use removeEventHandler to stop calling this function every frame.


function HidePanel ( )    removeEventHandler ( "onClientRender", root, Panel )end

 

Thanks, that's so simple xD sorry, this is my first time doing Dx drawing that needs to go when you leave marker, helped a lot :)

Edited by kieran
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...