Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.32 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. local admin = exports.ad_admin;
  60.  
  61. local f1 = dx:getFont("rbt-r", 2);
  62. local f2 = dx:getFont("rbt-r", 5);
  63. local f3 = dx:getFont("rbt-r", 2);
  64. local f4 = dx:getFont("rbt-l", 10);
  65. local f5 = dx:getFont("rbt-r", -1);
  66.  
  67. local sw,sh = guiGetScreenSize()
  68. local baseX = 1920
  69. local zoom = 1
  70. local minzoom = 2
  71. if sw < baseX then
  72. zoom = math.min(minzoom, baseX/sw)
  73. end
  74.  
  75. local scoreboard = {}
  76.  
  77. function isMouseIn(x, y, w, h)
  78. if not isCursorShowing() then return end
  79.  
  80. local pos = {getCursorPosition()}
  81. pos[1],pos[2] = (pos[1]*sw),(pos[2]*sh)
  82.  
  83. if pos[1] >= x and pos[1] <= (x+w) and pos[2] >= y and pos[2] <= (y+h) then
  84. return true
  85. end
  86. return false
  87. end
  88.  
  89. function isEventHandlerAdded(eventName, rootName, fnc)
  90. if type(eventName) == "string" and isElement(rootName) and type(fnc) == "function" then
  91. local eventHandlers = getEventHandlers(eventName, rootName)
  92. if type(eventHandlers) == "table" and #eventHandlers > 0 then
  93. for i,v in pairs(eventHandlers) do
  94. if v == fnc then
  95. return true
  96. end
  97. end
  98. end
  99. end
  100. return false
  101. end
  102.  
  103. local alpha = 0;
  104.  
  105. function scoreboard:Construction()
  106. self.textures = {
  107. "i/scoreboard.png",
  108. "i/edit.png",
  109. "i/logo2.png",
  110. "i/icons/all.png",
  111. "i/icons/premium.png",
  112. "i/icons/admins.png",
  113. };
  114.  
  115. self.img = {};
  116.  
  117. for i,v in pairs(self.textures) do
  118. self.img[i] = dxCreateTexture(v, "argb", false, "clamp");
  119. end;
  120.  
  121. self.min_row = 1
  122.  
  123. self.icons = {
  124. [1] = {self.img[4], "Wszyscy"},
  125. [2] = {self.img[5], "Premium"},
  126. [3] = {self.img[6], "Ekipa"},
  127. }
  128.  
  129. self.players = {}
  130. self.index = 0
  131.  
  132. self.update_player_data = 2500
  133. self.update_tick = getTickCount()
  134.  
  135. self.page = 1;
  136.  
  137. self.mouse_showed = false
  138.  
  139. self.edit_text = ""
  140.  
  141. self.render_fnc = function() self:Render() end
  142. self.scroll_fnc = function(key, state) self:Scroll(key, state) end
  143. self.toggle_fnc = function(key, state) self:Toggle(key, state) end
  144. self.mouse_fnc = function(key, state) self:Mouse(key, state) end
  145. self.load_players_fnc = function() self:LoadPlayers() end
  146. self.click = function(...) self:Click(...) end
  147.  
  148. bindKey("tab", "both", self.toggle_fnc)
  149.  
  150. addEventHandler("onPlayerJoin", root, self.load_players_fnc)
  151. addEventHandler("onPlayerQuit", root, self.load_players_fnc)
  152. addEventHandler("onClientClick", root, self.click)
  153. end
  154.  
  155. local ranks = admin:getRanks();
  156.  
  157. function scoreboard:GetPlayerHEX(v)
  158. if getElementData(v, "user:admin") and getElementData(v, "user:admin") == 1 then
  159. return ranks[1][1];
  160. elseif getElementData(v, "user:admin") and getElementData(v, "user:admin") == 2 then
  161. return ranks[2][1];
  162. elseif getElementData(v, "user:admin") and getElementData(v, "user:admin") == 3 then
  163. return ranks[3][1];
  164. elseif getElementData(v, "user:admin") and getElementData(v, "user:admin") == 4 then
  165. return ranks[4][1];
  166. elseif getElementData(v, "user:admin") and getElementData(v, "user:admin") == 5 then
  167. return ranks[5][1];
  168. elseif getElementData(v, "user:premium") then
  169. return "#ffff00"
  170. else
  171. return "#c8c8c8"
  172. end
  173. end
  174.  
  175. function scoreboard:LoadPlayers()
  176. self["players"] = {}
  177.  
  178. for i,v in pairs(getElementsByType("player")) do
  179. if((self.page == 2 and getElementData(v, "user:premium")) or (self.page == 3 and getElementData(v, "user:admin")) or self.page == 1)then
  180. if string.len(self["edit_text"]) > 0 then
  181. 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, "user:id"), self["edit_text"], 1, true))then
  182. table.insert(self["players"], {
  183. id=(getElementData(v, "user:id") or 0),
  184. name=(getElementData(v, "user:uid") and getPlayerName(v) or "Niezalogowany"),
  185. organization=(getElementData(v, "user:organization") or "brak"),
  186. faction=(getElementData(v, "user:faction") or "brak"),
  187. ping=getPlayerPing(v),
  188. hex=self:GetPlayerHEX(v),
  189. })
  190. end
  191. else
  192. table.insert(self["players"], {
  193. id=(getElementData(v, "user:id") or 0),
  194. name=(getElementData(v, "user:uid") and getPlayerName(v) or "Niezalogowany"),
  195. organization=(getElementData(v, "user:organization") or "brak"),
  196. faction=(getElementData(v, "user:faction") or "brak"),
  197. ping=getPlayerPing(v),
  198. hex=self:GetPlayerHEX(v),
  199. })
  200. end;
  201. end;
  202. end;
  203. end;
  204.  
  205. function scoreboard:Render()
  206. self["edit_text"] = editbox:dxGetEditText("SCOREBOARD-SEARCH") or "";
  207. self["index"] = 0;
  208.  
  209. local selected = editbox:dxEditGetSelected("SCOREBOARD-SEARCH");
  210. if #self.edit_text > 0 or selected or (getTickCount() - self["update_tick"]) > self["update_player_data"] then
  211. self["update_tick"] = getTickCount()
  212. self:LoadPlayers()
  213. end
  214.  
  215. self.min_row = math.floor(scroll:dxScrollGetPosition("SCOREBOARD-SCROLL") + 1);
  216.  
  217. 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);
  218. 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);
  219.  
  220. 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);
  221. 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);
  222.  
  223. 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);
  224.  
  225. dxDrawText("Obecnie na serwerze:", 0, sh/2-375/zoom, sw/2+340/zoom, 0, tocolor(200, 200, 200, alpha), 1, f1, "right", "top", false);
  226. dxDrawText("#c79623"..#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);
  227. dxDrawText("Naciśnij PPM by pokazać kursor", 0, sh/2+367/zoom, sw, sh, tocolor(206, 209, 208, alpha), 1, f1, "center", "top", false);
  228.  
  229. dxDrawText("ID", sw/2-655/zoom, sh/2-311/zoom, sw/2, sh, tocolor(206, 209, 208, alpha), 1, f3, "center", "top", false);
  230. dxDrawText("NICK", sw/2-480/zoom, sh/2-311/zoom, sw/2, sh, tocolor(206, 209, 208, alpha), 1, f3, "center", "top", false);
  231. dxDrawText("POZIOM", sw/2-210/zoom, sh/2-311/zoom, sw/2, sh, tocolor(206, 209, 208, alpha), 1, f3, "center", "top", false);
  232. dxDrawText("DUTY", sw/2+200/zoom, sh/2-311/zoom, sw/2, sh, tocolor(206, 209, 208, alpha), 1, f3, "center", "top", false);
  233. dxDrawText("PING", sw/2+590/zoom, sh/2-311/zoom, sw/2, sh, tocolor(206, 209, 208, alpha), 1, f3, "center", "top", false);
  234.  
  235. for i,v in pairs(self["players"]) do
  236. if(self["min_row"]+20 >= i and self["min_row"] <= i)then
  237. self["index"] = self["index"]+1;
  238.  
  239. local sY = (30/zoom)*self["index"]+5;
  240.  
  241. 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);
  242. 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);
  243. dxDrawText("1", sw/2-210/zoom, sh/2-311/zoom+sY, sw/2, sh, tocolor(206, 209, 208, alpha), 1, f3, "center", "top", false);
  244. 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);
  245. 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);
  246. end
  247. end
  248.  
  249. scroll:dxScrollSetAlpha("SCOREBOARD-SCROLL", alpha);
  250. editbox:dxSetEditAlpha("SCOREBOARD-SEARCH", alpha);
  251. end
  252.  
  253. function scoreboard:Click(key, state)
  254. if(key == "left" and state == "down")then
  255. if(isMouseIn(sw/2+115/zoom, sh/2-721/2/zoom, 17/zoom, 17/zoom))then
  256. if(self.page < 3)then
  257. self.page = self.page+1;
  258. else
  259. self.page = 1;
  260. end;
  261. self["update_tick"] = getTickCount()
  262. self:LoadPlayers()
  263. end;
  264. end;
  265. end;
  266.  
  267. function scoreboard:Toggle(key, state)
  268. if key == "tab" and getElementData(localPlayer, "user:showHud") then
  269. if state == "up" and isEventHandlerAdded("onClientRender", root, self["render_fnc"]) then
  270. if self["mouse_showed"] == true then return end
  271.  
  272. animate(alpha, 0, 1, 100, function(a)
  273. alpha = a;
  274.  
  275. if(a == 0)then
  276. removeEventHandler("onClientRender", root, self["render_fnc"])
  277.  
  278. editbox:dxDestroyEdit("SCOREBOARD-SEARCH")
  279. showCursor(false)
  280.  
  281. self["mouse_showed"] = false
  282.  
  283. unbindKey("mouse2", "down", self["mouse_fnc"])
  284.  
  285. scroll:dxDestroyScroll("SCOREBOARD-SCROLL");
  286. end;
  287. end);
  288. elseif state == "down" then
  289. if self["mouse_showed"] == true and isEventHandlerAdded("onClientRender", root, self["render_fnc"]) then
  290. animate(alpha, 0, 1, 100, function(a)
  291. alpha = a;
  292.  
  293. if(a == 0)then
  294. removeEventHandler("onClientRender", root, self["render_fnc"])
  295.  
  296. editbox:dxDestroyEdit("SCOREBOARD-SEARCH")
  297. showCursor(false)
  298.  
  299. self["mouse_showed"] = false
  300.  
  301. unbindKey("mouse2", "down", self["mouse_fnc"])
  302.  
  303. scroll:dxDestroyScroll("SCOREBOARD-SCROLL");
  304. end;
  305. end);
  306. end;
  307.  
  308. if isEventHandlerAdded("onClientRender", root, self["render_fnc"]) then return end
  309.  
  310. self:LoadPlayers()
  311. self["update_tick"] = getTickCount()
  312.  
  313. addEventHandler("onClientRender", root, self["render_fnc"])
  314.  
  315. editbox:dxCreateEdit("SCOREBOARD-SEARCH", "", "Aby wyszukać wpisz nick/id", sw/2-250/2/zoom, sh/2-740/2/zoom, 180/zoom, 34/zoom, false, 0, 255, false, true);
  316. scroll:dxCreateScroll("SCOREBOARD-SCROLL", sw/2+342/zoom, sh/2-280/zoom, 6/zoom, 60/zoom, 0, 21, self.players, 635/zoom);
  317.  
  318. self["mouse_showed"] = false
  319.  
  320. bindKey("mouse2", "down", self["mouse_fnc"])
  321.  
  322. animate(alpha, 255, 1, 100, function(a)
  323. alpha = a;
  324. end);
  325. end
  326. end
  327. end
  328.  
  329. function scoreboard:Mouse(key, state)
  330. if key == "mouse2" then
  331. showCursor(not self["mouse_showed"], false)
  332. self["mouse_showed"] = not self["mouse_showed"]
  333. end
  334. end
  335.  
  336. addEventHandler("onClientResourceStart", resourceRoot, function()
  337. scoreboard:Construction()
  338. end)
  339.  
  340. addEventHandler("onClientResourceStop", resourceRoot, function()
  341. editbox:dxDestroyEdit("SCOREBOARD-SEARCH")
  342. scroll:dxDestroyScroll("SCOREBOARD-SCROLL");
  343. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement