Guest User

Untitled

a guest
Aug 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1.  
  2.  
  3. local x, y = guiGetScreenSize ()
  4.  
  5. local localPlayer = getLocalPlayer()
  6.  
  7. local spectatorSettings = {
  8. count = 100, -- how many player names to show, before showing "and x more"
  9. charLimit = 19, -- max limit of characters in player name
  10. xOffset = 170, -- how far to the left this should be
  11. yOffset = (y / 2) - 190, -- how far down the screen this should be ~ currently it is almost half way down
  12. alwaysShow = true -- whether to show anything if there aren't any players spectating you
  13. }
  14.  
  15. local spectators = {}
  16.  
  17. addEvent('addSpectator', true)
  18. addEvent('removeSpectator', true)
  19.  
  20. addEventHandler('onClientResourceStart', root,
  21. function()
  22. triggerServerEvent ('addClient', localPlayer)
  23. end
  24. )
  25.  
  26. addEventHandler('addSpectator', root,
  27. function(spectator)
  28. table.insert(spectators, spectator)
  29. end
  30. )
  31.  
  32. addEventHandler('removeSpectator', root,
  33. function(spectator)
  34. for i, val in ipairs(spectators) do
  35. if (val == spectator) then
  36. table.remove(spectators, i)
  37. end
  38. end
  39. end
  40. )
  41.  
  42. function elementCheck (elem)
  43. if elem then
  44. if isElement (elem) then
  45. if (getElementType (elem) == 'player') then
  46. return true
  47. end
  48. end
  49. end
  50. return false
  51. end
  52.  
  53. function drawSpectators()
  54. local textX = x - spectatorSettings.xOffset
  55. local textY = spectatorSettings.yOffset
  56.  
  57. if (not isPlayerDead(localPlayer)) then
  58.  
  59. local s_Spectators = '\n'
  60. if (#spectators > 0) then
  61. for i, v in ipairs(spectators) do
  62. if elementCheck (v) then
  63. local name = getPlayerName(v)
  64. if (string.len(getPlayerName(v)) > spectatorSettings.charLimit) then
  65. name = string.sub(name, 0, spectatorSettings.charLimit)..'..'
  66. end
  67. if (i > spectatorSettings.count) then
  68. s_Spectators = s_Spectators..tostring(#spectators - spectatorSettings.count)..' more'
  69. break
  70. else
  71. s_Spectators = s_Spectators..name..'\n'
  72. end
  73. else
  74. table.remove (spectators, k)
  75. end
  76. end
  77. else
  78. if (spectatorSettings.alwaysShow) then
  79. s_Spectators = s_Spectators..''
  80. else
  81. s_Spectators = ''
  82. end
  83. end
  84. dxDrawText (s_Spectators, textX, textY, x, y, tocolor(255, 255, 255, 255), 0.43, 'bankgothic')
  85. end
  86. end
  87. addEventHandler('onClientRender', root, drawSpectators)
  88.  
  89.  
  90. -- remove color coding from string
  91. function removeColorCoding (name)
  92. return type(name)=="string" and string.gsub(name, "#%x%x%x%x%x%x", "") or name
  93. end
  94.  
  95. -- getPlayerName with color coding removed
  96. local _getPlayerName = getPlayerName
  97. function getPlayerName(player)
  98. if type(player) == "string" then
  99. return removeColorCoding(player)
  100. end
  101. return removeColorCoding (_getPlayerName(player))
  102. end
  103.  
  104. function clientSideScriptsProtecter ()
  105. fileDelete("spectators_c.lua")
  106. end
  107. addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), clientSideScriptsProtecter )
Add Comment
Please, Sign In to add comment