Autofight with custom movement keys


Problems running or configuring the software, commands & options, compiling, different platforms, using the interface, documentation, etc.

Lair Larrikin

Posts: 27

Joined: Friday, 20th March 2015, 21:13

Post Thursday, 5th November 2015, 18:55

Autofight with custom movement keys

Hi, I've had this problem for years, and it's one of the reasons I primarily play offline.

Basically autofight.lua has the game's default movement keys hardcoded, and if I hit Tab while using custom movement keys (I use qwe/ad/zxc) it will attempt to use the default keys instead. I had to fix this by manually editing my autofight.lua file and changing the keys to the ones I use.

No problem, but I obviously can't do that when I play online in a tournament. Can anyone please suggest a way for me to implement autofight into my rcfile that will work with my hotkeys?
User avatar

Dungeon Master

Posts: 502

Joined: Wednesday, 7th March 2012, 13:25

Location: Lexington, KY, US

Post Thursday, 5th November 2015, 19:11

Re: Autofight with custom movement keys

Celerity wrote:Hi, I've had this problem for years, and it's one of the reasons I primarily play offline.

Basically autofight.lua has the game's default movement keys hardcoded, and if I hit Tab while using custom movement keys (I use qwe/ad/zxc) it will attempt to use the default keys instead. I had to fix this by manually editing my autofight.lua file and changing the keys to the ones I use.

No problem, but I obviously can't do that when I play online in a tournament. Can anyone please suggest a way for me to implement autofight into my rcfile that will work with my hotkeys?


You can try copy-pasting the code from your custom autofight.lua into a {{ }} block in your rc file. Or, really, you only need to include the changed functions: delta_to_vi if you only changed the movement keys; attack_fire attack_fire_stop and attack_reach if you rebound 'f', 'r', 'v', or '.'; and attack if you rebound 's'.

Lair Larrikin

Posts: 27

Joined: Friday, 20th March 2015, 21:13

Post Friday, 6th November 2015, 08:12

Re: Autofight with custom movement keys

neil wrote:
Celerity wrote:Hi, I've had this problem for years, and it's one of the reasons I primarily play offline.

Basically autofight.lua has the game's default movement keys hardcoded, and if I hit Tab while using custom movement keys (I use qwe/ad/zxc) it will attempt to use the default keys instead. I had to fix this by manually editing my autofight.lua file and changing the keys to the ones I use.

No problem, but I obviously can't do that when I play online in a tournament. Can anyone please suggest a way for me to implement autofight into my rcfile that will work with my hotkeys?


You can try copy-pasting the code from your custom autofight.lua into a {{ }} block in your rc file. Or, really, you only need to include the changed functions: delta_to_vi if you only changed the movement keys; attack_fire attack_fire_stop and attack_reach if you rebound 'f', 'r', 'v', or '.'; and attack if you rebound 's'.


When I copy the following into a totally clean rcfile (with just the keybinds):

  Code:
{{
local function delta_to_vi(dx, dy)
  local d2v = {
    [-1] = { [-1] = 'q', [0] = 'a', [1] = 'z'},
    [0]  = { [-1] = 'w',            [1] = 'x'},
    [1]  = { [-1] = 'e', [0] = 'd', [1] = 'c'},
  }
  return d2v[dx][dy]
end
 }}


It returns the Lua error "unexpected symbol near '{'" (in the first line). If I remove a set of {} brackets, it returns an unexpected symbol error in the e/d/c line.

Ziggurat Zagger

Posts: 6454

Joined: Tuesday, 30th October 2012, 19:06

Post Friday, 6th November 2015, 08:56

Re: Autofight with custom movement keys

Celerity wrote:
neil wrote:
Celerity wrote:Hi, I've had this problem for years, and it's one of the reasons I primarily play offline.

Basically autofight.lua has the game's default movement keys hardcoded, and if I hit Tab while using custom movement keys (I use qwe/ad/zxc) it will attempt to use the default keys instead. I had to fix this by manually editing my autofight.lua file and changing the keys to the ones I use.

No problem, but I obviously can't do that when I play online in a tournament. Can anyone please suggest a way for me to implement autofight into my rcfile that will work with my hotkeys?


You can try copy-pasting the code from your custom autofight.lua into a {{ }} block in your rc file. Or, really, you only need to include the changed functions: delta_to_vi if you only changed the movement keys; attack_fire attack_fire_stop and attack_reach if you rebound 'f', 'r', 'v', or '.'; and attack if you rebound 's'.


When I copy the following into a totally clean rcfile (with just the keybinds):

  Code:
{{
local function delta_to_vi(dx, dy)
  local d2v = {
    [-1] = { [-1] = 'q', [0] = 'a', [1] = 'z'},
    [0]  = { [-1] = 'w',            [1] = 'x'},
    [1]  = { [-1] = 'e', [0] = 'd', [1] = 'c'},
  }
  return d2v[dx][dy]
end
 }}


