LeonardoWilliams Posted May 12, 2021 Share Posted May 12, 2021 (edited) Hello guys, so i encountered a little problem. This is a icon for admin but, i can`t understand how this works. For example those tooltips are made in a straight line and i want to make my own line with tooltips, like box because i want them to be vertical not horizontal, and i can`t really understand this any help please, i tried a lot but i can`t seem to get it to work, i got no idea what to do to make them in straight line. local isAdmin = exports.integration:isPlayerTrialAdmin(localPlayer) if isAdmin then if getElementData( localPlayer,"duty_admin" ) == 1 then --dxDrawImage(ax,ay,iconH,iconH,"images/hud/adm_on.png") --dxDrawImage(1645, 500, 64, 64, "images/hud/adm_on.png") --table.insert(tooltips, "adminonduty") --This is a tooltip for it, and on the second script it fires something but i can t really understand it. else --dxDrawImage(ax, ay, iconH, iconH, "images/hud/adm_off.png") --dxDrawImage(1558, 501, 77, 63, "images/hud/adm_off.png", false) --table.insert(tooltips, "adminoffduty") end ax = ax - iconW end This is what i can`t really understand at all, trying already for 3 hours to understand this script. if isCursorShowing() then ax, ay = screenWidth, getElementData(localPlayer, "annHeight") or 0 bx, by = screenWidth, screenHeight - iconH + 4 cursorX, cursorY = cursorX * screenWidth, cursorY * screenHeight for i = 1, #tooltips do ax = ax - iconW if isInBox( cursorX, cursorY, ax, ax + iconW, ay, ay + iconH/2 ) then --ADMIN DUTY / MAXIME if tooltips[i] == "adminonduty" then --what does this mean tooltip( cursorX, cursorY, "Admin Duty is ON", "Click to go OFF duty") --this too if justClicked then triggerEvent("accounts:settings:updateAccountSettings", localPlayer, "duty_admin", 0) --triggerServerEvent("updateNametagColor", localPlayer) playToggleSound() end if isInBox( cursorX, cursorY, ax, ax + iconW, ay, ay + iconH/2 ) then -- FEEL LIKE THIS IS THE THING THAT MATTERS THE MOST BUT I HAVE NO IDEA HOW TO USE IT OR ROTATE IT UPWARDS SO IT CAN BE VERTICAL, FOR NOW IS ONLY HORIZONTAL.. Edited May 12, 2021 by LeonardoWilliams Link to comment
LeonardoWilliams Posted May 12, 2021 Author Share Posted May 12, 2021 1 hour ago, LeonardoWilliams said: Hello guys, so i encountered a little problem. This is a icon for admin but, i can`t understand how this works. For example those tooltips are made in a straight line and i want to make my own line with tooltips, like box because i want them to be vertical not horizontal, and i can`t really understand this any help please, i tried a lot but i can`t seem to get it to work, i got no idea what to do to make them in straight line. local isAdmin = exports.integration:isPlayerTrialAdmin(localPlayer) if isAdmin then if getElementData( localPlayer,"duty_admin" ) == 1 then --dxDrawImage(ax,ay,iconH,iconH,"images/hud/adm_on.png") --dxDrawImage(1645, 500, 64, 64, "images/hud/adm_on.png") --table.insert(tooltips, "adminonduty") --This is a tooltip for it, and on the second script it fires something but i can t really understand it. else --dxDrawImage(ax, ay, iconH, iconH, "images/hud/adm_off.png") --dxDrawImage(1558, 501, 77, 63, "images/hud/adm_off.png", false) --table.insert(tooltips, "adminoffduty") end ax = ax - iconW end This is what i can`t really understand at all, trying already for 3 hours to understand this script. if isCursorShowing() then ax, ay = screenWidth, getElementData(localPlayer, "annHeight") or 0 bx, by = screenWidth, screenHeight - iconH + 4 cursorX, cursorY = cursorX * screenWidth, cursorY * screenHeight for i = 1, #tooltips do ax = ax - iconW if isInBox( cursorX, cursorY, ax, ax + iconW, ay, ay + iconH/2 ) then --ADMIN DUTY / MAXIME if tooltips[i] == "adminonduty" then --what does this mean tooltip( cursorX, cursorY, "Admin Duty is ON", "Click to go OFF duty") --this too if justClicked then triggerEvent("accounts:settings:updateAccountSettings", localPlayer, "duty_admin", 0) --triggerServerEvent("updateNametagColor", localPlayer) playToggleSound() end if isInBox( cursorX, cursorY, ax, ax + iconW, ay, ay + iconH/2 ) then -- FEEL LIKE THIS IS THE THING THAT MATTERS THE MOST BUT I HAVE NO IDEA HOW TO USE IT OR ROTATE IT UPWARDS SO IT CAN BE VERTICAL, FOR NOW IS ONLY HORIZONTAL.. Please give me an exemple too if you know because i`m a beginner and i want to see a proof then learn that example and use it myself to further projects Link to comment
Moderators Patrick Posted May 12, 2021 Moderators Share Posted May 12, 2021 I don't understand completely how you are trying to do it, so I just wrote an example code. I hope it helps. local screenWidth, screenHeight = guiGetScreenSize() local tooltips = { "adminonduty", "random1", "random2", "random3" } -- list with tooptips, I just define it here, you can mess with inserts local firstX, firstY = screenWidth/2-40, screenHeight/2-(#tooltips*50/2) -- position of first tooltip -- you have to split it up 2 parts, for drawing and checking -- drawing part addEventHandler("onClientRender", root, function() local offset = 0 -- position offset between tooltips, ofc this is 0 by default for i = 1, #tooltips do local tooltip = tooltips[i] local tipX, tipY = firstX, firstY -- base position tipY = tipY + offset -- shift -- get cursor's absolute position (stay at 0,0 if cursor not showing) local cursorX, cursorY = 0, 0 if isCursorShowing() then cursorX, cursorY = getCursorPosition() cursorX, cursorY = cursorX * screenWidth, cursorY * screenHeight end if isInBox(cursorX, cursorY, tipX, tipY, 80, 30) then -- active button dxDrawRectangle(tipX, tipY, 80, 30, tocolor(0,0,0,255)) dxDrawText(tooltip, tipX, tipY, tipX+80, tipY+30, tocolor(255,255,255,255), 1, "default-bold", "center", "center") else -- not active button dxDrawRectangle(tipX, tipY, 80, 30, tocolor(255,255,255,255)) dxDrawText(tooltip, tipX, tipY, tipX+80, tipY+30, tocolor(0,0,0,255), 1, "default-bold", "center", "center") end -- increase offset (to draw next one under the previous) offset = offset + 50 end end) -- cheking part -- here we calculate the tooltips positions again with the same method addEventHandler("onClientClick", root, function(key, state, cursorX, cursorY) if key == "left" and state == "up" then -- check only left-clicks local offset = 0 -- position offset between tooltips, ofc this is 0 by default for i = 1, #tooltips do local tooltip = tooltips[i] local tipX, tipY = firstX, firstY -- base position tipY = tipY + offset -- shift -- the event give us the cursor positions, we don't have to calculate them if isInBox(cursorX, cursorY, tipX, tipY, 80, 30) then -- clicking on this tooltip outputChatBox("Clicking on tooltip: " .. tooltip) return -- stop the for loop, not necessary to check others end -- increase offset offset = offset + 50 end end end) function isInBox(clickX, clickY, boxX, boxY, boxWidth, boxHeight) return (clickX >= boxX and clickX <= boxX + boxWidth ) and (clickY >= boxY and clickY <= boxY + boxHeight ) end 1 Link to comment
LeonardoWilliams Posted May 12, 2021 Author Share Posted May 12, 2021 Thank you so much patrick, i`ll learn a lot from this Link to comment
LeonardoWilliams Posted May 12, 2021 Author Share Posted May 12, 2021 By the way @Patrick, can you tell me what script writer you use ? i don`t know how is called, for example i use Sublime text 3 Link to comment
Moderators Patrick Posted May 12, 2021 Moderators Share Posted May 12, 2021 5 minutes ago, LeonardoWilliams said: By the way @Patrick, can you tell me what script writer you use ? i don`t know how is called, for example i use Sublime text 3 Visual Studio Code 1 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