thund3rbird23 Posted September 4, 2019 Posted September 4, 2019 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 )
WorthlessCynomys Posted September 4, 2019 Posted September 4, 2019 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.
AlvarO Posted September 5, 2019 Posted September 5, 2019 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
Ceeser Posted September 5, 2019 Posted September 5, 2019 (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 September 5, 2019 by Ceeser
root. Posted September 28, 2019 Posted September 28, 2019 -- 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
DNL291 Posted September 28, 2019 Posted September 28, 2019 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.
root. Posted September 29, 2019 Posted September 29, 2019 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)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now