Author Topic: How to "cycle" through weapons or buildable structures with bindings  (Read 16647 times)

zybork

  • Posts: 400
  • Turrets: +68/-72
(This is another bind-related topic, I put it here because I did not find a subforum better suited for this topic. If I am wrong, any moderator may feel free to move this topic.)

Some of you may have witnessed people standing near the armoury and obviously switchting from one weapon to another. Then you may have thought, Wow, cool, there is a bind where you can cycle through weapons, and then desperately tried to find it.

Stop searching. There IS NO such command.

In fact, if you want to achieve such an effect, you have to use the vstr-command in your bindings. A vstr now is nothing else then a string-definition,

Code: [Select]
set FOO "echo hello world"
bind x "vstr FOO"

will do the same like

Code: [Select]
bind x "echo hello world"
Doesn't seem to be very useful, but exactly this command allows you "cycling" effects. For instance, if you want to cycle through the commands "build mgturret","build armory" and "build medistat" with one single key, you can do this via

Code: [Select]
bind x "vstr buildret"
set buildret "build mgturret; bind x vstr buildarm"
set buildarm "build armory; bind x vstr buildmedi"
set buildmedi "build medistat; bind x vstr buildret"

If you now insert this code into your binds, are a builder, and push the x-xutton, that button will cycle through the respective commands.

Because this is a bit inconvenient to hardcode, above all else this code is a pain in the ass to maintain (if you want to change the order of the commands etc.) so I wrote a small python-script that does exactly this for you:

Code: [Select]
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-

# first, the "library"

def vstrname(thekey):
  "return the name of the vstr associatable to thekey"
  return("_BIND_"+thekey+"_")

def bind(thekey,thesequence):
  """
    generate a tremulous-bind,
    bind thekey to thesequence
   
    if thesequence is an array, the FIRST value of thesequence
    will be used as the default setting for that key
   
    This function assumes that you will NOT use a ; at the end of a bind!
  """
  if type(thesequence)!=list:
    result='bind '+thekey+' "'+thesequence+'"'
  else:
    if len(thesequence)==1:
      bind(thekey,thesequence[0])
      return()
    #else:
    myvstr=vstrname(thekey)
    mylen=len(thesequence)
    result = 'bind '+thekey+' "vstr '+myvstr+'0"'
    for i in range(mylen):
      result += '\nset '+myvstr+str(i)+' "'+thesequence[i]+'; bind '+thekey+' vstr '+myvstr+str((i+1)%mylen)+'"'
  print(result)

You now can push this code into a python-interpreter and then add the following command:

Code: [Select]
bind("x",["build mgturret","build armory","build medistat"])
And voila!, this is the result:

Code: [Select]
bind x "vstr _BIND_x_0"
set _BIND_x_0 "build mgturret; bind x vstr _BIND_x_1"
set _BIND_x_1 "build armory; bind x vstr _BIND_x_2"
set _BIND_x_2 "build medistat; bind x vstr _BIND_x_0"

Personally, I of course more sophisticated binds, so the code I use myself is:

Code: [Select]
structure_binds=[
  "echo - turret -; build mgturret; bind MWHEELDOWN build mgturret",
  "echo - armory -; build arm; bind MWHEELDOWN build arm",
  "echo - telenode -; build telenode; bind MWHEELDOWN build telenode",
  "echo - medistation -; build medistat; bind MWHEELDOWN build medistat",
  "echo - defence computer -; build dcc; bind MWHEELDOWN build dcc",
  "echo - tesla generator -; build tesla; bind MWHEELDOWN build tesla",
  "echo - repeater -; build repeater; bind MWHEELDOWN build repeater"
]
bind("0","vstr "+vstrname("x")+"; class ackit; class ckit; sell weapons; buy ackit; buy ckit")
bind("x",structure_binds)

but this is entirely up to you.

I have retired from Tremulous. Definetely. If you play a game just because it has become a habit, but u'r only feeling like a kindergarten teacher - well, maybe I am just getting too old (hell, I was a teenager when DukeNukem3D was *new*) - it's probably not a bad idea to just let it be. And I do.

Don't take this personally. Have fun, guys.

Hendrich

  • Posts: 898
  • Turrets: +168/-149
    • TremCommands
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #1 on: January 10, 2009, 04:16:49 am »
Heh, you could do some crazy stuff with these binds, too bad a friend of mine did this a few months ago, forgot which server, and people banned him because hey thought he had a weapon hack. :/

"ZOMG, WEPON H4X, BAN HAMMER PLZ kthxbai."

Anyways, good job Zybork. A guide for something like this wasn't really made until now, so I guess it'll be one of em' jewels to keep in the reference books.

Caveman

  • Guest
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #2 on: January 10, 2009, 12:40:51 pm »
Thanks for the offer, but there was already a way to do this w/o using python or whatnot.
The confs are flexible enough and can load and rebind on keypress.

zybork

  • Posts: 400
  • Turrets: +68/-72
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #3 on: January 10, 2009, 06:05:38 pm »
Well, that script doesn't do much, it just creates a set of bindings you have to copy into your bindlist manually.

Is there another way to "cycle" through commands then to made excessive use of vstrings? If yes, tell me, I have been looking for it for quite a time without figuring it out.
I have retired from Tremulous. Definetely. If you play a game just because it has become a habit, but u'r only feeling like a kindergarten teacher - well, maybe I am just getting too old (hell, I was a teenager when DukeNukem3D was *new*) - it's probably not a bad idea to just let it be. And I do.

Don't take this personally. Have fun, guys.

Rassilon

  • Posts: 4
  • Turrets: +0/-0
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #4 on: January 12, 2009, 01:56:24 am »
Volt HUD does some neat bindings that give choices like you are talking about from the postings.  If you haven't done a search of bind threads, please do so - between the bind threads and Volt's HUD i am almost set so i can play efficiently.

Good luck with your endeavor.

Kaine

  • Posts: 579
  • Turrets: +543/-314
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #5 on: January 12, 2009, 04:15:21 am »
I just made something kickass and beneficial.  Enjoy.

Thanks Zybork, I've met a lot of people that were really confused with vstrs.  Hopefully your script will benefit some of them.  And even for those it doesn't, they still are able to just copy and paste your code into their cfg.

Props man,
-Kaine

zybork

  • Posts: 400
  • Turrets: +68/-72
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #6 on: January 12, 2009, 01:34:11 pm »
Let's just hope they don't copy the python code into their config ;)
I have retired from Tremulous. Definetely. If you play a game just because it has become a habit, but u'r only feeling like a kindergarten teacher - well, maybe I am just getting too old (hell, I was a teenager when DukeNukem3D was *new*) - it's probably not a bad idea to just let it be. And I do.

Don't take this personally. Have fun, guys.

zybork

  • Posts: 400
  • Turrets: +68/-72
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #7 on: March 22, 2011, 12:33:23 pm »
Sorry for the necro, but I got asked by somebody who was spectating me how I “cycled” through the various buildings, so here it is.

Maybe I'll put this into the wiki.
I have retired from Tremulous. Definetely. If you play a game just because it has become a habit, but u'r only feeling like a kindergarten teacher - well, maybe I am just getting too old (hell, I was a teenager when DukeNukem3D was *new*) - it's probably not a bad idea to just let it be. And I do.

Don't take this personally. Have fun, guys.

Kasofa

  • Posts: 69
  • Turrets: +5/-2
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #8 on: March 23, 2011, 11:24:13 pm »
I was thinking about something like this for evolutions, except that it would be more like this: Spawn dretch, press the gkey, then press a number key which corresponds to one of the aliens/guns, and then have the number keys again free to use after pressing one to evolve.

-K

zybork

  • Posts: 400
  • Turrets: +68/-72
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #9 on: March 24, 2011, 01:04:58 am »
Hm, shouldn't be too hard to do, you just need a hell of a long bind for the “modififer” key to set all the keys from 0 to 9, do you need it for aliens only, or do you simply want to change bindings for humans and aliens? In that case, a humans.cfg and an aliens.cfg would actually be more appropriate.
I have retired from Tremulous. Definetely. If you play a game just because it has become a habit, but u'r only feeling like a kindergarten teacher - well, maybe I am just getting too old (hell, I was a teenager when DukeNukem3D was *new*) - it's probably not a bad idea to just let it be. And I do.

Don't take this personally. Have fun, guys.

OhaiReapd

  • Guest
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #10 on: March 25, 2011, 12:39:44 am »
Lol @ binders.......... There's code already on Volt's HUD for this. Press 1 and then 1-8 for aliens. Then 1-0 for humans with '-' and '=' for Jetpack and bsuit.

