Advertisement
Guest User

Untitled

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