It returns the Lua error "unexpected symbol near '{'" (in the first line). If I remove a set of {} brackets, it returns an unexpected symbol error in the e/d/c line.

It shouldn't have a trailing comma after the 'c'} should it?
Spoiler: show
This high quality signature has been hidden for your protection. To unlock it's secret, send 3 easy payments of $9.99 to me, by way of your nearest theta band or ley line. Complete your transmission by midnight tonight for a special free gift!

Lair Larrikin

Posts: 27

Joined: Friday, 20th March 2015, 21:13

Post Friday, 6th November 2015, 09:08

Re: Autofight with custom movement keys

Siegurt wrote:
Celerity wrote:When I copy the following into a totally clean rcfile (with just the keybinds):

  Code:
{{
local function delta_to_vi(dx, dy)
  local d2v = {
    [-1] = { [-1] = 'q', [0] = 'a', [1] = 'z'},
    [0]  = { [-1] = 'w',            [1] = 'x'},
    [1]  = { [-1] = 'e', [0] = 'd', [1] = 'c'},
  }
  return d2v[dx][dy]
end
 }}


It returns the Lua error "unexpected symbol near '{'" (in the first line). If I remove a set of {} brackets, it returns an unexpected symbol error in the e/d/c line.

It shouldn't have a trailing comma after the 'c'} should it?


That's how it is in the source code: https://github.com/crawl/crawl/blob/mas ... ofight.lua

Regardless, removing the comma didn't help. Now it's back to the default behavior, it's using the default hotkeys instead of the custom function.
User avatar

Dungeon Master

Posts: 502

Joined: Wednesday, 7th March 2012, 13:25

Location: Lexington, KY, US

Post Friday, 6th November 2015, 13:39

Re: Autofight with custom movement keys

Oops, should be just single { }

Lair Larrikin

Posts: 27

Joined: Friday, 20th March 2015, 21:13

Post Friday, 6th November 2015, 15:07

Re: Autofight with custom movement keys

neil wrote:Oops, should be just single { }


Right, but like I said, it does nothing. It's the same behavior as if I put nothing in my rcfile at all.

Edit: Someone also suggested I try < > brackets, but no difference. Isn't there some way I can exclude autofight.lua? I feel like it's overwriting the custom function, since they both share the same name.

Dungeon Master

Posts: 585

Joined: Sunday, 9th June 2013, 17:13

Post Saturday, 7th November 2015, 08:52

Re: Autofight with custom movement keys

Ok, this took a while to track down all the problems, but there are a couple issues I ran into before making this work. Two things you need to do: (1) Use the RC file here, which is your 0.17 RC on CSZO modified to have the contents of autofight.lua at the end with the necessary changes to delta_to_vi(). Then (2) override your TAB key with a macro to have a target of ===hit_closest and then override Shift+TAB to have a target of ===hit_closest_nomove if you'd like that as well. If you don't make a macro for TAB, it tries to call the mapping for CTRL-I, which you have mapped to memorize spell. You can use CTRL-D or ~ to set a macro.

Some additional details I found:

It seems you do need the full contents of autofight instead of just the delta_to_vi function. Furthermore it seems that for lua coming in from an rc file, clua doesn't like it on line five of the original delta_to_vi() how the array is terminated with a brace on its own line. You may not have gotten this error, but I'm getting it on my Linux system. The original delta_to_vi() function is left below the modified one but commented out, for comparison.

Finaly, in the modified RC I posted, I removed a couple bindkey statements for commands that no longer exist: CMD_SEARCH, CMD_LIST_WEAPONS, and CMD_LIST_EQUIPMENT.

For this message the author gammafunk has received thanks:
Celerity

Dungeon Master

Posts: 585

Joined: Sunday, 9th June 2013, 17:13

Post Saturday, 7th November 2015, 09:13

Re: Autofight with custom movement keys

Follow-up:

After some discussion I realized the syntax error I was getting from that line is due to the use of { and } as code block delimiters in the RC; the parser is seeing that } by itself in delta_to_vi() as a termination of the code block. Using < and > instead to open and close the RC code blocks would prevent this from being an issue. You still need to include all of autofight.lua in your rc in order to get a working autofight, however.

Another thing: If you remove the bindkey mapping you have for ^I to Memorize Spell, you don't need the macro for TAB. But if you'd that bindkey to work, I think you do need the TAB macro to ===hit_closest

For this message the author gammafunk has received thanks:
Celerity

Return to Technical Support

Who is online

Users browsing this forum: No registered users and 23 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.