From 748dbe812bd22688e9a5104a4fa3a488b4c75aa7 Mon Sep 17 00:00:00 2001 From: paumann Date: Wed, 24 May 2023 19:30:42 +0200 Subject: [PATCH] Initial commit --- knives.py | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 knives.py diff --git a/knives.py b/knives.py new file mode 100644 index 0000000..ca687d4 --- /dev/null +++ b/knives.py @@ -0,0 +1,103 @@ +import argparse +import shutil +import sys +from pathlib import Path + +# Change this order or remove elements to change the ingame knife order +# Make sure that the knive names are correct +KNIVES = [ + "weapon_knife_karambit", + "weapon_knife_m9_bayonet", + "weapon_bayonet", + "weapon_knife_butterfly", + "weapon_knife_flip", + "weapon_knife_gut", + "weapon_knife_push", + "weapon_knife_tactical", + "weapon_knife_falchion", + "weapon_knife_survival_bowie", + "weapon_knife_ursus", + "weapon_knife_gypsy_jackknife", + "weapon_knife_stiletto", + "weapon_knife_widowmaker", + "weapon_knife_ghost", + "weapon_knife_css", + "weapon_knife_canis", + "weapon_knife_cord", + "weapon_knife_outdoor", + "weapon_knife_skeleton", +] + +# For a list of available hotkeys, see https://totalcsgo.com/binds/keys +HOTKEY = "KP_END" + +# You should not have to change anything below here ! +# ------------------------------------------------------------------------------------ # + +CFG_CONTENT = ( + "ent_fire weapon_knifegg kill\n" + "give {knife}\n" + 'script DoEntFire("weapon_knife", "addoutput", "classname weapon_knifegg", 0, null, null)\n' + 'bind {hotkey} "exec knives/{next_cfg}"\n' + "slot3\n" +) + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "--cfg", + "-c", + type=Path, + default=Path( + "C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Global Offensive\csgo\cfg" + ), + help="CSGO cfg directory. Assumes default windows path if not specified.", + ) + args = parser.parse_args() + cfg: Path = args.cfg + + # Check if cfg directory is correct + if not cfg.exists(): + sys.exit("Error: cfg directory does not exist.") + if not cfg.name == "cfg": + sys.exit(f"Error: cfg directory must be named 'cfg' (not {cfg.name})") + + # Create `knives` subdirectory + knives = cfg / "knives" + + # If already exists, ask if current should be overwritten + if knives.exists(): + while True: + overwrite = input( + "Warning: cfg/knives directory already exists. Continue and overwrite? (y/n) " + ).lower() + if overwrite == "y": + shutil.rmtree(knives) + break + elif overwrite == "n": + sys.exit("Aborted") + + knives.mkdir() + + # For each knive, create cfg file + for index, knife in enumerate(KNIVES): + # Create file + knife_cfg = knives / f"{index:02d}_{KNIVES[index]}.cfg" + + # Next index in knife list (rotate) + next_index = (index + 1) % len(KNIVES) + + # Drop default knife initially + content = CFG_CONTENT.format( + knife=knife, + next_cfg=f"{next_index:02d}_{KNIVES[next_index]}", + hotkey=HOTKEY, + ) + + # Write to file + with open(knife_cfg, "w") as knife_cfg_file: + knife_cfg_file.write(content) + + # Done! Show user initial bind line + print("Done! Add this line to your config for the initial knife drop:") + print(f'bind {HOTKEY} "use weapon_knife; drop; exec knives/00_{KNIVES[0]}"')