Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------------------------------------------------
- -- Caching common functions
- --------------------------------------------------------------------------------
- local client_set_clan_tag, client_set_event_callback, client_system_time, entity_get_local_player, entity_get_player_resource, entity_get_prop, entity_is_alive, globals_curtime, math_floor, string_format, string_rep, table_insert, table_sort, ui_get, ui_new_checkbox, ui_new_combobox, ui_new_slider, ui_new_textbox, ui_set_callback, ui_set_visible, pairs = client.set_clan_tag, client.set_event_callback, client.system_time, entity.get_local_player, entity.get_player_resource, entity.get_prop, entity.is_alive, globals.curtime, math.floor, string.format, string.rep, table.insert, table.sort, ui.get, ui.new_checkbox, ui.new_combobox, ui.new_slider, ui.new_textbox, ui.set_callback, ui.set_visible, pairs
- --------------------------------------------------------------------------------
- -- Utility functions
- --------------------------------------------------------------------------------
- local function collect_keys(tbl, custom)
- local keys = {}
- for k in pairs(tbl) do
- keys[#keys + 1] = k
- end
- table_sort(keys)
- if custom then
- table_insert(keys, 1, "Disabled")
- table_insert(keys, "Custom")
- end
- return keys
- end
- --------------------------------------------------------------------------------
- -- Constants and variables
- --------------------------------------------------------------------------------
- local tags = {
- ["Toeaim"] = "toeaim.gov",
- ["Correct"] = "correct",
- ["Blaster"] = "nnblaster",
- ["Opulence"] = "opulence.cc",
- ["Nixware"] = "nixware.cc",
- ["Degadant"] = "degada.nt"
- }
- local tag = ""
- local tag_index = 0
- local tag_length = 0
- local tag_reverse = 0
- local tag_last_index = 0
- local commands = 0
- --------------------------------------------------------------------------------
- -- Clan tag animations
- --------------------------------------------------------------------------------
- local function static()
- if tag == "Disabled" then
- return
- end
- local local_player = entity_get_local_player()
- local current_tag = entity_get_prop(entity_get_player_resource(), "m_szClan", local_player)
- if tag:len() == 0 and current_tag:len() ~= 0 then
- client_set_clan_tag("\0")
- elseif current_tag ~= tag then
- client_set_clan_tag(tag)
- end
- end
- local function time()
- local h, m, s = client_system_time()
- local time_tag = string_format("%d:%02d:%02d", h, m, s)
- client_set_clan_tag(time_tag)
- end
- local function default()
- if tag_index == tag_last_index then
- return
- end
- client_set_clan_tag(tag_index == 0 and "\0" or tag:sub(1, tag_index))
- end
- local function reverse()
- if tag_index == tag_last_index then
- return
- end
- if tag_reverse <= tag_length then
- client_set_clan_tag(tag:sub(1, tag_index))
- else
- client_set_clan_tag(tag_length - tag_index == 0 and "\0" or tag:sub(1, tag_length - tag_index))
- end
- end
- local function loop()
- if tag_index == tag_last_index then
- return
- end
- local result = ""
- local loop_tag = tag
- for i=1, tag_index do
- loop_tag = loop_tag .. loop_tag:sub(1, 1)
- loop_tag = loop_tag:sub(2, loop_tag:len())
- end
- client_set_clan_tag(loop_tag)
- end
- local animations = {
- ["Static"] = static,
- ["Time"] = time,
- ["Default"] = default,
- ["Reverse"] = reverse,
- ["Classic"] = loop,
- ["Loop"] = loop,
- }
- --------------------------------------------------------------------------------
- -- Menu
- --------------------------------------------------------------------------------
- local menu = {
- enabled = ui_new_checkbox("LUA", "B", "Clan tag changer"),
- tags = ui_new_combobox("LUA", "B", "Tags", collect_keys(tags, true)),
- text = ui_new_textbox("LUA", "B", "Text"),
- styles = ui_new_combobox("LUA", "B", "Animation", collect_keys(animations, false)),
- speed = ui_new_slider("LUA", "B", "Speed", 0, 100, 30, true, "%")
- }
- local function handle_menu()
- local state = ui_get(menu.enabled)
- local menu_tag = ui_get(menu.tags)
- ui_set_visible(menu.tags, state)
- ui_set_visible(menu.styles, state)
- ui_set_visible(menu.speed, state)
- ui_set_visible(menu.text, state and menu_tag == "Custom")
- if not state then
- client_set_clan_tag("\0")
- end
- end
- handle_menu()
- ui_set_callback(menu.enabled, handle_menu)
- ui_set_callback(menu.tags, handle_menu)
- --------------------------------------------------------------------------------
- -- Game event handling
- --------------------------------------------------------------------------------
- local function net_update_end()
- if not ui_get(menu.enabled) then
- return
- end
- local local_player = entity_get_local_player()
- local menu_tag = ui_get(menu.tags)
- local tag_style = ui_get(menu.styles)
- local update_tag = commands == 0 or entity_is_alive(local_player) == false
- if menu_tag == "Disabled" then
- return
- end
- tag = menu_tag == "Custom" and ui_get(menu.text) or tags[menu_tag]
- tag = tag_style == "Loop" and tag .. " " or tag
- tag = tag_style == "Classic" and tag .. string_rep(" ", math_floor(tag:len() * 2)) or tag
- tag_length = tag:len()
- tag_index = math_floor((globals_curtime() * ui_get(menu.speed) / 10) % tag_length + 1)
- tag_reverse = math_floor((globals_curtime() * ui_get(menu.speed) / 10) % (tag_length * 2) + 1)
- if not update_tag then
- return
- end
- local animation = animations[tag_style]
- animation()
- tag_last_index = tag_index
- end
- local function run_command(cmd)
- if not ui_get(menu.enabled) then
- return
- end
- commands = cmd.chokedcommands
- end
- local function shutdown()
- client_set_clan_tag("\0")
- end
- client_set_event_callback("net_update_end", net_update_end)
- client_set_event_callback("run_command", run_command)
- client_set_event_callback("shutdown", shutdown)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement