lima Posted December 28, 2023 Share Posted December 28, 2023 is based on ejecting the play from the vehicle, leaving only the driver.. using the onClientClick function.. local screenW,screenH = guiGetScreenSize() local resW, resH = 1600,900 local x, y = (screenW/resW), (screenH/resH) function dx() dxDrawImage(x*786, y*572, x*36, y*27, "assets/img/expulse.png") end addEventHandler("onClientRender",root,dx) addEventHandler("onClientClick", root, function (b, s) if s == "down" and b == "left" then if isEventHandlerAdded("onClientRender", root, dx) then if isMouseInPosition (x*786, y*572, x*36, y*27) then Veh = getPedOccupiedVehicle(player) or 0 if (Veh) then vehSeatNo = getPedOccupiedVehicleSeat(player) or 0 if vehSeatNo == 0 then getVehicleOccupant(seat) removePedFromVehicle(source, ocVeh) pX, pY, pZ = getElementPosition(source) rX, rY, rZ = getElementRotation(source) ejectorSeat = createObject(1562, pX, pY, pZ, rX, rY, rZ) setElementAlpha(ejectorSeat, 0) -- make the seat invis. setElementCollisionsEnabled(ejectorSeat, false) -- make the seat untouchable so as to avoid crashes getVehicleOccupant(player) attachElements(source, ejectorSeat, 0, 0, 0, 0, 0, 0) moveObject(ejectorSeat, 5000, pX, pY, pZ, - 100) setTimer(detachElements,5000,1,player,ejectorSeat) setTimer(destroyElement,5000,1,ejectorSeat) triggerServerEvent ( "ejectVehicle", localPlayer ) end end end end end end) function isEventHandlerAdded( sEventName, pElementAttachedTo, func ) 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 function isMouseInPosition(x,y,w,h) if isCursorShowing() then local sx,sy = guiGetScreenSize() local cx,cy = getCursorPosition() local cx,cy = (cx*sx),(cy*sy) if (cx >= x and cx <= x+w) and (cy >= y and cy <= y+h) then return true end end end client side Link to comment
JamesDragon Posted December 28, 2023 Share Posted December 28, 2023 there's an issue with the isMouseInPosition function where it doesn't return false when the conditions aren't met. It's recommended to add a return false statement outside the if block to cover the case when the cursor isn't in the specified area: function isMouseInPosition(x, y, w, h) if isCursorShowing() then local sx, sy = guiGetScreenSize() local cx, cy = getCursorPosition() local cx, cy = (cx * sx), (cy * sy) if (cx >= x and cx <= x + w) and (cy >= y and cy <= y + h) then return true end end return false -- Add this line to return false if conditions aren't met end Link to comment
Hydra Posted December 31, 2023 Share Posted December 31, 2023 On 28/12/2023 at 22:17, JamesDragon said: there's an issue with the isMouseInPosition function where it doesn't return false when the conditions aren't met. It's recommended to add a return false statement outside the if block to cover the case when the cursor isn't in the specified area: function isMouseInPosition(x, y, w, h) if isCursorShowing() then local sx, sy = guiGetScreenSize() local cx, cy = getCursorPosition() local cx, cy = (cx * sx), (cy * sy) if (cx >= x and cx <= x + w) and (cy >= y and cy <= y + h) then return true end end return false -- Add this line to return false if conditions aren't met end function isMouseInPosition ( x, y, width, height ) if ( not isCursorShowing( ) ) then return false end local sx, sy = guiGetScreenSize ( ) local cx, cy = getCursorPosition ( ) local cx, cy = ( cx * sx ), ( cy * sy ) return ( ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) ) end Try this one Link to comment
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