Help - Search - Members - Calendar
Full Version: Plugins/accelerators/macro
Achaea's Forums > Off-Topic > Tech Support > Client Help
Nitro
How the hell can you add a macro to a plugin? I'm trying to add a simple 'KICK -target-' macro, but somehow it fails to work. Can you add Accelerators to plugings, or are they bound to the main script? Coding a simple macro in MUSHclient IS rocketscience.

And an additional question can you capture pluginbroadcasts in the main script?
Belus
The only way I could get it to work was with the Macro calling an alias which in turn called a script.

CODE
<!DOCTYPE muclient[]>

<muclient>
<plugin
   name="Example"
   author="Belus"
   id="id#"
   language="Lua"
   purpose="purpose"
   save_state="n"
   date_written="2009-9-3"
   requires="4.40"
   version="0.1">
</plugin>

<aliases>

<alias
    group="Offense_System"
    name="Envenom"
    match="^envenom (\w+), (\w+), (\w+)$"
    enabled="y"
    echo_alias="y"
    regexp="y"
    send_to="12">
        <send>
        envenom("%1", "%2", "%3")
    </send>
</alias>

<alias
    group="Offense_System"
    name="Yank"
    match="^yank$"
    enabled="y"
    echo_alias="n"
    regexp="y"
    send_to="12">
    <send>
        Send("yank " .. target.name)
    </send>
</alias>

</aliases>

<script>
<![CDATA[

function envenom(venom1, venom2, illusiontype)
    if system.debug == 1 then Note("ln3436: Entered function - envenom(" .. venom1 .. ", " .. venom2 .. ", " .. illusiontype .. ")") end
    if IsLogOpen() then WriteLog("offensive function called: envenom(" .. venom1 .. ", " .. venom2 ..", " .. illusiontype .. ")") end
    SendNoEcho("secrete " .. venom1 .. " on dirk")
    SendNoEcho("secrete " .. venom2 .. " on dirk")
    table.insert(illusions, 1, illusiontype)
end -- fuction envenom

AcceleratorTo ("\\", "yank", 10)
AcceleratorTo ("Decimal", "envenom vernalius, xentio, herb", 10)

]]>
</script>

</muclient>
Mymyc
QUOTE (Nitro @ Sep 3 2009, 02:45 PM) *
How the hell can you add a macro to a plugin? I'm trying to add a simple 'KICK -target-' macro, but somehow it fails to work. Can you add Accelerators to plugings, or are they bound to the main script? Coding a simple macro in MUSHclient IS rocketscience.


Putting a world into the @target variable with an alias in LUA:
alias: target *
SetVariable("target","%1")

syntax: target santar

In theory adding a macro key inside another LUA script is: Accelerator("F2","KICK @target") where target is the name of the variable containing a single word (eg: santar), you should check the EXPAND VARIABLES option else calling @target will not put the world "santar" after the world "KICK" in your F2 macro key.
Nitro
Bleh, that's complicated. But it gave me an idea.
Mymyc
QUOTE (Nitro @ Sep 3 2009, 04:41 PM) *
Bleh, that's complicated. But it gave me an idea.


A plugin is a long LUA script, so SetVariable/GetVariable and Accelerator functions should work out of the box.
Nitro
How I solved it:

AcceleratorTo ("F4", "domacro F4", sendto.execute)


CODE
<alias match="domacro *" enabled="y" sequence="100" send_to="12">
<send>
if "%1"=="F4" then
Send("gut " .. target)
end
</send>
</alias>


Allows for easy addition of other macros.
Soludra
QUOTE (Nitro @ Sep 3 2009, 05:45 AM) *
Coding a simple macro in MUSHclient IS rocketscience.

I wouldn't say that, but they are far more complex than they need to be. unsure.gif

QUOTE (Nitro @ Sep 3 2009, 05:45 AM) *
And an additional question can you capture pluginbroadcasts in the main script?

Not directly. I have a plugin that works indirectly, but only for Lua, and it's somewhat broken right now anyways. It catches plugin broadcasts, then Execute()'s a line using the scripting prefix, containing the broadcasted data, executing a function in the script file. It's very much a hack, but there's no easy way otherwise.
Soludra
QUOTE (Nitro @ Sep 3 2009, 07:52 AM) *
How I solved it:

AcceleratorTo ("F4", "domacro F4", sendto.execute)


CODE
<alias match="domacro *" enabled="y" sequence="100" send_to="12">
<send>
if "%1"=="F4" then
Send("gut " .. target)
end
</send>
</alias>


Allows for easy addition of other macros.



This might be marginally more helpful:

CODE
-- Call this to add a function macro
function CreatePluginMacro(key, func_name, data)
  AcceleratorTo(key, "CallPlugin('" .. GetPluginID() .. "', '" .. func_name .. "', '" .. data .. "')", 12)
end

-- Macro functions can only accept one string parameter
function my_macro(str)
  Note("This string was passed to me: ", str)
end

CreatePluginMacro("F4", "my_macro", "data_on_keypress")


Personally, I prefer this because it's cleaner; you don't leave middleman aliases hanging around for the unsuspecting user to accidentally use. Personally, my preference is to leave as much of the user's direct interface untouched, i.e. aliases and keybindings. Aliases are obviously a necessity; I just ensure I don't create too many, and I probably stick to just one base "verb" (like, HARVESTER <options> would be the root alias for all of my Harvester plugin aliases). Keybindings I'm less fond of being created by the plugins. If a user wants a binding, they can make one easily, but if you just add a keybinding to F4, and say they already have one there, you could make them scratch their head and/or punch their screen.
Trevize
QUOTE (Nitro @ Sep 3 2009, 10:52 AM) *
How I solved it:

AcceleratorTo ("F4", "domacro F4", sendto.execute)


CODE
<alias match="domacro *" enabled="y" sequence="100" send_to="12">
<send>
if "%1"=="F4" then
Send("gut " .. target)
end
</send>
</alias>


Allows for easy addition of other macros.

Even simpler, use Accelerators. Lets you use more keys than macros will too. Put this in your script file:
CODE
AcceleratorTo (Key, Send, 12)


For example, yours:
CODE
AcceleratorTo ("F4", Send ("gut " .. target), 12)


To get the exact Key to put there, go to Input|Key Name and hit a key, it'll tell you what the string should be.
Nitro
QUOTE (Trevize @ Sep 3 2009, 11:54 PM) *
For example, yours:
CODE
AcceleratorTo ("F4", Send ("gut " .. target), 12)


To get the exact Key to put there, go to Input|Key Name and hit a key, it'll tell you what the string should be.


Does this allow for multiple lines of code and even if statements inside the AcceleratorTo function?
Soludra
QUOTE (Trevize @ Sep 3 2009, 02:54 PM) *
CODE
AcceleratorTo ("F4", Send ("gut " .. target), 12)

I'm fairly sure that won't do what you want it to do. The Send call isn't quoted, so it'll actually call Send() and use its return value as the parameter (which is nothing useful).

QUOTE (Nitro @ Sep 4 2009, 10:05 AM) *
Does this allow for multiple lines of code and even if statements inside the AcceleratorTo function?


Yes. Everything in the second parameter string will be parsed and run as though it was really written out in the file. For example:

CODE
local do_this = [[
  if y > x then
    print("y>x")
  elseif x > y then
    print("x>y")
  else
    print("x==y")
  end
]]

AcceleratorTo ("F4", do_this, 12)


[[]] is just another way of quoting. None of the code in the string will actually be executed until the macro is pressed, and it'll be re-run every time you hit it.
Trevize
QUOTE (Soludra @ Sep 4 2009, 02:32 PM) *
QUOTE (Trevize @ Sep 3 2009, 02:54 PM) *
CODE
AcceleratorTo ("F4", Send ("gut " .. target), 12)

I'm fairly sure that won't do what you want it to do. The Send call isn't quoted, so it'll actually call Send() and use its return value as the parameter (which is nothing useful).

Correct, this would work instead:

CODE
AcceleratorTo ("F4", 'Send ("gut " .. target)', 12)


That's what I get for posting on no sleep. closedeyes.gif

QUOTE (Soludra @ Sep 4 2009, 02:32 PM) *
QUOTE (Nitro @ Sep 4 2009, 10:05 AM) *
Does this allow for multiple lines of code and even if statements inside the AcceleratorTo function?

CODE
local do_this = [[
  if y > x then
    print("y>x")
  elseif x > y then
    print("x>y")
  else
    print("x==y")
  end
]]

AcceleratorTo ("F4", do_this, 12)


Perhaps an easier way of doing it would be...
CODE
AcceleratorTo ("F4", [[
--code here
]], 12)
Nitro
Thanks for the help guys, really appreciated.
Trevize
Pleasure.
Nitro
QUOTE (Trevize @ Sep 5 2009, 01:55 AM) *
Pleasure.


I had yet another question about LUA/mush.

EDIT: Figured it out!
Nitro
QUOTE (Trevize @ Sep 5 2009, 12:26 AM) *
CODE
AcceleratorTo ("F4", [[
--code here
]], 12)


This doesn't allow to access plugin-variables inside the accelerator code apparently?
Belus
QUOTE (Nitro @ Sep 9 2009, 08:10 AM) *
QUOTE (Trevize @ Sep 5 2009, 12:26 AM) *
CODE
AcceleratorTo ("F4", [[
--code here
]], 12)


This doesn't allow to access plugin-variables inside the accelerator code apparently?

I'm not sure. I never could get that method to work.

More specifically I tried variations on this theme:
AcceleratorTo ("F4", "function('argument1', 'argument2')", 12) or
AcceleratorTo ("F4", 'function("argument1", "argument2")', 12)

I think you should stick with your AcceleratorTo ("F4", "domacro F4", sendto.execute) idea and move on. blush.gif
Nitro
QUOTE (Belus @ Sep 9 2009, 05:43 PM) *
I think you should stick with your AcceleratorTo ("F4", "domacro F4", sendto.execute) idea and move on. blush.gif


Yeah, indeed, it works.
Trevize
QUOTE (Nitro @ Sep 9 2009, 11:10 AM) *
QUOTE (Trevize @ Sep 5 2009, 12:26 AM) *
CODE
AcceleratorTo ("F4", [[
--code here
]], 12)


This doesn't allow to access plugin-variables inside the accelerator code apparently?

unsure.gif I'm not sure what you mean. You can't access variables in plugins normally, using GetVariable, you have to use GetPluginVariable. You can easily use any Lua variables, MUSH variables, or plugins variables in accelerators that you can use in any send to script.

QUOTE (Belus @ Sep 9 2009, 11:43 AM) *
I'm not sure. I never could get that method to work.

More specifically I tried variations on this theme:
AcceleratorTo ("F4", "function('argument1', 'argument2')", 12) or
AcceleratorTo ("F4", 'function("argument1", "argument2")', 12)

I think you should stick with your AcceleratorTo ("F4", "domacro F4", sendto.execute) idea and move on. blush.gif

Uh...
CODE
x = function (test)
  print (test)
end -- func

AcceleratorTo ("F1",  [[
  x ("print this")
]], sendto.execute)

Save, reload script file, hit F1 a few times...
QUOTE
print this
print this
print this
print this
print this
Soludra
QUOTE (Trevize @ Sep 9 2009, 11:01 AM) *
QUOTE (Nitro @ Sep 9 2009, 11:10 AM) *
QUOTE (Trevize @ Sep 5 2009, 12:26 AM) *
CODE
AcceleratorTo ("F4", [[
--code here
]], 12)


This doesn't allow to access plugin-variables inside the accelerator code apparently?

unsure.gif I'm not sure what you mean. You can't access variables in plugins normally, using GetVariable, you have to use GetPluginVariable. You can easily use any Lua variables, MUSH variables, or plugins variables in accelerators that you can use in any send to script.

e.g. accelerators set from a plugin are run in the world space rather than the plugin's space, hence lua variables in the plugin space are not accessible. Your example works correctly, Trevize, because you put it in the script file, which is part of the world's space, and hence isn't affected by this problem.
Trevize
QUOTE (Soludra @ Sep 9 2009, 07:00 PM) *
e.g. accelerators set from a plugin are run in the world space rather than the plugin's space, hence lua variables in the plugin space are not accessible. Your example works correctly, Trevize, because you put it in the script file, which is part of the world's space, and hence isn't affected by this problem.

Ah. I've never seen any need for putting accelerators in plugins.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.