Karuzo Posted May 25, 2014 Share Posted May 25, 2014 Hey Guys, I have a small problem with my scoreboard. I'm trying to show all the stats only for the player which is selected. At the moment it looks like this : And my code: function performRender() local playertab = getElementsByType("player") dxDrawRectangle(recintx,recinty,recintw,recinth,tocolor(101,101,101,100),false) dxDrawRectangle(recintx+10,recinty+10,180,180,tocolor(50,50,50,200),false) local player = playertab[offset+page*8] if player then for i=1,totallines do local v = playertab[i+page*8] local nameplayer = getPlayerName(v) local level = ( getElementData(v,"Level") or 0 ) local money = ( getElementData(v,"Money") or 0 ) local countries = getElementData(v,"Country") or "N/A" local state = getElementData(v,"Status") or "N/A" local playerX, playerY, playerZ = getElementPosition ( v ) local zone = getZoneName ( playerX, playerY, playerZ ) dxDrawRectangle(recintx+10,((recinty-10))+offset*20,180,20,tocolor(15,192,252,80),false) dxDrawText(nameplayer,recintx+15,(recinty-9)+i*20,x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,true,false,0,0,0) dxDrawText(nameplayer,recintx+200,(recinty+10),x,y,tocolor(255,255,255,255),2,"default","left","top",false,false,true,true,false,0,0,0) dxDrawText("Level: "..level,recintx+200,(recinty+40),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) dxDrawText("Money: "..money,recintx+200,(recinty+60),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) dxDrawText("Location: "..zone,recintx+200,(recinty+80),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) dxDrawText("State: "..state,recintx+200,(recinty+120),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) dxDrawText("Country: "..countries,recintx+200,(recinty+100),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) end --outputChatBox(page) end My question is : How can i check which player was selected? Since this: local v = playertab[i+page*8] Doesn't work for me. Hope you can help me. Link to comment
Arsilex Posted May 25, 2014 Share Posted May 25, 2014 selected = 0 function performRender() local playertab = getElementsByType("player") dxDrawRectangle(recintx,recinty,recintw,recinth,tocolor(101,101,101,100),false) dxDrawRectangle(recintx+10,recinty+10,180,180,tocolor(50,50,50,200),false) local player = playertab[offset+page*8] if player then for i=1,totallines do local v = playertab[i+page*8] local nameplayer = getPlayerName(v) local level = ( getElementData(v,"Level") or 0 ) local money = ( getElementData(v,"Money") or 0 ) local countries = getElementData(v,"Country") or "N/A" local state = getElementData(v,"Status") or "N/A" local playerX, playerY, playerZ = getElementPosition ( v ) local zone = getZoneName ( playerX, playerY, playerZ ) dxDrawRectangle(recintx+10,((recinty-10))+offset*20,180,20,tocolor(15,192,252,80),false) dxDrawText(nameplayer,recintx+15,(recinty-9)+i*20,x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,true,false,0,0,0) dxDrawText(nameplayer,recintx+200,(recinty+10),x,y,tocolor(255,255,255,255),2,"default","left","top",false,false,true,true,false,0,0,0) dxDrawText("Level: "..level,recintx+200,(recinty+40),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) dxDrawText("Money: "..money,recintx+200,(recinty+60),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) dxDrawText("Location: "..zone,recintx+200,(recinty+80),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) dxDrawText("State: "..state,recintx+200,(recinty+120),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) dxDrawText("Country: "..countries,recintx+200,(recinty+100),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) if isCursorHover(recintx+10,((recinty-10))+offset*20,180,20) then selected = i else selected = 0 end end end end function isCursorHover(posX,posY,sizeX,sizeY) if posX and posY and sizeX and sizeY then if isCursorShowing() then local x,y = getCursorPosition() local x,y = x*sX,y*sY if x>=posX and x<=posX+sizeX and y>=posY and y<=posY+sizeY then return true end else return false end else return false end end Link to comment
Karuzo Posted May 25, 2014 Author Share Posted May 25, 2014 I'm Sorry. I've should said that i'm trying to do this with an offset, which changes when you're scrolling. This is my code with the offset: function performRender() local tick = getTickCount() local endTime = tickk + 500 local laufzeit = tick - tickk local dauer = endTime - tickk local progress = laufzeit/dauer local recintw,recinth,_ = interpolateBetween(x,y,0,recw,rech,0,progress,eastype) local recintx,recinty,_ = interpolateBetween(0,0,0,recx,recy,0,progress,eastype) local playertab = getElementsByType("player") dxDrawRectangle(recintx,recinty,recintw,recinth,tocolor(101,101,101,100),false) dxDrawRectangle(recintx+10,recinty+10,180,180,tocolor(50,50,50,200),false) local player = playertab[offset+page*8] --local test = testtable[offset+page*8] if player then for i=1,totallines do --local v = testtable[i+page*8] local v = playertab[i+page*8] local nameplayer = getPlayerName(v) --local vdraw = tostring(string.gsub( getPlayerName(v), "#%x%x%x%x%x%x", "", 1 )) local level = ( getElementData(v,"Level") or 0 ) local money = ( getElementData(v,"Money") or 0 ) local countries = getElementData(v,"Country") or "N/A" local state = getElementData(v,"Status") or "N/A" local playerX, playerY, playerZ = getElementPosition ( v ) local zone = getZoneName ( playerX, playerY, playerZ ) dxDrawRectangle(recintx+10,((recinty-10))+offset*20,180,20,tocolor(15,192,252,80),false) dxDrawText(nameplayer,recintx+15,(recinty-9)+i*20,x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,true,false,0,0,0) dxDrawText(nameplayer,recintx+200,(recinty+10),x,y,tocolor(255,255,255,255),2,"default","left","top",false,false,true,true,false,0,0,0) dxDrawText("Level: "..level,recintx+200,(recinty+40),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) dxDrawText("Money: "..money,recintx+200,(recinty+60),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) dxDrawText("Location: "..zone,recintx+200,(recinty+80),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) dxDrawText("State: "..state,recintx+200,(recinty+120),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) dxDrawText("Country: "..countries,recintx+200,(recinty+100),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) end --outputChatBox(page) end end function scrolling(side) if side == "down" then offset = offset + step elseif side == "up" then if offset < 1 and page < 0 then page = 0 offset = 1 end offset = offset - step end if page < 0 then page = 0 offset = 1 elseif page == -1 then page = 0 end end function scrollUP() scrolling("up") if offset < 1 then page = page - 1 offset = 9 end end function scrollDown() scrolling("down") if offset > totallines then page = page + 1 offset = 1 end end bindKey("mouse_wheel_up","down",scrollUP) bindKey("mouse_wheel_down","down",scrollDown) Link to comment
Arsilex Posted May 25, 2014 Share Posted May 25, 2014 local hovered = nil local selected = 0 function performRender() local tick = getTickCount() local endTime = tickk + 500 local laufzeit = tick - tickk local dauer = endTime - tickk local progress = laufzeit/dauer local recintw,recinth,_ = interpolateBetween(x,y,0,recw,rech,0,progress,eastype) local recintx,recinty,_ = interpolateBetween(0,0,0,recx,recy,0,progress,eastype) local playertab = getElementsByType("player") dxDrawRectangle(recintx,recinty,recintw,recinth,tocolor(101,101,101,100),false) dxDrawRectangle(recintx+10,recinty+10,180,180,tocolor(50,50,50,200),false) local player = playertab[offset+page*8] --local test = testtable[offset+page*8] if player then for i=1,totallines do --local v = testtable[i+page*8] local v = playertab[i+page*8] local nameplayer = getPlayerName(v) --local vdraw = tostring(string.gsub( getPlayerName(v), "#%x%x%x%x%x%x", "", 1 )) local level = ( getElementData(v,"Level") or 0 ) local money = ( getElementData(v,"Money") or 0 ) local countries = getElementData(v,"Country") or "N/A" local state = getElementData(v,"Status") or "N/A" local playerX, playerY, playerZ = getElementPosition ( v ) local zone = getZoneName ( playerX, playerY, playerZ ) dxDrawRectangle(recintx+10,((recinty-10))+offset*20,180,20,tocolor(15,192,252,80),false) dxDrawText(nameplayer,recintx+15,(recinty-9)+i*20,x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,true,false,0,0,0) dxDrawText(nameplayer,recintx+200,(recinty+10),x,y,tocolor(255,255,255,255),2,"default","left","top",false,false,true,true,false,0,0,0) dxDrawText("Level: "..level,recintx+200,(recinty+40),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) dxDrawText("Money: "..money,recintx+200,(recinty+60),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) dxDrawText("Location: "..zone,recintx+200,(recinty+80),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) dxDrawText("State: "..state,recintx+200,(recinty+120),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) dxDrawText("Country: "..countries,recintx+200,(recinty+100),x,y,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,true,false,false,0,0,0) if isCursorHover(recintx+10,((recinty-10))+offset*20,180,20) hovered = {[1] = i, [2] = page} else hovered = nil end end --outputChatBox(page) end end function scrolling(side) if side == "down" then offset = offset + step elseif side == "up" then if offset < 1 and page < 0 then page = 0 offset = 1 end offset = offset - step end if page < 0 then page = 0 offset = 1 elseif page == -1 then page = 0 end end function scrollUP() scrolling("up") if offset < 1 then page = page - 1 offset = 9 end end function scrollDown() scrolling("down") if offset > totallines then page = page + 1 offset = 1 end end bindKey("mouse_wheel_up","down",scrollUP) bindKey("mouse_wheel_down","down",scrollDown) function saveIndex() if type(hovered) == "table" then local playertab = getElementsByType("player") selected = playertab[hovered[1]+hovered[2]*8] end end bindKey ( "mouse1", "up", saveIndex ) function isCursorHover(posX,posY,sizeX,sizeY) if posX and posY and sizeX and sizeY then if isCursorShowing() then local x,y = getCursorPosition() local x,y = x*sX,y*sY if x>=posX and x<=posX+sizeX and y>=posY and y<=posY+sizeY then return true end else return false end else return false end end Link to comment
Arsilex Posted May 25, 2014 Share Posted May 25, 2014 what you like say whit still same? Link to comment
Karuzo Posted May 25, 2014 Author Share Posted May 25, 2014 It's like in the first picture. Link to comment
Arsilex Posted May 25, 2014 Share Posted May 25, 2014 Is not the same that first in the first only get index and not save in in the second get the index and page and after when you click in the rectangle this will save the player that you select Link to comment
Karuzo Posted May 26, 2014 Author Share Posted May 26, 2014 You don't understand me right. I just want to change the player if i scroll down or up. So if i scroll down it should do player + 1 and if i scroll up it should do player - 1 . Link to comment
Karuzo Posted May 26, 2014 Author Share Posted May 26, 2014 debug There's nothing to debug. It just doesn't simply get the player. Link to comment
Moderators Citizen Posted May 26, 2014 Moderators Share Posted May 26, 2014 And here I come ! Your code was a mess so I just cleaned as much as I wanted (because it's taking a lot of time actually which I don't really have). local x, y = 200, 200 local recx, recy = 300, 200 local recw, rech = 400, 200 local eastype = "Linear" local totallines = 10 local nbToSkip = 0 local playersTable = getElementsByType("player") setTimer(function() playersTable = getElementsByType("player") end, 3000, 0) local selectedPlayer = playersTable[1] local tickk = getTickCount() function performRender() local tick = getTickCount() local endTime = tickk + 500 local laufzeit = tick - tickk local dauer = endTime - tickk local progress = laufzeit/dauer local recintw, recinth, _ = interpolateBetween(x, y, 0, recw, rech, 0, progress, eastype) local recintx, recinty, _ = interpolateBetween(0, 0, 0, recx, recy, 0, progress, eastype) dxDrawRectangle(recintx, recinty, recintw, recinth, tocolor(101, 101, 101, 100), false) dxDrawRectangle(recintx+10, recinty+10, 180, 180, tocolor(50, 50, 50, 200), false) -- Drawing table + row selection local line = 0 for k, player in ipairs (playersTable) do if k > nbToSkip and line < totallines-1 then local nameplayer = getPlayerName(player) if player == selectedPlayer or line == 0 then dxDrawRectangle(recintx+10, recinty+10+line*20, 180, 20, tocolor(15, 192, 252, 80), false) end dxDrawText(nameplayer, recintx+15, recinty+10+line*20, recintx+15+180, recinty+12+line*20+20, tocolor(255,255,255,255), 1, "default-bold", "left", "center", false, false, true, true) line = line + 1 end end -- Drawing details only local nameplayer = getPlayerName(selectedPlayer) or "Undefined" local level = getElementData(selectedPlayer, "Level") or 0 local money = getElementData(selectedPlayer, "Money") or 0 local country = getElementData(selectedPlayer, "Country") or "N/A" local state = getElementData(selectedPlayer, "Status") or "N/A" local playerX, playerY, playerZ = getElementPosition( selectedPlayer ) local zone = getZoneName( playerX, playerY, playerZ ) dxDrawText(nameplayer, recintx+200, (recinty+10), x, y, tocolor(255, 255, 255, 255), 2, "default", "left", "top", false, false, true, true) dxDrawText("Level: "..level, recintx+200, (recinty+40), x, y, tocolor(255, 255, 255, 255), 1, "default-bold", "left", "top", false, false, true, false) dxDrawText("Money: "..money,recintx+200, (recinty+60), x, y, tocolor(255, 255, 255, 255), 1, "default-bold", "left", "top", false, false, true, false) dxDrawText("Location: "..zone, recintx+200, (recinty+80), x, y, tocolor(255, 255, 255, 255), 1, "default-bold", "left", "top", false, false, true, false) dxDrawText("State: "..state, recintx+200, (recinty+120), x, y, tocolor(255, 255, 255, 255), 1, "default-bold", "left", "top", false, false, true, false) dxDrawText("Country: "..country, recintx+200, (recinty+100), x, y, tocolor(255, 255, 255, 255), 1, "default-bold", "left", "top", false, false, true, false) end -- addEventHandler("onClientRender", root, performRender) function scrolling( _, _, side) outputChatBox(side) if side == "down" then nbToSkip = nbToSkip + 1 elseif side == "up" then nbToSkip = nbToSkip - 1 end if nbToSkip < 0 then nbToSkip = 0 end if nbToSkip >= #playersTable then nbToSkip = #playersTable-1 end selectedPlayer = playersTable[nbToSkip+1] end bindKey("mouse_wheel_up", "down", scrolling, "up") bindKey("mouse_wheel_down", "down", scrolling, "down") It can obviously be improuved but I won't do it. (Or maybe I will but not for free) Also the selected row will always be the 1st one due to the way I'm scrolling the table. If you want this blue rectangle to be scrolled instead of the table, I can do it, just ask. I was alone to test it so I used some tricks to fill that table and the display on the right might have bugs (even if I think it's okay ). I'm waiting for your feedback. (Also feel free to replace the values at the top from line 1 to 5 only) Link to comment
Karuzo Posted May 27, 2014 Author Share Posted May 27, 2014 @Citizen: Thank you for your effort, but i solved it I was so dumb that i just forgot a if query Thank you all guys! 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