koragg Posted January 27, 2017 Share Posted January 27, 2017 So my idea's to make it possible for players to double click a player's nickname in the scoreboard and spectate him. That would avoid a lot of arrows spam left/right to find the player who you want to spectate, also it's faster than typing /spectate nick. But I'm not sure how to actually get nickname from the row I've double clicked so that it would use that into the /spectate command. The following code is in the dxscoreboard_client.lua file. I wanna use the 'specNick' variable to save the player's name on which I've double clicked but not really sure how nor where to do it. function scoreboardDoubleClick(button) local sx, sy = guiGetScreenSize() local rowsCount = math.floor(sy / 20) - 2 if scoreboardShowing and button == "left" then local rCount = math.min(scoreboardGetSize(), rowsCount - 1) local x, y = sx / 2 - 320, sy / 2 - rCount * 20 / 2 local cx, cy = getCursorPosition() cx = cx * sx cy = cy * sy if x <= cx and cx <= x + 640 and y <= cy and cy <= y + rCount * 20 then cy = cy - y cy = math.floor(cy / 20) + 1 if isElement(specNick) then outputChatBox("Spectating "..specNick..".") executeCommandHandler("spectate", specNick) else outputChatBox("Player not found.") end end end end function startDrawing() addEventHandler("onClientDoubleClick", root, scoreboardDoubleClick) scoreboardShowing = true end bindKey("tab", "down", startDrawing) function stopDrawing() removeEventHandler("onClientDoubleClick", root, scoreboardDoubleClick) showCursor(false) scoreboardShowing = false end bindKey("tab", "up", stopDrawing) Link to comment
koragg Posted January 27, 2017 Author Share Posted January 27, 2017 Fixed 'dxscoreboard_client.lua' -- Double-Click nickname in scoreboard to spectate the selected player local nickName = false function scoreboardClick() for key, column in ipairs(scoreboardColumns) do if column.name == "name" then nickName = getPlayerNametagText(source) end end end addEventHandler("onClientPlayerScoreboardClick", root, scoreboardClick) function scoreboardDoubleClick() for key, column in ipairs(scoreboardColumns) do if column.name == "name" then local playerName = nickName if playerName then executeCommandHandler("spectate", playerName) outputChatBox("#FFFFFFSpectating: "..playerName, 255, 255, 255, true) end end end end function startDrawing() addEventHandler("onClientDoubleClick", root, scoreboardDoubleClick) scoreboardShowing = true end bindKey("tab", "down", startDrawing) function stopDrawing() removeEventHandler("onClientDoubleClick", root, scoreboardDoubleClick) showCursor(false) scoreboardShowing = false end bindKey("tab", "up", stopDrawing) Link to comment
Einheit-101 Posted January 28, 2017 Share Posted January 28, 2017 Nice stuff and a good idea! 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