Murilo_apa Posted December 9, 2022 Posted December 9, 2022 Yesterday I tried a help with the forum community but it didn't work, so I realized that the error was not what I was saying, but even so I think I'm too dumb to be able to do that. I can't synchronize the scroll with select. Someone help me? Sorry for the inconvenience. This is my current code: local espace = 0.0052 local screenW, screenH = guiGetScreenSize() local rx, ry = screenW * 0.2079, screenH * 0.5599 local render = dxCreateRenderTarget(rx, ry, true) local scroll = 0.0000 local scrollV = 0.0255 local maxScroll = 0.0000 local selected = nil local slots = {} local cx, cy = screenW * 0.3960, screenH * 0.2214 local bx, by = (screenW/2) - (rx/2), (screenH/2) - (ry/2); local Color = tocolor(140, 140, 140, 150) local selectedColor = tocolor(0, 200, 255, 200) function drawInv() if render and isElement(render) then showCursor(true) local x, y = 0.0029, 0.0052 dxDrawRectangle(cx, cy, rx, ry, tocolor(0, 0, 0, 100), false) dxSetRenderTarget(render, true) for i=1,50 do dxDrawRectangle(screenW * x, screenH * (y - scroll), screenW * 0.0483, screenH * 0.0872, i == selected and selectedColor or Color) dxDrawImage(screenW * (x + 0.0050), screenH * ((y + 0.0100) - scroll), screenW * (0.0483 - 0.0100), screenH * (0.0872 - 0.0200), 'img/agua.png', 0, 0, 0, tocolor(255, 255, 255, 255), false) table.insert(slots, {screenW * x, screenH * (y - scroll), screenW * 0.0483, screenH * 0.0872}) x = x + 0.0512 if x >= 0.1823 then x = 0.0029 y = y + 0.0920 end maxScroll = y - 0.4727 + espace end dxSetRenderTarget() dxDrawImage(cx, cy, rx, ry, render) end end addEventHandler('onClientRender', root, drawInv) function scrollRoller(b, p) if p then if b == 'mouse_wheel_up' then scroll = math.max(0, scroll - scrollV) elseif b == "mouse_wheel_down" then scroll = math.min(maxScroll, scroll + scrollV) end end end addEventHandler('onClientKey', root, scrollRoller) function clickSelect(b, s) if s == 'down' then if b == 'left' then for i,v in ipairs(slots) do if isMouseInPosition(cx, cy, rx, ry) then if isMouseInPosition(v[1] + cx, v[2] + cy, v[3], v[4]) then selected = i break end end end end end end addEventHandler('onClientClick', root, clickSelect) And the video about what is the problem:
mafioz Posted December 10, 2022 Posted December 10, 2022 local espace = 0.0052 local screenW, screenH = guiGetScreenSize() local rx, ry = screenW * 0.2079, screenH * 0.5599 local render = dxCreateRenderTarget(rx, ry, true) local scroll = 0.0000 local scrollV = 0.0255 local maxScroll = 0.0000 local selected = nil local slots = {} local cx, cy = screenW * 0.3960, screenH * 0.2214 local bx, by = (screenW/2) - (rx/2), (screenH/2) - (ry/2); local Color = tocolor(140, 140, 140, 150) local selectedColor = tocolor(0, 200, 255, 200) function drawInv() if render and isElement(render) then showCursor(true) local x, y = 0.0029, 0.0052 dxDrawRectangle(cx, cy, rx, ry, tocolor(0, 0, 0, 100), false) dxSetRenderTarget(render, true) for i=1,50 do dxDrawRectangle(screenW * x, screenH * (y - scroll), screenW * 0.0483, screenH * 0.0872, i == selected and selectedColor or Color) dxDrawImage(screenW * (x + 0.0050), screenH * ((y + 0.0100) - scroll), screenW * (0.0483 - 0.0100), screenH * (0.0872 - 0.0200), 'img/agua.png', 0, 0, 0, tocolor(255, 255, 255, 255), false) slots[i] = {screenW * x, screenH * (y - scroll), screenW * 0.0483, screenH * 0.0872} x = x + 0.0512 if x >= 0.1823 then x = 0.0029 y = y + 0.0920 end maxScroll = y - 0.4727 + espace end dxSetRenderTarget() dxDrawImage(cx, cy, rx, ry, render) end end addEventHandler('onClientRender', root, drawInv) function scrollRoller(b, p) if p then if b == 'mouse_wheel_up' then scroll = math.max(0, scroll - scrollV) elseif b == "mouse_wheel_down" then scroll = math.min(maxScroll, scroll + scrollV) end end end addEventHandler('onClientKey', root, scrollRoller) function clickSelect(b, s) if s == 'down' then if b == 'left' then for i,v in ipairs(slots) do if isMouseInPosition(cx, cy, rx, ry) then if isMouseInPosition(v[1] + cx, v[2] + cy, v[3], v[4]) then selected = i break end end end end end end addEventHandler('onClientClick', root, clickSelect) Try this
Murilo_apa Posted December 10, 2022 Author Posted December 10, 2022 How? it work... I gonna study this Very thanks man
Addlibs Posted December 10, 2022 Posted December 10, 2022 1 hour ago, Murilo_apa said: How? it work... I gonna study this Very thanks man Pretty sure the most important part is slots[i] = {screenW * x, screenH * (y - scroll), screenW * 0.0483, screenH * 0.0872} replacing table.insert(slots, {screenW * x, screenH * (y - scroll), screenW * 0.0483, screenH * 0.0872}) The table.insert version was continuously adding new entries into the table rather than updating existing values as you scroll.
mafioz Posted December 10, 2022 Posted December 10, 2022 24 minutes ago, Addlibs said: Pretty sure the most important part is slots[i] = {screenW * x, screenH * (y - scroll), screenW * 0.0483, screenH * 0.0872} replacing table.insert(slots, {screenW * x, screenH * (y - scroll), screenW * 0.0483, screenH * 0.0872}) The table.insert version was continuously adding new entries into the table rather than updating existing values as you scroll. you're right
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