Macro Swapper

Posted by PJ on Sat 10 Aug 2002 04:27 AM — 3 posts, 15,321 views.

USA #0
I play a PK mud and I have trouble with people triple teaming me because I can never keep my macros set for the people I want to kill at certain times. I want to make MUSHclient swap them for me by using a scrip/plugin of some sort.

My idea is this:
A and B are attacking me, I want to be able to have a command to swap my macros from Bodyslam A to Bodyslam B.

The problem with that is that I dont use just one character class, so I'm often using macros like Cast 'Lightning' A or Backstab A..

Is there a way to have it leave the base of my macro alone while it changes A to B?
Australia Forum Administrator #1
An interesting problem. :)

First, I assume by "macros" you are referring to MUSHclient macros, which are things that happen when you press F2, F3 etc.? In that case, we need to migrate the actions that happen into aliases, because aliases give us the power to call scripts, do variable substitution, and so on.

To do that, edit each macro and make them send a string you wouldn't normally use in the MUD - I'll take the example of F2 sending "macro_F2+++" and so on.

To do this quickly, copy the stuff between the lines, and go to the File Menu -> Import -> Clipboard.



<!-- macros -->

<macros>

  <macro name="F2" type="send_now" >
  <send>macro_F2+++</send>
  </macro>

  <macro name="F3" type="send_now" >
  <send>macro_F3+++</send>
  </macro>

  <macro name="F4" type="send_now" >
  <send>macro_F4+++</send>
  </macro>

  <macro name="F5" type="send_now" >
  <send>macro_F5+++</send>
  </macro>
</macros>




Next, we need some aliases to do the actual work (bodyslam, backstab, cast spells etc.). We will target a variable with them so we can quickly modify who they will affect, eg. "bodyslam @target".

Here are some example aliases that do that, note how we match on the string sent by the macro. If you don't want to use F2, F3 etc. but actually type an alias, just make the match string shorter and more meaningful (eg. "bs" for bodyslam).




<aliases>
  <alias
   match="macro_F2+++"
   enabled="y"
   expand_variables="y"
  >
  <send>bodyslam @target</send>
  </alias>
  <alias
   match="macro_F3+++"
   enabled="y"
   expand_variables="y"
  >
  <send>backstab @target</send>
  </alias>
  <alias
   match="macro_F4+++"
   enabled="y"
   expand_variables="y"
  >
  <send>Cast 'Lightning' @target</send>
  </alias>
</aliases>




(You can import those too through the File -> Import if you want to).

Next we want a way of setting up our targets (your A and B) and swapping them. So we need four more aliases, and a small bit of scripting...

Below are the aliases, I am using "seta" to set target A, "setb" to set target B, "swap" to swap between them, and "list_targets" to show what they currently are.




<aliases>
  <alias
   script="On_List_Targets"
   match="list_targets"
   enabled="y"
  >
  </alias>
  <alias
   script="On_Set_A"
   match="seta *"
   enabled="y"
  >
  </alias>
  <alias
   script="On_Set_B"
   match="setb *"
   enabled="y"
  >
  </alias>
  <alias
   script="On_Swap"
   match="swap"
   enabled="y"
  >
  </alias>
</aliases>





The scripts below set and swap the variables - copy and paste into your script file (VBscript). You might make the "swap" one bind to a macro key (eg. make F9 send "swap" would do it).




sub On_Set_A (aliasname, full_line, wildcards)

dim target

  target = wildcards (1)
  world.setvariable "A", target
  world.note "Target A set to " & target

  world.setvariable "target", target
  world.note "Current target now " & target
end sub

sub On_Set_B (aliasname, full_line, wildcards)

dim target

  target = wildcards (1)
  world.setvariable "B", target
  world.note "Target B set to " & target

end sub

sub On_List_Targets (aliasname, full_line, wildcards)

  world.note "Target A = " & world.getvariable ("A")
  world.note "Target B = " & world.getvariable ("B")
  world.note "CURRENT target = " & world.getvariable ("target")

end sub

sub On_Swap (aliasname, full_line, wildcards)

dim A, B

  A = world.getvariable ("A")
  B = world.getvariable ("B")

  if world.getvariable ("target") = A then
     world.setvariable "target", B
  else
     world.setvariable "target", A
  end if

  world.note "Current target now " & world.getvariable ("target")

end sub




To use, set up your targets when required, eg.


seta Wiciedan
setb Miriradon


Then hit your function keys to attack them, and type "swap" (or the function key you have set up to send "swap" to swap between them). Say you made it F9, then you could do this ...


F2 F9 F2


That would send:


bodyslam Wiciedan
bodyslam Miriradon
USA #2
Thanks a ton, Nick, it all worked like a charm!

~Monkey