Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
120
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. if getElementData(localPlayer, "interakcja") then return end
  193. self["edit_text"] = editbox:dxGetEditText("SCOREBOARD-SEARCH") or "";
  194. self["index"] = 0;
  195.  
  196. local selected = editbox:dxEditGetSelected("SCOREBOARD-SEARCH");
  197. if #self.edit_text > 0 or selected or (getTickCount() - self["update_tick"]) > self["update_player_data"] then
  198. self["update_tick"] = getTickCount()
  199. self:LoadPlayers()
  200. end
  201.  
  202. self.min_row = math.floor(scroll:dxScrollGetPosition("SCOREBOARD-SCROLL") + 1);
  203.  
  204. 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);
  205. 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);
  206.  
  207. 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);
  208. 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);
  209.  
  210. 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);
  211.  
  212. dxDrawText("Graczy na serwerze:", 0, sh/2-375/zoom, sw/2+340/zoom, 0, tocolor(200, 200, 200, alpha), 1, f1, "right", "top", false);
  213. 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);
  214. dxDrawText("Naciśnij PPM by pokazać kursor", 0, sh/2+367/zoom, sw, sh, tocolor(206, 209, 208, alpha), 1, f1, "center", "top", false);
  215.  
  216. dxDrawText("ID", sw/2-655/zoom, sh/2-311/zoom, sw/2, sh, tocolor(255, 255, 255, alpha), 1, f3, "center", "top", false);
  217. dxDrawText("NICK", sw/2-480/zoom, sh/2-311/zoom, sw/2, sh, tocolor(255, 255, 255, alpha), 1, f3, "center", "top", false);
  218. dxDrawText("REPUTACJA", sw/2-210/zoom, sh/2-311/zoom, sw/2, sh, tocolor(255, 255, 255, alpha), 1, f3, "center", "top", false);
  219. dxDrawText("ORGANIZACJA", sw/2+200/zoom, sh/2-311/zoom, sw/2, sh, tocolor(255, 255, 255, alpha), 1, f3, "center", "top", false);
  220. dxDrawText("PING", sw/2+590/zoom, sh/2-311/zoom, sw/2, sh, tocolor(255, 255, 255, alpha), 1, f3, "center", "top", false);
  221.  
  222. for i,v in pairs(self["players"]) do
  223. if(self["min_row"]+20 >= i and self["min_row"] <= i)then
  224. self["index"] = self["index"]+1;
  225.  
  226. local sY = (30/zoom)*self["index"]+5;
  227. local gracze = getElementsByType("player")
  228. table.sort(gracze, sort)
  229. 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);
  230. 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);
  231. 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);
  232. 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);
  233. 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);
  234. end
  235. end
  236.  
  237. scroll:dxScrollSetAlpha("SCOREBOARD-SCROLL", alpha);
  238. editbox:dxSetEditAlpha("SCOREBOARD-SEARCH", alpha);
  239. end
  240.  
  241. function scoreboard:Click(key, state)
  242. if(key == "left" and state == "down")then
  243. if(isMouseIn(sw/2+115/zoom, sh/2-721/2/zoom, 17/zoom, 17/zoom))then
  244. if(self.page < 3)then
  245. self.page = self.page+1;
  246. else
  247. self.page = 1;
  248. end;
  249. self["update_tick"] = getTickCount()
  250. self:LoadPlayers()
  251. end;
  252. end;
  253. end;
  254.  
  255. function scoreboard:Toggle(key, state)
  256. if key == "tab" then
  257. if state == "up" and isEventHandlerAdded("onClientRender", root, self["render_fnc"]) then
  258. if self["mouse_showed"] == true then return end
  259.  
  260. animate(alpha, 0, 1, 100, function(a)
  261. alpha = a;
  262.  
  263. if(a == 0)then
  264. removeEventHandler("onClientRender", root, self["render_fnc"])
  265.  
  266. editbox:dxDestroyEdit("SCOREBOARD-SEARCH")
  267. showCursor(false)
  268.  
  269. self["mouse_showed"] = false
  270.  
  271. unbindKey("mouse2", "down", self["mouse_fnc"])
  272.  
  273. scroll:dxDestroyScroll("SCOREBOARD-SCROLL");
  274. end;
  275. end);
  276. elseif state == "down" then
  277. if self["mouse_showed"] == true and isEventHandlerAdded("onClientRender", root, self["render_fnc"]) then
  278. animate(alpha, 0, 1, 100, function(a)
  279. alpha = a;
  280.  
  281. if(a == 0)then
  282. removeEventHandler("onClientRender", root, self["render_fnc"])
  283.  
  284. editbox:dxDestroyEdit("SCOREBOARD-SEARCH")
  285. showCursor(false)
  286.  
  287. self["mouse_showed"] = false
  288.  
  289. unbindKey("mouse2", "down", self["mouse_fnc"])
  290.  
  291. scroll:dxDestroyScroll("SCOREBOARD-SCROLL");
  292. end;
  293. end);
  294. end;
  295.  
  296. if isEventHandlerAdded("onClientRender", root, self["render_fnc"]) then return end
  297.  
  298. self:LoadPlayers()
  299. self["update_tick"] = getTickCount()
  300.  
  301. addEventHandler("onClientRender", root, self["render_fnc"])
  302.  
  303. editbox:dxCreateEdit("SCOREBOARD-SEARCH", "", "Wyszukiwarka", sw/2-250/2/zoom, sh/2-740/2/zoom, 180/zoom, 34/zoom, false, 0, 255, false, true);
  304. scroll:dxCreateScroll("SCOREBOARD-SCROLL", sw/2+342/zoom, sh/2-280/zoom, 6/zoom, 60/zoom, 0, 21, self.players, 635/zoom);
  305.  
  306. self["mouse_showed"] = false
  307.  
  308. bindKey("mouse2", "down", self["mouse_fnc"])
  309.  
  310. animate(alpha, 255, 1, 100, function(a)
  311. alpha = a;
  312. end);
  313. end
  314. end
  315. end
  316.  
  317. function scoreboard:Mouse(key, state)
  318. if key == "mouse2" then
  319. showCursor(not self["mouse_showed"], false)
  320. self["mouse_showed"] = not self["mouse_showed"]
  321. end
  322. end
  323.  
  324. addEventHandler("onClientResourceStart", resourceRoot, function()
  325. scoreboard:Construction()
  326. end)
  327.  
  328. addEventHandler("onClientResourceStop", resourceRoot, function()
  329. editbox:dxDestroyEdit("SCOREBOARD-SEARCH")
  330. scroll:dxDestroyScroll("SCOREBOARD-SCROLL");
  331. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement