Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.13 KB | None | 0 0
  1.  
  2.  
  3. local anims, builtins = {}, {"Linear", "InQuad", "OutQuad", "InOutQuad", "OutInQuad", "InElastic", "OutElastic", "InOutElastic", "OutInElastic", "InBack", "OutBack", "InOutBack", "OutInBack", "InBounce", "OutBounce", "InOutBounce", "OutInBounce", "SineCurve", "CosineCurve"}
  4.  
  5. function table.find(t, v)
  6. for k, a in ipairs(t) do
  7. if a == v then
  8. return k
  9. end
  10. end
  11. return false
  12. end
  13.  
  14. function animate(f, t, easing, duration, onChange, onEnd)
  15. assert(type(f) == "number", "Bad argument @ 'animate' [expected number at argument 1, got "..type(f).."]")
  16. assert(type(t) == "number", "Bad argument @ 'animate' [expected number at argument 2, got "..type(t).."]")
  17. assert(type(easing) == "string" or (type(easing) == "number" and (easing >= 1 or easing <= #builtins)), "Bad argument @ 'animate' [Invalid easing at argument 3]")
  18. assert(type(duration) == "number", "Bad argument @ 'animate' [expected function at argument 4, got "..type(duration).."]")
  19. assert(type(onChange) == "function", "Bad argument @ 'animate' [expected function at argument 5, got "..type(onChange).."]")
  20. table.insert(anims, {from = f, to = t, easing = table.find(builtins, easing) and easing or builtins[easing], duration = duration, start = getTickCount( ), onChange = onChange, onEnd = onEnd})
  21. return #anims
  22. end
  23.  
  24. function destroyAnimation(a)
  25. if anims[a] then
  26. table.remove(anims, a)
  27. end
  28. end
  29.  
  30. addEventHandler("onClientRender", root, function( )
  31. local now = getTickCount( )
  32. for k,v in ipairs(anims) do
  33. v.onChange(interpolateBetween(v.from, 0, 0, v.to, 0, 0, (now - v.start) / v.duration, v.easing))
  34. if now >= v.start+v.duration then
  35. if type(v.onEnd) == "function" then
  36. v.onEnd( )
  37. end
  38. table.remove(anims, k)
  39. end
  40. end
  41. end)
  42.  
  43. -- animation function :D
  44.  
  45. local dx = exports.ad_dx;
  46. local editbox = exports.ad_editbox;
  47. local scroll = exports.ad_scroll;
  48.  
  49.  
  50.  
  51. local f1 = dxCreateFont("font.ttf", 12)
  52. local f2 = dxCreateFont("font.ttf", 13)
  53. local f3 = dxCreateFont("font.ttf", 12)
  54. local f4 = dxCreateFont("font.ttf", 9)
  55. local f5 = dxCreateFont("font.ttf", 7)
  56.  
  57. local sw,sh = guiGetScreenSize()
  58. local baseX = 1920
  59. local zoom = 1
  60. local minzoom = 2
  61. if sw < baseX then
  62. zoom = math.min(minzoom, baseX/sw)
  63. end
  64.  
  65. local scoreboard = {}
  66.  
  67. function isMouseIn(x, y, w, h)
  68. if not isCursorShowing() then return end
  69.  
  70. local pos = {getCursorPosition()}
  71. pos[1],pos[2] = (pos[1]*sw),(pos[2]*sh)
  72.  
  73. if pos[1] >= x and pos[1] <= (x+w) and pos[2] >= y and pos[2] <= (y+h) then
  74. return true
  75. end
  76. return false
  77. end
  78.  
  79. function isEventHandlerAdded(eventName, rootName, fnc)
  80. if type(eventName) == "string" and isElement(rootName) and type(fnc) == "function" then
  81. local eventHandlers = getEventHandlers(eventName, rootName)
  82. if type(eventHandlers) == "table" and #eventHandlers > 0 then
  83. for i,v in pairs(eventHandlers) do
  84. if v == fnc then
  85. return true
  86. end
  87. end
  88. end
  89. end
  90. return false
  91. end
  92.  
  93. local alpha = 0;
  94.  
  95. function scoreboard:Construction()
  96. self.textures = {
  97. "i/scoreboard.png",
  98. "i/edit.png",
  99. "i/logo2.png",
  100. "i/icons/all.png",
  101. "i/icons/premium.png",
  102. "i/icons/admins.png",
  103. };
  104.  
  105. self.img = {};
  106.  
  107. for i,v in pairs(self.textures) do
  108. self.img[i] = dxCreateTexture(v, "argb", false, "clamp");
  109. end;
  110.  
  111. self.min_row = 1
  112.  
  113. self.icons = {
  114. [1] = {self.img[4], "Wszyscy"},
  115. [2] = {self.img[5], "Premium"},
  116. [3] = {self.img[6], "Ekipa"},
  117. }
  118.  
  119. self.players = {}
  120. self.index = 0
  121.  
  122. self.update_player_data = 2500
  123. self.update_tick = getTickCount()
  124.  
  125. self.page = 1;
  126.  
  127. self.mouse_showed = false
  128.  
  129. self.edit_text = ""
  130.  
  131. self.render_fnc = function() self:Render() end
  132. self.scroll_fnc = function(key, state) self:Scroll(key, state) end
  133. self.toggle_fnc = function(key, state) self:Toggle(key, state) end
  134. self.mouse_fnc = function(key, state) self:Mouse(key, state) end
  135. self.load_players_fnc = function() self:LoadPlayers() end
  136. self.click = function(...) self:Click(...) end
  137.  
  138. bindKey("tab", "both", self.toggle_fnc)
  139.  
  140. addEventHandler("onPlayerJoin", root, self.load_players_fnc)
  141. addEventHandler("onPlayerQuit", root, self.load_players_fnc)
  142. addEventHandler("onClientClick", root, self.click)
  143. end
  144. function sort(parametr1, parametr2)
  145. if isElement(parametr1) and isElement(parametr2) then
  146. return (getElementData(parametr1, "id") or 0) < (getElementData(parametr2, "id") or 0)
  147. end
  148. end
  149.  
  150. function scoreboard:GetPlayerHEX(v)
  151. if getElementData(v, "user:premium") then
  152. return "#ffff00"
  153. else
  154. return "#c8c8c8"
  155. end
  156. end
  157.  
  158. function scoreboard:LoadPlayers()
  159. self["players"] = {}
  160.  
  161. for i,v in pairs(getElementsByType("player")) do
  162. if((self.page == 2 and getElementData(v, "player:premium")) or (self.page == 3 and getElementData(v, "player:admin")) or self.page == 1)then
  163. if string.len(self["edit_text"]) > 0 then
  164. if(string.find(string.gsub(getPlayerName(v):lower(),"#%x%x%x%x%x%x", ""), self["edit_text"]:lower(), 1, true) or string.find(getElementData(v, "id"), self["edit_text"], 1, true))then
  165. table.insert(self["players"], {
  166. id=(getElementData(v, "id") or "brak"),
  167. name=(getElementData(v, "player:sid") and getPlayerName(v) or "Niezalogowany"),
  168. organization=(getElementData(v, "player:organization") or "brak"),
  169. faction=(getElementData(v, "player:faction") or "brak"),
  170. ping=getPlayerPing(v),
  171. hex=self:GetPlayerHEX(v),
  172. rp=(getElementData(v, "player:srp") or "brak"),
  173. })
  174. end
  175. else
  176. table.insert(self["players"], {
  177. id=(getElementData(v, "id") or "brak"),
  178. name=(getElementData(v, "player:sid") and getPlayerName(v) or "Niezalogowany"),
  179. organization=(getElementData(v, "player:organization") or "brak"),
  180. faction=(getElementData(v, "player:faction") or "brak"),
  181.  
  182. ping=getPlayerPing(v),
  183. hex=self:GetPlayerHEX(v),
  184. rp=(getElementData(v, "player:srp") or "brak"),
  185. })
  186. end;
  187. end;
  188. end;
  189. end;
  190.  
  191. function scoreboard:Render()
  192. local gracze = getElementsByType("player")
  193. table.sort(gracze, sort)
  194. if getElementData(localPlayer, "interakcja") then return end
  195. self["edit_text"] = editbox:dxGetEditText("SCOREBOARD-SEARCH") or "";
  196. self["index"] = 0;
  197.  
  198. local selected = editbox:dxEditGetSelected("SCOREBOARD-SEARCH");
  199. if #self.edit_text > 0 or selected or (getTickCount() - self["update_tick"]) > self["update_player_data"] then
  200. self["update_tick"] = getTickCount()
  201. self:LoadPlayers()
  202. end
  203.  
  204. self.min_row = math.floor(scroll:dxScrollGetPosition("SCOREBOARD-SCROLL") + 1);
  205.  
  206. dxDrawImage(sw/2-721/2/zoom, sh/2-787/2/zoom, 721/zoom, 787/zoom, self.img[1], 0, 0, 0, tocolor(255, 255, 255, alpha), false);
  207. dxDrawImage(sw/2-270/2/zoom, sh/2-740/2/zoom, 274/zoom, 34/zoom, self.img[2], 0, 0, 0, tocolor(255, 255, 255, alpha), false);
  208.  
  209. dxDrawImage(sw/2+115/zoom, sh/2-721/2/zoom, 17/zoom, 17/zoom, self.icons[self.page][1], 0, 0, 0, tocolor(255, 255, 255, alpha), false);
  210. dxDrawText(self.icons[self.page][2], 0, sh/2-360/zoom, sw/2+110/zoom, 0, tocolor(124, 125, 127, alpha), 1, f5, "right", "top", false);
  211.  
  212. dxDrawImage(sw/2-700/2/zoom, sh/2-770/2/zoom, 200/zoom, 60/zoom, self.img[3], 0, 0, 0, tocolor(255, 255, 255, alpha), false);
  213.  
  214. dxDrawText("Graczy na serwerze:", 0, sh/2-375/zoom, sw/2+340/zoom, 0, tocolor(200, 200, 200, alpha), 1, f1, "right", "top", false);
  215. dxDrawText("#c88500"..#getElementsByType("player").."#ced1d0 ONLINE", 0, sh/2-360/zoom, sw/2+340/zoom, 0, tocolor(255, 255, 255, alpha), 1, f2, "right", "top", false, false, false, true);
  216. dxDrawText("Naciśnij PPM by pokazać kursor", 0, sh/2+367/zoom, sw, sh, tocolor(206, 209, 208, alpha), 1, f1, "center", "top", false);
  217.  
  218. dxDrawText("ID", sw/2-655/zoom, sh/2-311/zoom, sw/2, sh, tocolor(255, 255, 255, alpha), 1, f3, "center", "top", false);
  219. dxDrawText("NICK", sw/2-480/zoom, sh/2-311/zoom, sw/2, sh, tocolor(255, 255, 255, alpha), 1, f3, "center", "top", false);
  220. dxDrawText("REPUTACJA", sw/2-210/zoom, sh/2-311/zoom, sw/2, sh, tocolor(255, 255, 255, alpha), 1, f3, "center", "top", false);
  221. dxDrawText("ORGANIZACJA", sw/2+200/zoom, sh/2-311/zoom, sw/2, sh, tocolor(255, 255, 255, alpha), 1, f3, "center", "top", false);
  222. dxDrawText("PING", sw/2+590/zoom, sh/2-311/zoom, sw/2, sh, tocolor(255, 255, 255, alpha), 1, f3, "center", "top", false);
  223.  
  224. for i,v in pairs(self["players"]) do
  225. if(self["min_row"]+20 >= i and self["min_row"] <= i)then
  226. self["index"] = self["index"]+1;
  227.  
  228. local sY = (30/zoom)*self["index"]+5;
  229.  
  230. dxDrawText(v.id, sw/2-655/zoom, sh/2-311/zoom+sY, sw/2, sh, tocolor(206, 209, 208, alpha), 1, f3, "center", "top", false);
  231. dxDrawText(v.hex..v.name, sw/2-480/zoom, sh/2-311/zoom+sY, sw/2, sh, tocolor(206, 209, 208, alpha), 1, f3, "center", "top", false, false, false, true);
  232. dxDrawText(v.rp, sw/2-210/zoom, sh/2-311/zoom+sY, sw/2, sh, tocolor(206, 209, 208, alpha), 1, f3, "center", "top", false);
  233. dxDrawText(v.organization, sw/2+200/zoom, sh/2-311/zoom+sY, sw/2, sh, tocolor(206, 209, 208, alpha), 1, f3, "center", "top", false);
  234. dxDrawText(v.ping, sw/2+590/zoom, sh/2-311/zoom+sY, sw/2, sh, tocolor(206, 209, 208, alpha), 1, f3, "center", "top", false);
  235. end
  236. end
  237.  
  238. scroll:dxScrollSetAlpha("SCOREBOARD-SCROLL", alpha);
  239. editbox:dxSetEditAlpha("SCOREBOARD-SEARCH", alpha);
  240. end
  241.  
  242. function scoreboard:Click(key, state)
  243. if(key == "left" and state == "down")then
  244. if(isMouseIn(sw/2+115/zoom, sh/2-721/2/zoom, 17/zoom, 17/zoom))then
  245. if(self.page < 3)then
  246. self.page = self.page+1;
  247. else
  248. self.page = 1;
  249. end;
  250. self["update_tick"] = getTickCount()
  251. self:LoadPlayers()
  252. end;
  253. end;
  254. end;
  255.  
  256. function scoreboard:Toggle(key, state)
  257. if key == "tab" then
  258. if state == "up" and isEventHandlerAdded("onClientRender", root, self["render_fnc"]) then
  259. if self["mouse_showed"] == true then return end
  260.  
  261. animate(alpha, 0, 1, 100, function(a)
  262. alpha = a;
  263.  
  264. if(a == 0)then
  265. removeEventHandler("onClientRender", root, self["render_fnc"])
  266.  
  267. editbox:dxDestroyEdit("SCOREBOARD-SEARCH")
  268. showCursor(false)
  269.  
  270. self["mouse_showed"] = false
  271.  
  272. unbindKey("mouse2", "down", self["mouse_fnc"])
  273.  
  274. scroll:dxDestroyScroll("SCOREBOARD-SCROLL");
  275. end;
  276. end);
  277. elseif state == "down" then
  278. if self["mouse_showed"] == true and isEventHandlerAdded("onClientRender", root, self["render_fnc"]) then
  279. animate(alpha, 0, 1, 100, function(a)
  280. alpha = a;
  281.  
  282. if(a == 0)then
  283. removeEventHandler("onClientRender", root, self["render_fnc"])
  284.  
  285. editbox:dxDestroyEdit("SCOREBOARD-SEARCH")
  286. showCursor(false)
  287.  
  288. self["mouse_showed"] = false
  289.  
  290. unbindKey("mouse2", "down", self["mouse_fnc"])
  291.  
  292. scroll:dxDestroyScroll("SCOREBOARD-SCROLL");
  293. end;
  294. end);
  295. end;
  296.  
  297. if isEventHandlerAdded("onClientRender", root, self["render_fnc"]) then return end
  298.  
  299. self:LoadPlayers()
  300. self["update_tick"] = getTickCount()
  301.  
  302. addEventHandler("onClientRender", root, self["render_fnc"])
  303.  
  304. editbox:dxCreateEdit("SCOREBOARD-SEARCH", "", "Wyszukiwarka", sw/2-250/2/zoom, sh/2-740/2/zoom, 180/zoom, 34/zoom, false, 0, 255, false, true);
  305. scroll:dxCreateScroll("SCOREBOARD-SCROLL", sw/2+342/zoom, sh/2-280/zoom, 6/zoom, 60/zoom, 0, 21, self.players, 635/zoom);
  306.  
  307. self["mouse_showed"] = false
  308.  
  309. bindKey("mouse2", "down", self["mouse_fnc"])
  310.  
  311. animate(alpha, 255, 1, 100, function(a)
  312. alpha = a;
  313. end);
  314. end
  315. end
  316. end
  317.  
  318. function scoreboard:Mouse(key, state)
  319. if key == "mouse2" then
  320. showCursor(not self["mouse_showed"], false)
  321. self["mouse_showed"] = not self["mouse_showed"]
  322. end
  323. end
  324.  
  325. addEventHandler("onClientResourceStart", resourceRoot, function()
  326. scoreboard:Construction()
  327. end)
  328.  
  329. addEventHandler("onClientResourceStop", resourceRoot, function()
  330. editbox:dxDestroyEdit("SCOREBOARD-SEARCH")
  331. scroll:dxDestroyScroll("SCOREBOARD-SCROLL");
  332. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement