Xonotic Forums
[SOLVED] Two weapons on each key? - Printable Version

+- Xonotic Forums (https://forums.xonotic.org)
+-- Forum: Support (https://forums.xonotic.org/forumdisplay.php?fid=3)
+--- Forum: Xonotic - Help & Troubleshooting (https://forums.xonotic.org/forumdisplay.php?fid=4)
+--- Thread: [SOLVED] Two weapons on each key? (/showthread.php?tid=8114)



Two weapons on each key? - FAF - 08-15-2019

Hi
How can I bind two weapons on each key? I would like to fix two weapons on eg. Q.
Can it be done in the cfg?
Thank you


RE: Two weapons on each key? - FAF - 08-15-2019

Is this still actual? Is this the only way?

Source:

Weapon Hook

When you change your active weapon, the game calls the alias cl_hook_activeweapon with a parameter that is the name of the selected weapon. Here's what I do with it:
set bx_weapon "shotgun" // default value
alias cl_hook_activeweapon "bx_weapon ${1}; bx_on_weapon_change" // now we have the current weapon name in a variable, and can execute an action, too!
alias bx_on_weapon_change "hud_panel_physics 3; bx_if_eq ${bx_weapon} laser hud_panel_physics 2" // show speed HUD panel only when laser is selected
I will show one more way to use this variable in the next section.

Weapon Switching

Don't you think that the current way to switch weapons – one, sometimes two per key – is somewhat inefficient? Well, there's a better way. Go to the console and type search cl_weapon* right now.
So, the cl_weaponpriorityN cvars can hold individual weapon cycling lists, to be used by impulse 20N, impulse 21N and impulse 22N. I'll just leave my binds here.

cl_weaponpriority1 "crylink shotgun"; cl_weaponpriority2 "hagar uzi hlac"; cl_weaponpriority3 "rocketlauncher electro grenadelauncher"; cl_weaponpriority4 "minstanex nex rifle"; cl_weaponpriority5 "fireball seeker minelayer porto"; cl_weaponpriority0 "laser hook"
bind 1 "impulse 221"; bind 2 "impulse 222"; bind 3 "impulse 223"; bind 4 "impulse 224"; bind 5 "impulse 225"; bind 6 "impulse 226"
bind Q "bx_if_not_eq ${bx_weapon} laser impulse 220; bx_if_eq ${bx_weapon} laser weaplast" // if not laser, switch to laser, else switch to previous weapon

Weapon Combos

Yes, weaplast command (Q button by default) is useful, but imagine this situation: you have a 2-weapon combo, you keep switching between those weapons, shoot your opponent... but then you need to use the laser, so your 'combo' is broken: now it is one of the weapons and laser. Well, I made a similar bx_invprev command that does just the same, but excludes laser! You can use the laser and then the command can switch back to your combo of 2 weapons.

alias bx_on_weapon_change "bx_save_last_weapon_ ${bx_weapon}" // save new weapon selection
set bx_last_weapons "" //this variable will hold 2 last weapons, separated with space
alias bx_save_last_weapon_ "rpn /bx_last_weapons_temp_ /${1} bx_last_weapons union /shotgun union \"/laser none\" difference =; // save ($1$bx_last_weaponsshotgun)–(lasernone)
····························bx_save_last_weapon_step2_"
alias bx_save_last_weapon_step2_ "bx_save_last_weapon_step3_ ${bx_last_weapons_temp_}" // a relay so we can cut off all arguments except the first 2
alias bx_save_last_weapon_step3_ "bx_last_weapons \"${1 ?} ${2 ?}\""·················· // save the first 2 weapons from the 'set'

alias bx_invprev "bx_switch_weapon2_ ${bx_last_weapons} shotgun shotgun" // shotgun is added in case the variable is empty
alias bx_switch_weapon2_ "weapon_${2}" // many arguments are passed, but we take only the 2nd
bind E "bx_invprev" // it is probably more usual to put Q here, but I use it for laser





RE: Two weapons on each key? - _para - 08-15-2019

I can think of a much simpler solution which switches the bind everytime you press the key.

Into console enter(open shift+esc; you can ctrl+c/v):
Code:
alias weap2 "weapon_blaster; bind <KEY> weap1";
alias weap1 "weapon_devastator; bind <KEY> weap2";
weap1;

you can also cycle with more:

Code:
alias weap3 "weapon_vortex; bind <KEY> weap2";
alias weap2 "weapon_blaster; bind <KEY> weap1";
alias weap1 "weapon_devastator; bind <KEY> weap3";
weap1;

Replace <KEY> with what you want.

Example:
Code:
alias weap2 "weapon_blaster; bind c weap1";
alias weap1 "weapon_devastator; bind c weap2";
weap1;



RE: Two weapons on each key? - FAF - 08-16-2019

Thank you very very much for your answer.

Is this persistent?


RE: Two weapons on each key? - FAF - 08-16-2019

(08-16-2019, 01:11 AM)FAF Wrote: Thank you very very much for your answer.

Is this persistent?

It is not! I have put them in an autoexec.cfg

I now have multiple weapons on different keys, thank you...now I need to practice Smile

What a joy that it could be this simple.


RE: Two weapons on each key? - FAF - 08-16-2019

Anyway to use this per game-type, like only to use on CA?


RE: Two weapons on each key? - Mirio - 08-16-2019

I guess this might work:
Code:
alias cl_hook_gamestart_ca "aliasname1; aliasname2"

You can add as many aliases as you wish with semicolons.
"ca" can be any gamemode.


RE: Two weapons on each key? - FAF - 08-16-2019

(08-16-2019, 06:06 AM)Mirio Wrote: I guess this might work:
Code:
alias cl_hook_gamestart_ca "aliasname1; aliasname2"

You can add as many aliases as you wish with semicolons.
"ca" can be any gamemode.

Thank you, but how do I load the alias without exposing it to dm? How can I call it?

The "alias weap2 "weapon_vortex; bind <key> weap1";" loads up in whatever game-type as it's exposed in autoexec.cfg.

I really need basic instructions as I have not done this before.


RE: Two weapons on each key? - FAF - 08-16-2019

OK. I have now made different cfg files for the different game-types which are called by "alias cl_hook_gamestart_ca "exec ca_exec.cfg". That works, but I loose my default keys when I again join a "dm" game.

Is there a way to reset to default keys in cfg? Like "alias cl_hook_gamestart_dm "exec reset_keys"?


Thank you for helping this noob here Smile


RE: Two weapons on each key? - martin-t - 08-16-2019

You can use cl_hook_gamestart_all for resetting to defaults - it runs each time before the gametype-specific hook. You still need to have an explicit list of keys to reset, there is no built-in reset_keys.


RE: Two weapons on each key? - FAF - 08-16-2019

Thx Martin. I will type in an explicit list of keys to reset...was thinking that I had to but hoped not.
Thx again to all.


RE: Two weapons on each key? - FAF - 08-17-2019

Is there a list, database, or dictionary, with all the different commands that I can use? I have some ideas of what I want, but if I fly in the dark its hard.


RE: Two weapons on each key? - martin-t - 08-17-2019

Yes. Not everything is documented properly. Not everything can be because shit's badly designed. Aliases can't have descriptions. There are also examples in the data repo like a brainfuck interpreter. The config/console lang is turing complete. Additionally the forum has a search feature.


RE: Two weapons on each key? - FAF - 08-17-2019

Thank you, yes found some here and there.
Have been messing with this: unbindall; cvar_resettodefaults_all; exec default.cfg;
... but I resolved to manually entering the binds in the cfg. Works ok.


RE: Two weapons on each key? - FAF - 08-28-2019

Is there a way to set weapon priority to the switch? If there is a priority it does not work.
Code:
alias weap2 "weapon_blaster; bind <KEY> weap1";
alias weap1 "weapon_devastator; bind <KEY> weap2";
weap1;



RE: Two weapons on each key? - _para - 08-28-2019

I don't know there used to be a command like "wait <time>" or something to delay commands.That way you could make it switch back after some time.
But else this is cheap weapon switching where you have to remember the weapon that you get with the binds.

As it works it switches a bind which is saved. So the weapon switching is saved across sessions. To cope with that you could include into the autoexec.cfg a line with "weap1" to make it reset to the right bind on startup.

Other solution would be a reset bind: alias reset_bind "weap1; weapX; weapY"
Where neither weapX nor weapY would be weap2 in that case but the initial bind of other weapon switches.

Then just bind <key> reset_bind and/or put it into the autoexec.cfg.


RE: Two weapons on each key? - FAF - 08-28-2019

Thank you. As it is now, I have put the binds into different exec files, which are loaded from autoexec.cfg.
The only one I really need in quick combat situations is the vortex, so I should probably put than on a key of its own.
Maybe this dual-key setup is not optimal in the long run, but it makes my life easier right now.
Thank you again for your help.