From 7f689f649c86332ff7609e280192e88abea8dc49 Mon Sep 17 00:00:00 2001 From: Jaime Moreira Date: Mon, 1 Aug 2022 14:31:26 -0400 Subject: [PATCH] Faster weapon switching with 'cycleweap' Allows to skip elements on the weapon list by tapping the same bound key --- doc/050_commands.md | 1 + src/game/g_cmds.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/050_commands.md b/doc/050_commands.md index 6826c3e2..6ca37934 100644 --- a/doc/050_commands.md +++ b/doc/050_commands.md @@ -9,6 +9,7 @@ original clients (Vanilla Quake II) commands are still in place. weapon classnames separated by whitespaces. A weapon in the list is skipped if it is not a valid weapon classname, you do not own it in your inventory or you do not have enough ammo to use it. + By quickly tapping the bound key, you can navigate the list faster. * **prefweap **: Similar to the previous command, this will select the first weapon available in the priority list given. Useful diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c index cb201969..e91ff062 100644 --- a/src/game/g_cmds.c +++ b/src/game/g_cmds.c @@ -1430,6 +1430,7 @@ cycle_weapon(edict_t *ent) int i; int start; int num_weaps; + const char *weapname = NULL; if (!ent) { @@ -1446,11 +1447,20 @@ cycle_weapon(edict_t *ent) num_weaps = gi.argc(); /* find where we want to start the search for the next eligible weapon */ - if (cl->pers.weapon) + if (cl->newweapon) + { + weapname = cl->newweapon->classname; + } + else if (cl->pers.weapon) + { + weapname = cl->pers.weapon->classname; + } + + if (weapname) { for (i = 1; i < num_weaps; i++) { - if (Q_stricmp(cl->pers.weapon->classname, gi.argv(i)) == 0) + if (Q_stricmp(weapname, gi.argv(i)) == 0) { break; }