Scyrix Posted March 29, 2022 Share Posted March 29, 2022 Hi , I wanted to create a scroll for rectangles that i have inserted into a table. I tried to avoid rendertargets Does anyone have idea of how i can make that scroll so it acctually works. Or maybe someone correct me because i might have made the whole function just wrong local przecho = { {1000.79, 1069.15, 11.07-1,"CODELV",981.18, 1070.89, 10.81-0.98} } local oknoprzecho = false local data = nil local gridlisto = {} for _,v in ipairs(przecho) do local markerekPrzecho = createMarker(v[1],v[2],v[3],"cylinder",1.0,255,255,255,255) local markerOdbior = createMarker(v[5],v[6],v[7],"cylinder",2.0,255,255,255,255) addEventHandler("onClientMarkerHit",markerekPrzecho,function(plr) if plr == localPlayer then oknoprzecho = true showCursor(true) data = getElementData(localPlayer,"veh:list") showVehicles(748, 375, 416, 37) end end) addEventHandler("onClientMarkerHit",markerOdbior,function() end) end function showVehicles(x,y,z,h) local offset = 0 for k,v in pairs(gridlisto) do gridlisto[k]=nil end for k,v in ipairs(data) do table.insert(gridlisto,{x=x,y=y+offset,z=z,h=h,model=v.model}) offset = offset + 50 end print(#gridlisto) end --dxDrawRectangle(732, 321, 450, 294, tocolor(255, 255, 255, 255), true) addEventHandler("onClientRender", root,function() if oknoprzecho then dxDrawRectangle(561, 207, 798, 666, tocolor(32, 32, 32, 255), false) dxDrawRectangle(1290, 236, 41, 34, tocolor(255, 0, 0, 255), false) for i,v in ipairs(gridlisto) do dxDrawRectangle(v.x,v.y,v.z,v.h,tocolor(255,255,255,255)) dxDrawText(v.model, v.x, v.y, v.z, v.h, tocolor(0, 0, 0, 255), 1.00, "default", "left", "top", false, false, false, false, false) end end end) addEventHandler("onClientClick",root,function(btn,state) if btn == "left" and state == "down" then if oknoprzecho then if isMouseIn(1290, 236, 41, 34) then oknoprzecho = false showCursor(false) end for k,v in ipairs(gridlisto) do if isMouseIn(v.x, v.y, v.z, v.h) then outputChatBox(v.model) end end end end end) function isMouseIn( 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 Link to comment
alex17" Posted March 29, 2022 Share Posted March 29, 2022 I leave you an example of how you could make a grid list without using rendertarget local items = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"} local scroll = 0 local maxRows = 5 local select local sx, sy = guiGetScreenSize() function onMouseScroll(bind,state) if state == "down" then if bind == "mouse_wheel_down" then if scroll < #items - maxRows then scroll = scroll + 1 end else if scroll > 0 then scroll = scroll - 1 end end end end bindKey("mouse_wheel_down", "down", onMouseScroll) bindKey("mouse_wheel_up", "down", onMouseScroll) addEventHandler("onClientClick", root, function(_, state) if state == "down" then local cache = 0 for i = 1 + scroll, maxRows + scroll do if isMouseInPosition(sx * .4, sy * .3 + cache, sx * .2, sy * 0.05) then select = i return end cache = cache + sy * 0.05 end end end ) addEventHandler("onClientRender", root, function() local cache = 0 for i = 1 + scroll, maxRows + scroll do if isMouseInPosition(sx * .4, sy * .3 + cache, sx * .2, sy * 0.05) or select == i then dxDrawRectangle(sx * .4, sy * .3 + cache, sx * .2, sy * 0.05, tocolor(255, 255, 255, 100)) dxDrawText(items[i], sx * .4, sy * .3 + cache, sx * .6, sy * 0.35 + cache, tocolor(255, 255, 255)) else dxDrawRectangle(sx * .4, sy * .3 + cache, sx * .2, sy * 0.05, tocolor(0, 0, 0, 100)) dxDrawText(items[i], sx * .4, sy * .3 + cache, sx * .6, sy * 0.35 + cache, tocolor(255, 255, 255)) end cache = cache + sy * 0.05 end -- // draw scroll rectangle local rx = sx * .6 local ry = sy * .3 local rw = sx * .01 local rh = sy * 0.05 * maxRows local rh2 = sy * 0.05 local pos = ((rh - rh2) / (#items - maxRows)) * scroll dxDrawRectangle(rx, ry, rw, rh, tocolor(255, 255, 255)) dxDrawRectangle(rx, ry + pos, rw, rh2, tocolor(0, 0, 0)) end ) Link to comment
Scyrix Posted March 29, 2022 Author Share Posted March 29, 2022 Whats are cons and pros of using rendertarget for scroll system ? 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