F50

  • Posts: 740
  • Turrets: +16/-26
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #11 on: March 25, 2011, 01:57:50 am »
How do you think the HUD does it?

There are several ways to do this, you can either bind everything to "vstr variablename" and then "set variablename" for each key that you want to change the binds for, or you can dynamically re-bind your keys (my personal preference) which is essentially the same thing except with "bind KEY class level0; bind KEY class level1;" etc, or can bind your chosen key to things like "exec humanbuy.cfg", which can then use either of the above methods, in a potentially more readable form.

Also, I highly recommend making use of cg_humanConfig and cg_alienConfig.
"Any sufficiently advanced stupidity is indistinguishable from malice." -- Grey's Law


zybork

  • Posts: 400
  • Turrets: +68/-72
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #12 on: March 25, 2011, 02:09:20 pm »
Hm, cg_humanConfig & Co. are new in 1.2, and since I do not use menus anymore and do almost everything via binding, personally I don't need it, but if I'd start over with my bindings, it would definetely be a good idea.
I have retired from Tremulous. Definetely. If you play a game just because it has become a habit, but u'r only feeling like a kindergarten teacher - well, maybe I am just getting too old (hell, I was a teenager when DukeNukem3D was *new*) - it's probably not a bad idea to just let it be. And I do.

Don't take this personally. Have fun, guys.

OhaiReapd

  • Guest
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #13 on: March 26, 2011, 05:59:44 am »
How do you think the HUD does it?

There are several ways to do this, you can either bind everything to "vstr variablename" and then "set variablename" for each key that you want to change the binds for, or you can dynamically re-bind your keys (my personal preference) which is essentially the same thing except with "bind KEY class level0; bind KEY class level1;" etc, or can bind your chosen key to things like "exec humanbuy.cfg", which can then use either of the above methods, in a potentially more readable form.

Also, I highly recommend making use of cg_humanConfig and cg_alienConfig.

I know how it works. Clearly they don't. I already have a set of binds which ill probably post.

DraZiLoX

  • Posts: 844
  • Turrets: +24/-24
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #14 on: March 26, 2011, 10:52:40 am »
Code: [Select]
set human_buildable_one "build mgturret; bind MWHEELDOWN vstr human_buildable_two;bind MWHEELUP vstr human_buildable_eight"
set human_buildable_two "build tesla; bind MWHEELDOWN vstr human_buildable_three;bind MWHEELUP vstr human_buildable_one"
set human_buildable_three "build telenode; bind MWHEELDOWN vstr human_buildable_four;bind MWHEELUP vstr human_buildable_two"
set human_buildable_four "build arm; bind MWHEELDOWN vstr human_buildable_five;bind MWHEELUP vstr human_buildable_three"
set human_buildable_five "build medistat; bind MWHEELDOWN vstr human_buildable_six;bind MWHEELUP vstr human_buildable_four"
set human_buildable_six "build dcc; bind MWHEELDOWN vstr human_buildable_seven;bind MWHEELUP vstr human_buildable_five"
set human_buildable_seven "build reactor; bind MWHEELDOWN vstr human_buildable_eight;bind MWHEELUP vstr human_buildable_six"
set human_buildable_eight "build repeater; bind MWHEELDOWN vstr human_buildable_one;bind MWHEELUP vstr human_buildable_seven"

bind MOUSE3 "vstr human_buildable_one"

