Jump to content

Cursor enter/leave


HunT

Recommended Posts

  • 2 months later...

Again here about that :/ MTAsa really need the events onMouseEnter and onMouseLeave like onClientClick.

I need start the function if the cursor enter in the world objects. Any solution? Tnx

Link to comment

i have find that in the editor_gui/client/guiGetMouseOverElement.lua

  
--GUI's onClientMouseMove is flawed in the fact that it does not trigger when you move your mouse without a gui element on top 
--this script works around that for the highlighter when the mouse is not on top of gui 
--it also provides a guiGetMouseOverElement to retrieve the current mouse over element. 
local worldDetector 
function createWorldDetector() 
    worldDetector = guiCreateProgressBar ( 0,0,1,1,true ) 
    guiSetAlpha ( worldDetector, 0 ) 
    guiMoveToBack( worldDetector ) 
    addEventHandler ( "onClientGUIWorldClick",worldDetector,function()  
    if source == worldDetector or source == getRootElement() then 
    guiMoveToBack(worldDetector) end end ) 
end 
  
local mouseOverElement = false 
addEventHandler ( "onClientMouseMove", getRootElement(), 
function ( cursorX, cursorY ) 
    if not isGUICreated then return end 
    if source == worldDetector then 
        hideHighlighter() 
        mouseOverElement = false 
    else 
        showHighlighter(source) 
        mouseOverElement = source 
    end 
end ) 
  
function guiGetMouseOverElement() 
    return mouseOverElement 
end 
  

Only the PRO scripter can make the useful function mouse enter/leave like in map editor.

Link to comment
How i can make the event like onClientMouseEnter/onClientMouseLeave in the world objects and peds?

I need start the function if the cursor is over an object or ped.

Any solution? Tnx.

All what you need is

  
local Target = false 
  
function YourFunction() 
if (not Target) then return end 
    local sX, sY, wX, wY, wZ = getCursorPosition() 
    local oX, oY, oZ = getCameraMatrix() 
    local hit, hitX, hitY, hitZ, hitEl = processLineOfSight(oX, oY, oZ, wX, wY, wZ) 
    if (hit and hitEl and isElement(hitEl)) then 
        if (getElementType(hitEl) == "object") then 
         
        -- You code here 
         
        elseif (getElementType(hitEl) == "ped") then 
         
        -- You code here 
         
        end  
    end  
end 
addEventHandler("onClientRender", root, YourFunction) 

Link to comment
How i can make the event like onClientMouseEnter/onClientMouseLeave in the world objects and peds?

I need start the function if the cursor is over an object or ped.

Any solution? Tnx.

All what you need is

  
local Target = false 
  
function YourFunction() 
if (not Target) then return end 
    local sX, sY, wX, wY, wZ = getCursorPosition() 
    local oX, oY, oZ = getCameraMatrix() 
    local hit, hitX, hitY, hitZ, hitEl = processLineOfSight(oX, oY, oZ, wX, wY, wZ) 
    if (hit and hitEl and isElement(hitEl)) then 
        if (getElementType(hitEl) == "object") then 
         
        -- You code here 
         
        elseif (getElementType(hitEl) == "ped") then 
         
        -- You code here 
         
        end  
    end  
end 
addEventHandler("onClientRender", root, YourFunction) 

Mhh now i cant try :/ Tnx

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