Jump to content

onMarkerHit shows the DX Rectangle & Lines only for a second


thund3rbird23

Recommended Posts

Posted

I did a simple modal with the guieditor (dxDrawText,dxDrawLine,dxDrawRectangle).

And I want to show that modal when player hit the marker and hide when leaves the marker.

This works, but shows the modal only for a second... how can I keep show the modal as long as the player is in the marker?

local szuretMarker = createMarker(-1003.563659668, -1249.7315673828, 130.26364135742, 'cylinder', 2.0, 255, 0, 0, 150)

function MarkerHit( hitElement, matchingDimension )
    local elementType = getElementType( hitElement )
     triggerClientEvent ( "szuret", getRootElement(), szureteles )
end
addEventHandler( "onMarkerHit", szuretMarker, MarkerHit )

 

Posted

Hy! You have to put the dx functions in an onClientRender event. dx draws only live for a frame, therefor you have to draw them on every frame. That's what the onClientRender event does.

If you need further help, send me a PM and I'll help in hungarian.

Posted

I would use this:

local marker = createMarker (0, 0, 0, "cylinder", 1.5, 255, 255, 0, 170 )

function playerJoinMarker()
	addEventHandler("onClientRender", getRootElement(), drawMarkerPanel)
end
addEventHandler( "onMarkerHit", marker, playerJoinMarker)

function drawMarkerPanel()
	--YOU CAN DRAW HERE YOUR PANEL, ALSO, ADD A CLOSE BUTTON WHICH REMOVE THE onClientRender EVENT
end

 

Posted (edited)
3 hours ago, AlvarO said:

I would use this:


local marker = createMarker (0, 0, 0, "cylinder", 1.5, 255, 255, 0, 170 )

function playerJoinMarker()
	addEventHandler("onClientRender", getRootElement(), drawMarkerPanel)
end
addEventHandler( "onMarkerHit", marker, playerJoinMarker)

function drawMarkerPanel()
	--YOU CAN DRAW HERE YOUR PANEL, ALSO, ADD A CLOSE BUTTON WHICH REMOVE THE onClientRender EVENT
end

 

@thund3rbird23 You cant do it like this, because your script is serverside.
Add the onClientRender event clientside in the function that get triggered by your event.

Edited by Ceeser
  • 4 weeks later...
Posted

-- Serverside

local szuretMarker = createMarker(-1003.563659668, -1249.7315673828, 130.26364135742, 'cylinder', 2.0, 255, 0, 0, 150)

function MarkerHit( hitElement, matchingDimension )
  if matchingDimension then
    	triggerClientEvent (hitElement, "szuret", hitElement )
    end
end
addEventHandler( "onMarkerHit", szuretMarker, MarkerHit )
addEventHandler( "onMarkerLeave", szuretMarker, MarkerHit)

-- Clientside

addEvent('szuret',true)
addEventHandler('szuret',getRootElement(),
	function()
		if not addEventHandler('onClientRender',getRootElement(),showDX) then
		   addEventHandler('onClientRender',getRootElement(),showDX)
		else
		   removeEventHandler('onClientRender',getRootElement(),showDX)
		end
	end
)

function showDX()
   --dxDrawRectangle() for example
end

function isEventHandlerAdded( sEventName, pElementAttachedTo, func ) -- Useful function
     if type( sEventName ) == 'string' and isElement( pElementAttachedTo ) and type( func ) == 'function' then
          local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo )
          if type( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then
               for i, v in ipairs( aAttachedFunctions ) do
                    if v == func then
        	         return true
        	    end
	       end
	  end
     end
     return false
end

Not tested

Posted
7 hours ago, Rut said:

-- Serverside


local szuretMarker = createMarker(-1003.563659668, -1249.7315673828, 130.26364135742, 'cylinder', 2.0, 255, 0, 0, 150)

function MarkerHit( hitElement, matchingDimension )
  if matchingDimension then
    	triggerClientEvent (hitElement, "szuret", hitElement )
    end
end
addEventHandler( "onMarkerHit", szuretMarker, MarkerHit )
addEventHandler( "onMarkerLeave", szuretMarker, MarkerHit)

-- Clientside


addEvent('szuret',true)
addEventHandler('szuret',getRootElement(),
	function()
		if not addEventHandler('onClientRender',getRootElement(),showDX) then
		   addEventHandler('onClientRender',getRootElement(),showDX)
		else
		   removeEventHandler('onClientRender',getRootElement(),showDX)
		end
	end
)

function showDX()
   --dxDrawRectangle() for example
end

function isEventHandlerAdded( sEventName, pElementAttachedTo, func ) -- Useful function
     if type( sEventName ) == 'string' and isElement( pElementAttachedTo ) and type( func ) == 'function' then
          local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo )
          if type( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then
               for i, v in ipairs( aAttachedFunctions ) do
                    if v == func then
        	         return true
        	    end
	       end
	  end
     end
     return false
end

Not tested

I would use a variable to toggle when "onClientRender" is active and when it's removed instead of the function "isEventHandlerAdded" which is too much for a simple thing, and it's less performative than using a variable. Also, you forgot to use that function in your code.

Posted
5 hours ago, DNL291 said:

I would use a variable to toggle when "onClientRender" is active and when it's removed instead of the function "isEventHandlerAdded" which is too much for a simple thing, and it's less performative than using a variable. Also, you forgot to use that function in your code.

Yep, It is not necessary to use the useful function, I only put one option (not the best)

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...