eDIT:
tl;dr, you were talking about scrolling through weapons/buildables, right?
eDIT2:Weapons!
Code: [Select]
set h_w_0 "sell weapons;sell upgrades;buy ackit;buy ckit;buy larmour;buy helmet;bind MWHEELDOWN vstr h_w_1;bind MWHEELUP vstr h_w_9"
set h_w_1 "sell weapons;sell upgrades;buy rifle;buy larmour;buy helmet;bind MWHEELDOWN vstr h_w_2;bind MWHEELUP vstr h_w_0"
set h_w_2 "sell weapons;sell upgrades;buy psaw;buy larmour;buy helmet;bind MWHEELDOWN vstr h_w_3;bind MWHEELUP vstr h_w_1"
set h_w_3 "sell weapons;sell upgrades;buy shotgun;buy larmour;buy helmet;bind MWHEELDOWN vstr h_w_4;bind MWHEELUP vstr h_w_2"
set h_w_4 "sell weapons;sell upgrades;buy lgun;buy larmour;buy helmet;buy battpack;bind MWHEELDOWN vstr h_w_5;bind MWHEELUP vstr h_w_3"
set h_w_5 "sell weapons;sell upgrades;buy mdriver;buy larmour;buy helmet;buy battpack;bind MWHEELDOWN vstr h_w_6;bind MWHEELUP vstr h_w_4"
set h_w_6 "sell weapons;sell upgrades;buy chaingun;buy larmour;buy helmet;bind MWHEELDOWN vstr h_w_7;bind MWHEELUP vstr h_w_5"
set h_w_7 "sell weapons;sell upgrades;buy flamer;buy larmour;buy helmet;bind MWHEELDOWN vstr h_w_8;bind MWHEELUP vstr h_w_6"
set h_w_8 "sell weapons;sell upgrades;buy prifle;buy larmour;buy helmet;buy battpack;bind MWHEELDOWN vstr h_w_9;bind MWHEELUP vstr h_w_7"
set h_w_9 "sell weapons;sell upgrades;buy lcannon;buy larmour;buy helmet;buy battpack;bind MWHEELDOWN vstr h_w_0;bind MWHEELUP vstr h_w_8"
bind MWHEELDOWN "vstr h_w_0"
bind MWHEELUP "vstr h_w_0"
« Last Edit: March 27, 2011, 06:06:18 pm by DraZiLoX »

OhaiReapd

  • Guest
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #15 on: March 27, 2011, 03:23:48 pm »
Drazzzzzi!! I love those binds. But I cart forsake my standard binds:[ That and my mouse wheel is fucked up..D:

DraZiLoX

  • Posts: 844
  • Turrets: +24/-24
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #16 on: March 27, 2011, 06:06:41 pm »
Drazzzzzi!! I love those binds. But I cart forsake my standard binds:[ That and my mouse wheel is fucked up..D:
Thanks! Added weapon scroll binds too.

CreatureofHell

  • Posts: 2422
  • Turrets: +430/-126
    • Tremtopia
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #17 on: March 27, 2011, 08:35:59 pm »
How do you think the HUD does it?

There are several ways to do this, you can either bind everything to "vstr variablename" and then "set variablename" for each key that you want to change the binds for, or you can dynamically re-bind your keys (my personal preference) which is essentially the same thing except with "bind KEY class level0; bind KEY class level1;" etc, or can bind your chosen key to things like "exec humanbuy.cfg", which can then use either of the above methods, in a potentially more readable form.

Also, I highly recommend making use of cg_humanConfig and cg_alienConfig.

I know how it works. Clearly they don't. I already have a set of binds which ill probably post.
Not everyone uses a non-default HUD.
{NoS}StalKer
Quote
<Timbo> posting on the trem forums rarely results in anything good

Kasofa

  • Posts: 69
  • Turrets: +5/-2
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #18 on: March 28, 2011, 07:42:59 pm »
How do you load a cgf while playing?

-K

DraZiLoX

  • Posts: 844
  • Turrets: +24/-24
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #19 on: March 28, 2011, 07:47:39 pm »
Code: [Select]
/exec filename.cfg

Pazuzu

  • Posts: 987
  • Turrets: +50/-12
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #20 on: March 30, 2011, 03:47:57 am »
Apropos of this:
Code: [Select]
set wep "itemact weapon; bind x vstr blaster"
set blaster "itemact blaster; bind x vstr wep"
bind x "vstr blaster"
This binds x to switch between the blaster and whatever weapon you have (for those who don't have something like this already).

ok, can you give me the tool thingy app that can code?

Meisseli

  • Spam Killer
  • *
  • Posts: 765
  • Turrets: +83/-25
Re: How to "cycle" through weapons or buildable structures with bindings
« Reply #21 on: March 31, 2011, 05:56:12 pm »
Apropos of this:
Code: [Select]
set wep "itemact weapon; bind x vstr blaster"
set blaster "itemact blaster; bind x vstr wep"
bind x "vstr blaster"
This binds x to switch between the blaster and whatever weapon you have (for those who don't have something like this already).
No, "itemtoggle blaster" works just fine.