notaloli

clan tag

Apr 18th, 2021
1,047
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.64 KB | None | 0 0
  1. local globals_realtime = globals.realtime
  2. local globals_curtime = globals.curtime
  3. local globals_frametime = globals.frametime
  4. local globals_absolute_frametime = globals.absoluteframetime
  5. local globals_maxplayers = globals.maxplayers
  6. local globals_tickcount = globals.tickcount
  7. local globals_tickinterval = globals.tickinterval
  8. local globals_mapname = globals.mapname
  9.  
  10. local client_set_event_callback = client.set_event_callback
  11. local client_console_log = client.log
  12. local client_color_log = client.color_log
  13. local client_console_cmd = client.exec
  14. local client_userid_to_entindex = client.userid_to_entindex
  15. local client_get_cvar = client.get_cvar
  16. local client_set_cvar = client.set_cvar
  17. local client_draw_debug_text = client.draw_debug_text
  18. local client_draw_hitboxes = client.draw_hitboxes
  19. local client_draw_indicator = client.draw_indicator
  20. local client_random_int = client.random_int
  21. local client_random_float = client.random_float
  22. local client_draw_text = client.draw_text
  23. local client_draw_rectangle = client.draw_rectangle
  24. local client_draw_line = client.draw_line
  25. local client_draw_gradient = client.draw_gradient
  26. local client_draw_cricle = client.draw_circle
  27. local client_draw_circle_outline = client.draW_circle_outline
  28. local client_world_to_screen = client.world_to_screen
  29. local client_screen_size = client.screen_size
  30. local client_visible = client.visible
  31. local client_delay_call = client.delay_call
  32. local client_latency = client.latency
  33. local client_camera_angles = client.camera_angles
  34. local client_trace_line = client.trace_line
  35. local client_eye_position = client.eye_position
  36. local client_set_clan_tag = client.set_clan_tag
  37. local client_system_time = client.system_time
  38.  
  39. local entity_get_local_player = entity.get_local_player
  40. local entity_get_all = entity.get_all
  41. local entity_get_players = entity.get_players
  42. local entity_get_classname = entity.get_classname
  43. local entity_set_prop = entity.set_prop
  44. local entity_get_prop = entity.get_prop
  45. local entity_is_enemy = entity.is_enemy
  46. local entity_get_player_name = entity.get_player_name
  47. local entity_get_player_weapon = entity.get_player_weapon
  48. local entity_hitbox_position = entity.hitbox_position
  49. local entity_get_steam64 = entity.get_steam64
  50. local entity_get_bounding_box = entity.get_bounding_box
  51. local entity_is_alive = entity.is_alive
  52. local entity_is_dormant = entity.is_dormant
  53.  
  54. local ui_new_checkbox = ui.new_checkbox
  55. local ui_new_slider = ui.new_slider
  56. local ui_new_combobox = ui.new_combobox
  57. local ui_new_multiselect = ui.new_multiselect
  58. local ui_new_hotkey = ui.new_hotkey
  59. local ui_new_button = ui.new_button
  60. local ui_new_color_picker = ui.new_color_picker
  61. local ui_reference = ui.reference
  62. local ui_set = ui.set
  63. local ui_get = ui.get
  64. local ui_set_callback = ui.set_callback
  65. local ui_set_visible = ui.set_visible
  66. local ui_is_menu_open = ui.is_menu_open
  67.  
  68. local math_floor = math.floor
  69. local math_random = math.random
  70. local math_sqrt = math.sqrt
  71. local table_insert = table.insert
  72. local table_remove = table.remove
  73. local table_size = table.getn
  74. local table_sort = table.sort
  75. local string_format = string.format
  76. local string_length = string.len
  77. local string_reverse = string.reverse
  78. local string_sub = string.sub
  79.  
  80. -- Key value table for holding preset clan tags
  81. local clantag = {
  82.  
  83.     ["Skeet"] = "skeet.cc",
  84.     ["Gamer"] = "Gamer",
  85.     ["Noname Blaster"] = "nnblaster",
  86.  
  87. }
  88.  
  89. -- Function for collecting the keys for the clantag combobox
  90. local function getMenuItems()
  91.  
  92.     local names = {}
  93.  
  94.     for k, v in pairs(clantag) do
  95.  
  96.         names[#names + 1] = k
  97.  
  98.     end
  99.  
  100.     table_sort(names)
  101.     table_insert(names, 1, "Disabled")
  102.     table_insert(names, "Custom")
  103.  
  104.     return names
  105.  
  106. end
  107.  
  108. -- Menu
  109. local menu = {
  110.  
  111.     enabled = ui_new_checkbox("MISC", "Miscellaneous", "Clantag changer"),
  112.     clantags = ui_new_combobox("MISC", "Miscellaneous", "Clan tags", getMenuItems()),
  113.     animated = ui_new_checkbox("MISC", "Miscellaneous", "Animated tag"),
  114.     style = ui_new_combobox("MISC", "Miscellaneous", "Animation style", "Default", "Reverse"),
  115.     speed = ui_new_slider("MISC", "Miscellaneous", "Animation speed", 0, 100, 30, true, "%", 1)
  116.  
  117. }
  118.  
  119. -- Variables
  120. local sClanTag
  121. local bSendPacket
  122. local bStaticStatus
  123. local iClanTagIndex
  124. local iClanTagReverseIndex
  125. local iClantTagPreviousIndex
  126. local iTagLength
  127.  
  128. -- Function for handling the menu
  129. local function handleMenu()
  130.  
  131.     if ui_get(menu.enabled) then
  132.  
  133.         ui_set_visible(menu.clantags, true)
  134.         ui_set_visible(menu.animated, true)
  135.  
  136.         if ui_get(menu.animated) then
  137.  
  138.             ui_set_visible(menu.style, true)
  139.             ui_set_visible(menu.speed, true)
  140.  
  141.         else
  142.  
  143.             ui_set_visible(menu.style, false)
  144.             ui_set_visible(menu.speed, false)
  145.  
  146.         end
  147.  
  148.     else
  149.  
  150.         client_set_clan_tag("\0")
  151.         ui_set_visible(menu.clantags, false)
  152.         ui_set_visible(menu.animated, false)
  153.         ui_set_visible(menu.style, false)
  154.         ui_set_visible(menu.speed, false)
  155.  
  156.     end
  157.  
  158. end
  159.  
  160. handleMenu()
  161. ui_set_callback(menu.enabled, handleMenu)
  162. ui_set_callback(menu.animated, handleMenu)
  163.  
  164. -- Run command event
  165. client_set_event_callback("run_command", function(e)
  166.  
  167.     if not ui_get(menu.enabled) then
  168.  
  169.         return
  170.  
  171.     end
  172.  
  173.     -- Checks to see if packets are being sent, and setting the value of bSendPacket
  174.     if e.chokedcommands == 0 then
  175.  
  176.         bSendPacket = false
  177.  
  178.     else
  179.  
  180.         bSendPacket = true
  181.  
  182.     end
  183.  
  184. end)
  185.  
  186. -- Function for updated clantag information
  187. local function handleClanTags()
  188.  
  189.     if not ui_get(menu.enabled) or ui_get(menu.clantags) == "Disabled" then
  190.  
  191.         -- Disabling the clantag if it's set to "Disabled"
  192.         client_set_clan_tag("\0")
  193.         return
  194.  
  195.     end
  196.  
  197.     -- Getting and settings the clantag string
  198.     if ui_get(menu.clantags) == "Custom" then
  199.  
  200.         if sClanTag ~= client_get_cvar("r_eyegloss") then
  201.  
  202.             sClanTag = client_get_cvar("r_eyegloss")
  203.             bStaticStatus = false
  204.  
  205.         end
  206.  
  207.     else
  208.  
  209.         if sClanTag ~= clantag[ui_get(menu.clantags)] then
  210.  
  211.             sClanTag = clantag[ui_get(menu.clantags)]
  212.             bStaticStatus = false
  213.  
  214.         end
  215.  
  216.     end
  217.  
  218.     -- Getting the tag length, and clamping it to 16
  219.     iTagLength = math.min(16, string_length(sClanTag))
  220.  
  221. end
  222.  
  223. handleClanTags()
  224. ui_set_callback(menu.clantags, handleClanTags)
  225.  
  226. -- Animating function
  227. local function animateClanTag(style, index)
  228.  
  229.     if not ui_get(menu.animated) then
  230.  
  231.         return
  232.  
  233.     end
  234.  
  235.     if style == "Default" then
  236.  
  237.         if index == 0 then
  238.  
  239.             sClanTag = "\0"
  240.             index = index + 1
  241.  
  242.         end
  243.  
  244.         client_set_clan_tag(string_sub(sClanTag, 1, index))
  245.  
  246.     elseif style == "Reverse" then
  247.  
  248.         if iClanTagReverseIndex <= iTagLength then
  249.  
  250.             client_set_clan_tag(string_sub(sClanTag, 1, index))
  251.  
  252.         else
  253.  
  254.             if iTagLength - index == 0 then
  255.  
  256.                 sClanTag = "\0"
  257.                 index = iTagLength - 1
  258.  
  259.             end
  260.  
  261.             client_set_clan_tag(string_sub(sClanTag, 1, iTagLength - index))
  262.  
  263.         end
  264.  
  265.     end
  266.  
  267. end
  268.  
  269. -- Paint event (Used so clantag updates while dead)
  270. client_set_event_callback("paint", function(ctx)
  271.  
  272.     if not ui_get(menu.enabled) or ui_get(menu.clantags) == "Disabled" then
  273.  
  274.         return
  275.  
  276.     end
  277.  
  278.     -- Run command only runs while alive, if you're dead you're not sending packets.
  279.     if not entity_is_alive(entity_get_local_player()) then
  280.  
  281.         bSendPacket = false
  282.  
  283.     end
  284.  
  285.     -- Don't update animated tag if choking packets
  286.     if bSendPacket then
  287.  
  288.         return
  289.  
  290.     end
  291.  
  292.     -- Updating clantag information
  293.     handleClanTags()
  294.  
  295.     -- Checking if the clan tag is animated
  296.     if not ui_get(menu.animated) then
  297.  
  298.         -- Setting the static clantag once
  299.         if not bStaticStatus then
  300.  
  301.             client_set_clan_tag(sClanTag)
  302.             bStaticStatus = true
  303.  
  304.         end
  305.  
  306.     else
  307.        
  308.         -- Adding a few characters onto the length to add a slight pause when animating.
  309.         iTagLength = iTagLength + 3
  310.  
  311.     end
  312.  
  313.     -- Getting the current clantag indexes
  314.     iClanTagIndex = math_floor((globals_curtime() * (ui_get(menu.speed) / 10)) % iTagLength + 1)
  315.     iClanTagReverseIndex = math_floor((globals_curtime() * (ui_get(menu.speed) / 10)) % (iTagLength * 2) + 1)
  316.  
  317.     -- Checking if the last index is the same as the current index to avoid spamming
  318.     if iClanTagIndex == iClantTagPreviousIndex then
  319.  
  320.         return
  321.  
  322.     end
  323.  
  324.     -- Setting the previous Index
  325.     iClantTagPreviousIndex = iClanTagIndex
  326.  
  327.     -- Call animation function
  328.     animateClanTag(ui_get(menu.style), iClanTagIndex)
  329.  
  330. end)
Add Comment
Please, Sign In to add comment