Advertisement
The_Belch

Player Info

Jul 2nd, 2019
1,620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.24 KB | None | 0 0
  1. -- Player information tool by ShadyRetard
  2. local listen_to_events = {
  3. "game_init",
  4. "player_team",
  5. "player_changename",
  6. "game_end",
  7. "player_disconnect"
  8. }
  9.  
  10. local SCRIPT_FILE_NAME = GetScriptName();
  11. local SCRIPT_FILE_ADDR = "https://raw.githubusercontent.com/hyperthegreat/aw_playerinfo/master/playerinfo.lua";
  12. local VERSION_FILE_ADDR = "https://raw.githubusercontent.com/hyperthegreat/aw_playerinfo/master/version.txt";
  13. local NETWORK_GET_ADDR = "https://api.shadyretard.io/playerinfo/%s";
  14.  
  15. local SHOW_WINDOW_CB = gui.Checkbox(gui.Reference("MISC", "Automation", "Other"), "PIT_SHOW_WINDOW_CB", "Show player information", true);
  16.  
  17. local VERSION_NUMBER = "1.0.2";
  18. local version_check_done = false;
  19. local update_downloaded = false;
  20. local update_available = false;
  21.  
  22. local selected_player_id;
  23. local fields_to_show;
  24. local playerinfo_cache = {};
  25.  
  26. local PLAYERINFO_WINDOW_X, PLAYERINFO_WINDOW_Y = 200, 200;
  27. local PLAYERINFO_WINDOW_WIDTH, PLAYERINFO_WINDOW_HEIGHT = 640, 350;
  28. local is_dragging = false;
  29. local last_click = globals.RealTime();
  30. local dragging_offset_x, dragging_offset_y;
  31.  
  32. for _, v in ipairs(listen_to_events) do
  33. client.AllowListener(v);
  34. end
  35.  
  36. local function is_mouse_in_rect(left, top, width, height)
  37. local mouse_x, mouse_y = input.GetMousePos();
  38. return (mouse_x >= left and mouse_x <= left + width and mouse_y >= top and mouse_y <= top + height);
  39. end
  40.  
  41. local function draw_shadow(left, top, right, bottom, color, length, fade)
  42. local shadow_r, shadow_g, shadow_b, shadow_a = gui.GetValue(color);
  43.  
  44. local a = math.min(shadow_a, length);
  45. local l = left;
  46. local t = top;
  47. local r = right;
  48. local b = bottom;
  49. for i = 1, length / 2 do
  50. a = a - fade;
  51.  
  52. if (a < 0) then
  53. break;
  54. end
  55.  
  56. l = l - 1;
  57. t = t - 1;
  58. b = b + 1;
  59. r = r + 1;
  60. draw.Color(shadow_r, shadow_g, shadow_b, a);
  61. draw.OutlinedRect(l, t, r, b);
  62. end
  63. end
  64.  
  65. local function draw_menu()
  66. draw.Color(gui.GetValue('clr_gui_window_background'));
  67. draw.FilledRect(PLAYERINFO_WINDOW_X, PLAYERINFO_WINDOW_Y - 25, PLAYERINFO_WINDOW_X + PLAYERINFO_WINDOW_WIDTH, PLAYERINFO_WINDOW_Y + PLAYERINFO_WINDOW_HEIGHT);
  68. draw.Color(gui.GetValue('clr_gui_window_header'));
  69. draw.FilledRect(PLAYERINFO_WINDOW_X, PLAYERINFO_WINDOW_Y - 50, PLAYERINFO_WINDOW_X + PLAYERINFO_WINDOW_WIDTH, PLAYERINFO_WINDOW_Y - 25);
  70. draw.Color(gui.GetValue('clr_gui_window_header_tab2'));
  71. draw.FilledRect(PLAYERINFO_WINDOW_X, PLAYERINFO_WINDOW_Y - 25, PLAYERINFO_WINDOW_X + PLAYERINFO_WINDOW_WIDTH, PLAYERINFO_WINDOW_Y - 25 + 4);
  72. draw.Color(gui.GetValue('clr_gui_text1'));
  73. draw.TextShadow(PLAYERINFO_WINDOW_X + 8, PLAYERINFO_WINDOW_Y - 25 - 18, "Player Information Tool");
  74.  
  75. draw.Color(gui.GetValue('clr_gui_window_footer'));
  76. draw.FilledRect(PLAYERINFO_WINDOW_X, PLAYERINFO_WINDOW_Y + PLAYERINFO_WINDOW_HEIGHT, PLAYERINFO_WINDOW_X + PLAYERINFO_WINDOW_WIDTH, PLAYERINFO_WINDOW_Y + PLAYERINFO_WINDOW_HEIGHT + 20);
  77. draw.Color(gui.GetValue('clr_gui_window_footer_text'));
  78. draw.TextShadow(PLAYERINFO_WINDOW_X + 8, PLAYERINFO_WINDOW_Y + PLAYERINFO_WINDOW_HEIGHT + 4, "By ShadyRetard");
  79. draw_shadow(PLAYERINFO_WINDOW_X, PLAYERINFO_WINDOW_Y - 50, PLAYERINFO_WINDOW_X + PLAYERINFO_WINDOW_WIDTH, PLAYERINFO_WINDOW_Y - 25 + PLAYERINFO_WINDOW_HEIGHT + 20, 'clr_gui_window_shadow', 20, 2);
  80. end
  81.  
  82. local function draw_list(mouse_down)
  83. draw.Color(gui.GetValue('clr_gui_groupbox_background'))
  84. draw.FilledRect(PLAYERINFO_WINDOW_X + 10, PLAYERINFO_WINDOW_Y - 10, PLAYERINFO_WINDOW_X + 210, PLAYERINFO_WINDOW_Y + PLAYERINFO_WINDOW_HEIGHT);
  85. draw.Color(gui.GetValue('clr_gui_text1'));
  86. draw.Text(PLAYERINFO_WINDOW_X + 15, PLAYERINFO_WINDOW_Y - 15, "Player List");
  87.  
  88. local offset = 5;
  89. for steam_id, info in pairs(playerinfo_cache) do
  90. draw.Color(gui.GetValue('clr_gui_text1'));
  91.  
  92. if (selected_player_id ~= nil and selected_player_id == steam_id) then
  93. draw.Color(255, 191, 0, 255);
  94. end
  95.  
  96. local w, h = draw.GetTextSize(info["summary"]["nickname"]);
  97. if (h ~= nil) then
  98. draw.Text(PLAYERINFO_WINDOW_X + 15, PLAYERINFO_WINDOW_Y + offset, info["summary"]["nickname"]);
  99.  
  100. if (mouse_down and is_mouse_in_rect(PLAYERINFO_WINDOW_X + 15, PLAYERINFO_WINDOW_Y + offset, 200, h)) then
  101. if (selected_player_id ~= steam_id) then
  102. selected_player_id = steam_id;
  103. fields_to_show = nil;
  104. end
  105.  
  106. last_click = globals.RealTime();
  107. end
  108.  
  109. offset = offset + h;
  110. end
  111. end
  112. end
  113.  
  114. local function draw_player_info(mouse_down)
  115. draw.Color(gui.GetValue('clr_gui_groupbox_background'))
  116. draw.FilledRect(PLAYERINFO_WINDOW_X + 230, PLAYERINFO_WINDOW_Y - 10, PLAYERINFO_WINDOW_X + 230 + 400, PLAYERINFO_WINDOW_Y + PLAYERINFO_WINDOW_HEIGHT);
  117. draw.Color(gui.GetValue('clr_gui_text1'));
  118. draw.Text(PLAYERINFO_WINDOW_X + 245, PLAYERINFO_WINDOW_Y - 15, "Player Info");
  119.  
  120. if (selected_player_id == nil) then return end
  121. if (fields_to_show == nil) then
  122. fields_to_show = {};
  123. local playerinfo = playerinfo_cache[selected_player_id]
  124. if (playerinfo == nil) then return end
  125.  
  126. local summary = playerinfo["summary"];
  127. if (summary ~= nil) then
  128. table.insert(fields_to_show, { title = "SteamID", value = summary["steamID"] });
  129. table.insert(fields_to_show, { title = "Steam URL", value = summary["url"] });
  130. table.insert(fields_to_show, { title = "Nickname", value = summary["nickname"] });
  131. table.insert(fields_to_show, { title = "Real name", value = summary["realName"] });
  132. table.insert(fields_to_show, { title = "Account Created", value = os.date('%Y-%m-%d %H:%M:%S', summary["created"]) });
  133. table.insert(fields_to_show, { title = "Last logged in", value = os.date('%Y-%m-%d %H:%M:%S', summary["lastLogOff"]) });
  134. table.insert(fields_to_show, { title = "Playing CS:GO", value = tostring(summary["gameID"] == 730) });
  135. end
  136.  
  137. local friends = playerinfo["friends"];
  138. if (friends ~= nil) then
  139. table.insert(fields_to_show, { title = "Friends", value = #friends });
  140. else
  141. table.insert(fields_to_show, { title = "Friends", value = 0 });
  142. end
  143.  
  144. table.insert(fields_to_show, { title = "Steam Level", value = playerinfo["level"] })
  145.  
  146. local bans = playerinfo["bans"];
  147. if (bans ~= nil) then
  148. table.insert(fields_to_show, { title = "Game Bans", value = bans["gameBans"] });
  149. table.insert(fields_to_show, { title = "VAC Bans", value = bans["vacBans"] });
  150. table.insert(fields_to_show, { title = "Economy Ban", value = bans["economyBan"] });
  151. table.insert(fields_to_show, { title = "Days since last ban", value = bans["daysSinceLastBan"] });
  152. end
  153.  
  154. local statistics = playerinfo["stats"];
  155. if (statistics ~= nil) then
  156. local stats = statistics["stats"];
  157. if (stats ~= nil) then
  158. table.insert(fields_to_show, { title = "Total Time Played", value = string.format("%.2f", stats["total_time_played"] / 60 / 60) .. " hours" })
  159. table.insert(fields_to_show, { title = "Total Matches Played", value = stats["total_matches_played"] });
  160. table.insert(fields_to_show, { title = "Total Matches Won", value = stats["total_matches_won"] });
  161. table.insert(fields_to_show, { title = "Total Win Ratio", value = string.format("%.2f", stats["total_matches_won"] / stats["total_matches_played"] * 100) .. "%" });
  162. table.insert(fields_to_show, { title = "Total Kills", value = stats["total_kills"] });
  163. table.insert(fields_to_show, { title = "Total Kills Headshot", value = stats["total_kills_headshot"] });
  164. table.insert(fields_to_show, { title = "Total Deaths", value = stats["total_deaths"] });
  165. table.insert(fields_to_show, { title = "Total KDA", value = string.format("%.2f", stats["total_kills"] / stats["total_deaths"]) });
  166. table.insert(fields_to_show, { title = "Total Shots Fired", value = stats["total_shots_fired"] });
  167. table.insert(fields_to_show, { title = "Total Shots Hit", value = stats["total_shots_hit"] });
  168. table.insert(fields_to_show, { title = "Total Shot Accuracy", value = string.format("%.2f", (stats["total_shots_hit"] / stats["total_shots_fired"]) * 100) .. "%" });
  169. end
  170.  
  171. local achievements = statistics["achievements"];
  172. if (achievements ~= nil) then
  173. table.insert(fields_to_show, { title = "Achievements", value = #achievements });
  174. else
  175. table.insert(fields_to_show, { title = "Achievements", value = 0 });
  176. end
  177. end
  178. end
  179.  
  180. local offset = 5;
  181. for _, v in ipairs(fields_to_show) do
  182. if (v ~= nil and v["title"] ~= nil and v["value"] ~= nil) then
  183. local w, h = draw.GetTextSize(v["title"] .. ": " .. v["value"]);
  184. draw.Text(PLAYERINFO_WINDOW_X + 245, PLAYERINFO_WINDOW_Y + offset, v["title"] .. ": " .. v["value"]);
  185. offset = offset + h;
  186. end
  187. end
  188. end
  189.  
  190. local function key_in_table(tbl, key)
  191. for k, _ in pairs(tbl) do
  192. if key == k then
  193. return true
  194. end
  195. end
  196. return false
  197. end
  198.  
  199. local function value_in_table(tbl, value)
  200. for _, v in ipairs(tbl) do
  201. if value == v then
  202. return true
  203. end
  204. end
  205. return false
  206. end
  207.  
  208. local char_to_hex = function(c)
  209. return string.format("%%%02X", string.byte(c))
  210. end
  211.  
  212. local function urlencode(url)
  213. if url == nil then
  214. return
  215. end
  216. url = url:gsub("\n", "\r\n")
  217. url = url:gsub("([^%w ])", char_to_hex)
  218. url = url:gsub(" ", "+")
  219. return url
  220. end
  221.  
  222. local function update_players()
  223. local my_player = entities.GetLocalPlayer();
  224. if (my_player == nil) then return end
  225.  
  226. for i = 1, globals.MaxClients(), 1 do
  227. local player_info = client.GetPlayerInfo(i);
  228. if (player_info ~= nil and player_info["IsBot"] == false and key_in_table(playerinfo_cache, player_info["SteamID"]) == false) then
  229. http.Get(string.format(NETWORK_GET_ADDR, urlencode(player_info["SteamID"])), function(response)
  230. if (response == nil or response == "error" or key_in_table(playerinfo_cache, player_info["SteamID"]) == true) then return end
  231. playerinfo_cache[player_info["SteamID"]] = json.decode(response);
  232. end)
  233. end
  234. end
  235. end
  236.  
  237. callbacks.Register("Draw", function()
  238. if (gui.GetValue("lua_allow_http") == false) then
  239. draw.Color(255, 0, 0, 255);
  240. draw.Text(25, 25, "[PIT] Allow internet connections from lua needs to be enabled to use this script");
  241. return;
  242. end
  243. if (gui.GetValue("lua_allow_cfg") == false) then
  244. draw.Color(255, 0, 0, 255);
  245. draw.Text(25, 25, "[PIT] Allow script/config editing from lua need to be enabled to use this script");
  246. return;
  247. end
  248.  
  249. if (not gui.Reference("MENU"):IsActive() or SHOW_WINDOW_CB:GetValue() == false) then return end
  250.  
  251. if (last_click ~= nil and last_click > globals.RealTime()) then
  252. last_click = globals.RealTime();
  253. end
  254.  
  255. local mouse_down = input.IsButtonPressed(1);
  256. draw_menu();
  257. draw_list(mouse_down);
  258. draw_player_info(mouse_down);
  259. end)
  260.  
  261. callbacks.Register("Draw", function()
  262. if (gui.GetValue("lua_allow_http") == false or gui.GetValue("lua_allow_cfg") == false) then
  263. return;
  264. end
  265.  
  266. if (SHOW_WINDOW_CB:GetValue() == false) then return end
  267.  
  268. local mouse_x, mouse_y = input.GetMousePos();
  269. local left_mouse_down = input.IsButtonDown(1);
  270. local left_mouse_pressed = input.IsButtonPressed(1);
  271.  
  272. if (is_dragging == true and left_mouse_down == false) then
  273. is_dragging = false;
  274. dragging_offset_x = 0;
  275. dragging_offset_y = 0;
  276. return;
  277. end
  278.  
  279. if (is_dragging == true) then
  280. PLAYERINFO_WINDOW_X = mouse_x - dragging_offset_x;
  281. PLAYERINFO_WINDOW_Y = mouse_y - dragging_offset_y;
  282. return;
  283. end
  284.  
  285. if (left_mouse_pressed and is_mouse_in_rect(PLAYERINFO_WINDOW_X, PLAYERINFO_WINDOW_Y - 50, PLAYERINFO_WINDOW_WIDTH, 25)) then
  286. is_dragging = true;
  287. dragging_offset_x = mouse_x - PLAYERINFO_WINDOW_X;
  288. dragging_offset_y = mouse_y - PLAYERINFO_WINDOW_Y;
  289. return;
  290. end
  291. end)
  292.  
  293. callbacks.Register("Draw", function()
  294. if (update_available and not update_downloaded) then
  295. if (gui.GetValue("lua_allow_cfg") == false) then
  296. draw.Color(255, 0, 0, 255);
  297. draw.Text(0, 0, "[PlayerInfo] An update is available, please enable Lua Allow Config and Lua Editing in the settings tab");
  298. else
  299. local new_version_content = http.Get(SCRIPT_FILE_ADDR);
  300. local old_script = file.Open(SCRIPT_FILE_NAME, "w");
  301. old_script:Write(new_version_content);
  302. old_script:Close();
  303. update_available = false;
  304. update_downloaded = true;
  305. end
  306. end
  307.  
  308. if (update_downloaded) then
  309. draw.Color(255, 0, 0, 255);
  310. draw.Text(0, 0, "[PlayerInfo] An update has automatically been downloaded, please reload the player info script");
  311. return;
  312. end
  313.  
  314. if (not version_check_done) then
  315. if (gui.GetValue("lua_allow_http") == false) then
  316. draw.Color(255, 0, 0, 255);
  317. draw.Text(0, 0, "[PlayerInfo] Please enable Lua HTTP Connections in your settings tab to use this script");
  318. return;
  319. end
  320.  
  321. version_check_done = true;
  322. local version = http.Get(VERSION_FILE_ADDR);
  323. if (version ~= VERSION_NUMBER) then
  324. update_available = true;
  325. end
  326. end
  327. end);
  328.  
  329. callbacks.Register("FireGameEvent", function(event)
  330. if (value_in_table(listen_to_events, event:GetName())) then
  331. update_players();
  332. end
  333. end)
  334.  
  335. update_players();
  336.  
  337. -- Lightweight JSON Library for Lua
  338. -- Credits: RXI
  339. -- Link / Github: https://github.com/rxi/json.lua/blob/master/json.lua
  340. -- Minified Version
  341. json = { _version = "0.1.1" } local b; local c = { ["\\"] = "\\\\", ["\""] = "\\\"", ["\b"] = "\\b", ["\f"] = "\\f", ["\n"] = "\\n", ["\r"] = "\\r", ["\t"] = "\\t" } local d = { ["\\/"] = "/" } for e, f in pairs(c) do d[f] = e end; local function g(h) return c[h] or string.format("\\u%04x", h:byte()) end
  342.  
  343. ; local function i(j) return "null" end
  344.  
  345. ; local function k(j, l) local m = {} l = l or {} if l[j] then error("circular reference") end; l[j] = true; if j[1] ~= nil or next(j) == nil then local n = 0; for e in pairs(j) do if type(e) ~= "number" then error("invalid table: mixed or invalid key types") end; n = n + 1 end; if n ~= #j then error("invalid table: sparse array") end; for o, f in ipairs(j) do table.insert(m, b(f, l)) end; l[j] = nil; return "[" .. table.concat(m, ",") .. "]" else for e, f in pairs(j) do if type(e) ~= "string" then error("invalid table: mixed or invalid key types") end; table.insert(m, b(e, l) .. ":" .. b(f, l)) end; l[j] = nil; return "{" .. table.concat(m, ",") .. "}" end end
  346.  
  347. ; local function p(j) return '"' .. j:gsub('[%z\1-\31\\"]', g) .. '"' end
  348.  
  349. ; local function q(j) if j ~= j or j <= -math.huge or j >= math.huge then error("unexpected number value '" .. tostring(j) .. "'") end; return string.format("%.14g", j) end
  350.  
  351. ; local r = { ["nil"] = i, ["table"] = k, ["string"] = p, ["number"] = q, ["boolean"] = tostring } b = function(j, l) local s = type(j) local t = r[s] if t then return t(j, l) end; error("unexpected type '" .. s .. "'") end; function json.encode(j) return b(j) end
  352.  
  353. ; local u; local function v(...) local m = {} for o = 1, select("#", ...) do m[select(o, ...)] = true end; return m end
  354.  
  355. ; local w = v(" ", "\t", "\r", "\n") local x = v(" ", "\t", "\r", "\n", "]", "}", ",") local y = v("\\", "/", '"', "b", "f", "n", "r", "t", "u") local z = v("true", "false", "null") local A = { ["true"] = true, ["false"] = false, ["null"] = nil } local function B(C, D, E, F) for o = D, #C do if E[C:sub(o, o)] ~= F then return o end end; return #C + 1 end
  356.  
  357. ; local function G(C, D, H) local I = 1; local J = 1; for o = 1, D - 1 do J = J + 1; if C:sub(o, o) == "\n" then I = I + 1; J = 1 end end; error(string.format("%s at line %d col %d", H, I, J)) end
  358.  
  359. ; local function K(n) local t = math.floor; if n <= 0x7f then return string.char(n) elseif n <= 0x7ff then return string.char(t(n / 64) + 192, n % 64 + 128) elseif n <= 0xffff then return string.char(t(n / 4096) + 224, t(n % 4096 / 64) + 128, n % 64 + 128) elseif n <= 0x10ffff then return string.char(t(n / 262144) + 240, t(n % 262144 / 4096) + 128, t(n % 4096 / 64) + 128, n % 64 + 128) end; error(string.format("invalid unicode codepoint '%x'", n)) end
  360.  
  361. ; local function L(M) local N = tonumber(M:sub(3, 6), 16) local O = tonumber(M:sub(9, 12), 16) if O then return K((N - 0xd800) * 0x400 + O - 0xdc00 + 0x10000) else return K(N) end end
  362.  
  363. ; local function P(C, o) local Q = false; local R = false; local S = false; local T; for U = o + 1, #C do local V = C:byte(U) if V < 32 then G(C, U, "control character in string") end; if T == 92 then if V == 117 then local W = C:sub(U + 1, U + 5) if not W:find("%x%x%x%x") then G(C, U, "invalid unicode escape in string") end; if W:find("^[dD][89aAbB]") then R = true else Q = true end else local h = string.char(V) if not y[h] then G(C, U, "invalid escape char '" .. h .. "' in string") end; S = true end; T = nil elseif V == 34 then local M = C:sub(o + 1, U - 1) if R then M = M:gsub("\\u[dD][89aAbB]..\\u....", L) end; if Q then M = M:gsub("\\u....", L) end; if S then M = M:gsub("\\.", d) end; return M, U + 1 else T = V end end; G(C, o, "expected closing quote for string") end
  364.  
  365. ; local function X(C, o) local V = B(C, o, x) local M = C:sub(o, V - 1) local n = tonumber(M) if not n then G(C, o, "invalid number '" .. M .. "'") end; return n, V end
  366.  
  367. ; local function Y(C, o) local V = B(C, o, x) local Z = C:sub(o, V - 1) if not z[Z] then G(C, o, "invalid literal '" .. Z .. "'") end; return A[Z], V end
  368.  
  369. ; local function _(C, o) local m = {} local n = 1; o = o + 1; while 1 do local V; o = B(C, o, w, true) if C:sub(o, o) == "]" then o = o + 1; break end; V, o = u(C, o) m[n] = V; n = n + 1; o = B(C, o, w, true) local a0 = C:sub(o, o) o = o + 1; if a0 == "]" then break end; if a0 ~= "," then G(C, o, "expected ']' or ','") end end; return m, o end
  370.  
  371. ; local function a1(C, o) local m = {} o = o + 1; while 1 do local a2, j; o = B(C, o, w, true) if C:sub(o, o) == "}" then o = o + 1; break end; if C:sub(o, o) ~= '"' then G(C, o, "expected string for key") end; a2, o = u(C, o) o = B(C, o, w, true) if C:sub(o, o) ~= ":" then G(C, o, "expected ':' after key") end; o = B(C, o + 1, w, true) j, o = u(C, o) m[a2] = j; o = B(C, o, w, true) local a0 = C:sub(o, o) o = o + 1; if a0 == "}" then break end; if a0 ~= "," then G(C, o, "expected '}' or ','") end end; return m, o end
  372.  
  373. ; local a3 = { ['"'] = P, ["0"] = X, ["1"] = X, ["2"] = X, ["3"] = X, ["4"] = X, ["5"] = X, ["6"] = X, ["7"] = X, ["8"] = X, ["9"] = X, ["-"] = X, ["t"] = Y, ["f"] = Y, ["n"] = Y, ["["] = _, ["{"] = a1 } u = function(C, D) local a0 = C:sub(D, D) local t = a3[a0] if t then return t(C, D) end; G(C, D, "unexpected character '" .. a0 .. "'") end; function json.decode(C) if type(C) ~= "string" then error("expected argument of type string, got " .. type(C)) end; local m, D = u(C, B(C, 1, w, true)) D = B(C, D, w, true) if D <= #C then G(C, D, "trailing garbage") end; return m end
  374.  
  375. ; return a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement