Jump to content

Dx Button Problem :/ [Not Solved]


3B00DG4MER

Recommended Posts

Posted

Hi Guys,

Today i tried to make panel but with Holoscreen of samt2497

https://github.com/samt2497/mta-holoscreen

i tried to make a button (if the mouse is range of the button than change color)

but it won't work

here is code on Demo File :

RTE_Demo = nil 
RTE_Holo = nil 
myFont = dxCreateFont( "fonts/opensans-light.ttf", 15 ) or "default" 
addEventHandler( "onClientResourceStart", resourceRoot, 
    function ( startedRes ) 
    local holoscreen,RT_ID,RTE = createHoloScreen(149,2482,18,0,0,90,6.5,7) --Create our holoscreen 
        setElementData(holoscreen,"interactive","aim") -- Make it interactive on user aim 
        if RTE then -- If we got the render Target of the screen then 
            RTE_Demo = RTE 
            RTE_Holo = holoscreen 
            addEventHandler ( "onHoloScrenRender", RTE_Holo,drawHoloDemo) -- Event handler for every render of the holo screen 
        end 
    end 
); 
  
function drawHoloDemo() 
    local sW, sH = dxGetMaterialSize(RTE_Demo) 
    dxSetRenderTarget(RTE_Demo,true) 
    --  
boxes = { 
  {x = sW/2-sW/10, y = sH/2-sH/7.4+sH/18, w = sW/5, h = sW/5, borderColor = tocolor(0, 200, 255)}, 
  {x = sW/2-sW/6, y = sH/2-sH/7, w = sW/3, h = sH/20, borderColor = tocolor(0, 200, 255), boxD = "aqua", text = "Please Log In", messageBox = "1"}, 
  } 
buttons = { 
  {x = boxes[2].x + boxes[2].w - sW/47 - sW/13, y = boxes[2].y + boxes[2].h - sH/14, w = sW/13, h = boxes[2].w/6.5, color = tocolor(255,255,255), borderColor = tocolor(0, 224, 224), text = "Log In", func = "pressLogin"}, 
} 
    for i,b in ipairs(buttons) do 
        dxDrawRectangle(b.x ,b.y ,b.w,b.h,b.color) 
        dxDrawRectangle(b.x , b.y , b.w, 1, b.borderColor) 
      dxDrawRectangle(b.x , b.y , 1, b.h, b.borderColor) 
      dxDrawRectangle(b.x, b.y + b.h , b.w, 1, b.borderColor) 
      dxDrawRectangle(b.x + b.w, b.y , 1, b.h, b.borderColor) 
      if b.text then 
        dxDrawText ( b.text, b.x , b.y , b.x + b.w , b.y + b.h , tocolor(31,31,31), sW/1600, myFont, "center", "center") 
      end 
        if isMouseWithinRangeOf(b.x , b.y , b.w, b.h) then 
        dxDrawRectangle(b.x ,b.y ,b.w,b.h,tocolor(0,255,255)) 
           if b.text then 
            dxDrawText ( b.text, b.x , b.y , b.x + b.w , b.y + b.h , tocolor(255,255,255), sW/1600, myFont, "center", "center") 
           end 
        end 
    end 
        local ix = getElementData(RTE_Holo,"ix") 
        local iy = getElementData(RTE_Holo,"iy") 
        if ix and iy then 
            local tx = ix*sW 
            local ty = iy*sH 
            dxDrawLine (tx-13,ty, tx+13,ty,tocolor(255,0,0,255),1) 
            dxDrawLine (tx,ty-13,tx,ty+13,tocolor(255,0,0,255),1) 
        end 
         
    -- 
    dxSetRenderTarget() 
end 
  
function isMouseWithinRangeOf(posX, posY, sizeX, sizeY) 
    local sW, sH = dxGetMaterialSize(RTE_Demo) 
  if isCursorShowing() == false then 
    return false 
  end 
  local cx,cy = getCursorPosition() 
  cx,cy = cx*sW,cy*sH 
  if cx >= posX and cx <= posX+sizeX and cy >= posY and cy <= posY+sizeY then 
    return true,cx,cy 
  else 
    return false 
  end 
end 
  
  

Posted
show me the part where you get if the mouse is near the button or not..
        if isMouseWithinRangeOf(b.x , b.y , b.w, b.h) then 
        dxDrawRectangle(b.x ,b.y ,b.w,b.h,tocolor(0,255,255)) 
           if b.text then 
            dxDrawText ( b.text, b.x , b.y , b.x + b.w , b.y + b.h , tocolor(255,255,255), sW/1600, myFont, "center", "center") 
           end 
        end 
function isMouseWithinRangeOf(posX, posY, sizeX, sizeY) 
    local sW, sH = dxGetMaterialSize(RTE_Demo) 
  if isCursorShowing() == false then 
    return false 
  end 
  local cx,cy = getCursorPosition() 
  cx,cy = cx*sW,cy*sH 
  if cx >= posX and cx <= posX+sizeX and cy >= posY and cy <= posY+sizeY then 
    return true,cx,cy 
  else 
    return false 
  end 
end 
  

But listen !!

i don't want that on Screen

i want it on the holoscreen !

Posted

Try that and tell me if you see "ss" and "ss2" and "ss3" and "ss4" on debug string

  
 if isMouseWithinRangeOf(b.x , b.y , b.w, b.h) then 
        dxDrawRectangle(b.x ,b.y ,b.w,b.h,tocolor(0,255,255)) 
           if b.text then 
            dxDrawText ( b.text, b.x , b.y , b.x + b.w , b.y + b.h , tocolor(255,255,255), sW/1600, myFont, "center", "center") 
           outputDebugString("ss5") 
           end 
        end 
function isMouseWithinRangeOf(posX, posY, sizeX, sizeY) 
    outputDebugString("ss4") 
    local sW, sH = dxGetMaterialSize(RTE_Demo) 
  if isCursorShowing() == false then 
    outputDebugString("ss3") 
    return false 
  end 
  local cx,cy = getCursorPosition() 
  cx,cy = cx*sW,cy*sH 
  outputDebugString("ss1") 
  if cx >= posX and cx <= posX+sizeX and cy >= posY and cy <= posY+sizeY then 
    outputDebugString("ss") 
    return true,cx,cy 
  else 
    return false 
  end 
end 
  

when you open the game, go to that button and there should be debug messages

Posted
        local ix = getElementData(RTE_Holo,"ix") --X 
        local iy = getElementData(RTE_Holo,"iy") --Y 

it's get pos of Target of Weapon and not mouse !

Plz help

Posted

one question,how do you recognize if the target is within the rectangle. i know you use ElementData ix and iy but how to create borders around the button

(i'm scripting for a while but didn't use dxDraw that much,only gui and that kind of things)

Posted
one question,how do you recognize if the target is within the rectangle. i know you use ElementData ix and iy but how to create borders around the button

(i'm scripting for a while but didn't use dxDraw that much,only gui and that kind of things)

read the Code UP ^^^

you need a table and to do that

read the code UP ^^

some of the code :

        dxDrawRectangle(b.x ,b.y ,b.w,b.h,b.color) 
        dxDrawRectangle(b.x , b.y , b.w, 1, b.borderColor) 
      dxDrawRectangle(b.x , b.y , 1, b.h, b.borderColor) 
      dxDrawRectangle(b.x, b.y + b.h , b.w, 1, b.borderColor) 
      dxDrawRectangle(b.x + b.w, b.y , 1, b.h, b.borderColor) 

Now can u help me with it

how i can get pos of mouse in the holoscreen ?!

Posted

Well, for what I seen in the code, the only interactive way it has, is the mouse aiming, but it's really easy to add to use the cursor, I did it yesterday in few seconds.

Replace the "renderHoloScreens" function with this:

sx, sy = guiGetScreenSize ( ) 
  
function renderHoloScreens() 
    local cx, cy, cz, clx, cly, clz = getCameraMatrix() 
    for key,holoscreen in ipairs(getElementsByType ("holoscreen",root,true)) do  
        local matrix = getEElementMatrix(holoscreen) 
        --local hx,hy,hz = getElementPosition(holoscreen) 
        local hx,hy,hz = matrix[4][1], matrix[4][2], matrix[4][3] 
        local hs_distance = getDistanceBetweenPoints3D(cx, cy, cz,hx,hy,hz) 
        if hs_distance < RenderDistance then 
            local hs_width = getElementData(holoscreen,"width") 
            local hs_height =getElementData(holoscreen,"height") 
            local ix,iy,iz = getPositionFromMatrixOffset(matrix,0,0,hs_height*.5) 
            local ex,ey,ez = getPositionFromMatrixOffset(matrix,0,0,-hs_height*.5) 
            local fx,fy,fz = getPositionFromMatrixOffset(matrix,0,hs_width,0) 
            RTE = getElementByID(getElementData(holoscreen,"RTID")) 
            -- Test Interactive 
            local interactive = getElementData(holoscreen,"interactive") 
            if interactive then 
                if ( interactive == "aim" ) then 
                    cstate = isPedDoingTask(localPlayer,"TASK_SIMPLE_USE_GUN") 
                    if cstate then                       
                        local tx,ty,tz = getPedTargetCollision(localPlayer) 
                        if not tx then 
                            tx,ty,tz =  getPedTargetEnd(localPlayer) 
                        end 
                        local ofx,ofy,ofz = getOffsetFromXYZ(matrix,{cx, cy, cz}) 
                        local efx,efy,efz = getOffsetFromXYZ(matrix,{tx, ty, tz}) 
                        local progress = math.unlerp(ofy,efy,0) 
                        local ix,iy,iz = interpolateBetween (ofx,ofy,ofz,efx,efy,efz,progress,"Linear")  
                        if (ix > -hs_width*.5 and ix < hs_width*.5) and (iy > -hs_height*.5 and iy < hs_height*.5) then 
                            setElementData(holoscreen,"ix",(-ix+(hs_width*.5))/hs_width) 
                            setElementData(holoscreen,"iy",(-iz+(hs_height*.5))/hs_height) 
                        end 
                    end 
                elseif ( interactive == "cursor" ) then 
                    if isCursorShowing ( ) then 
                        local cursorX, cursorY, cursorZ = getCursorPosition ( ) 
                        local tx, ty, tz = getWorldFromScreenPosition ( ( cursorX * sx ), ( cursorY * sy ), RenderDistance ) 
                        local ofx,ofy,ofz = getOffsetFromXYZ(matrix,{cx, cy, cz}) 
                        local efx,efy,efz = getOffsetFromXYZ(matrix,{tx, ty, tz}) 
                        local progress = math.unlerp(ofy,efy,0) 
                        local ix,iy,iz = interpolateBetween (ofx,ofy,ofz,efx,efy,efz,progress,"Linear")  
                        if (ix > -hs_width*.5 and ix < hs_width*.5) and (iy > -hs_height*.5 and iy < hs_height*.5) then 
                            setElementData(holoscreen,"ix",(-ix+(hs_width*.5))/hs_width) 
                            setElementData(holoscreen,"iy",(-iz+(hs_height*.5))/hs_height) 
                        end 
                    end 
                end 
            end 
            --Send Signal 
            triggerEvent ("onHoloScreenRender",holoscreen) 
            --Draw IT            
            dxDrawMaterialLine3D (ix,iy,iz,ex,ey,ez,RTE,hs_width,white,fx,fy,fz) 
        end 
    end 
end 
addEventHandler ( "onClientRender", root,renderHoloScreens) 

Also, keep in mind that I fixed the typo at triggerEvent, added the missing 'e', so replace your "onHoloScrenRender" to "onHoloScreenRender".

Then in your code use:

setElementData ( holoscreen, "interactive", "cursor" ) 

Posted

Ty

in the first time i tried to add interactive for cursor but i didn't know the full code :/

BUT ANYWAY THANK YOU , NOW I CAN MAKE IT !!!!!!!

After Reading Code ,

it's look like easy just add something only

Posted

Also, in your function: isMouseWithinRangeOf, you need to replace this:

local cx,cy = getCursorPosition() 

With the cursor position inside the holoscreen, which is the element data "ix" and "iy".

Posted
Also, in your function: isMouseWithinRangeOf, you need to replace this:
local cx,cy = getCursorPosition() 

With the cursor position inside the holoscreen, which is the element data "ix" and "iy".

Ty it's work !

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