Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Tips and tricks ➜ Targeting alias

Targeting alias

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Tue 30 May 2006 06:41 AM (UTC)

Amended on Tue 30 May 2006 07:43 AM (UTC) by Nick Gammon

Message
The alias here (written in Lua) demonstrates how to write a targetting function that lets you select a word in the output window, and make that your target.

For instance, if you have a kobold attacking you, double-click the word kobold in the output window (to select it) and then type "target". You can speed things up by making a macro like Alt+T to be the word "target".

The alias finds the line, and start and end column of the selection (if any). If found, it applies a regular expression to the found text to make sure it passes its rules (ie. is a single word consisting of A-Z or 0-9).

If no word is found, it uses utils.inputbox to request the name of the target to be typed in (which you can cancel if you don't want to type it).



<aliases>
  <alias
   match="target"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
do
  local target -- Lua variable to hold our target

  -- find the selection range

  local startline, endline, startcol, endcol = 
    GetSelectionStartLine (),
    GetSelectionEndLine (),
    GetSelectionStartColumn (),
    GetSelectionEndColumn ()

  -- if a single line selected, take that word  

  if startline &gt; 0 and 
     endline == startline and
     startcol &gt; 0 and
     endcol &gt; 0 then
    local word = string.sub (GetLineInfo (startline, 1), startcol, endcol - 1)

  -- sanity check on word (in case whole line selected)

    _, _, target = string.find (word, "^([A-Za-z0-9]+)$")
  end

  -- otherwise prompt for one

  if not target then

    target = utils.inputbox ("Enter the name of the desired target", 
                             "Select target")
  end -- if no target selected

  -- echo new target name
  
  if target then
    ColourNote ("white", "blue", "Target now " .. target)
    SetVariable ("target", target)  -- copy into MUSHclient variable
  end -- have a target
end -- do
</send>
  </alias>
</aliases>

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Hapless   (3 posts)  Bio
Date Reply #1 on Mon 14 May 2007 09:53 PM (UTC)
Message
Is it possible to use this as a plug in?

I copied the code, launched the plug in wizard, pasted into the scipt section, and saved it. I then attempted to load the plug in (under file > plugin) but I recieved the following error:

Scipting Error

Error Number: 0

Event: Compile Error

Raised by: Plugin: target (called from world: test) (I loaded an empty world and called it test.)

[string "Plugin"]:140: unexpected symbol near '<'

Called By: Immediate execution

The system I use is written in a language other then Lua and I'd like to try this method of targetting if possible.
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #2 on Mon 14 May 2007 10:06 PM (UTC)
Message
Quote:
The alias here (written in Lua) demonstrates how to write a targetting function that lets you select a word in the output window, and make that your target.

From the quote above, this is written in Lua, so it won't work on other script engines. Which script language do you use? This shouldn't be terribly hard to convert over to other scripts. Aside from the util box, perhaps.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #3 on Tue 15 May 2007 12:27 AM (UTC)

Amended on Tue 15 May 2007 02:38 AM (UTC) by Nick Gammon

Message
Quote:

I copied the code, launched the plug in wizard, pasted into the scipt section, and saved it.


What you needed to do, and what I did to make the plugin below is:


  • Copy the alias

  • Paste into your current world (see http://mushclient.com/pasting) - this adds one alias

  • Launch the plugin wizard and make a plugin consisting of just that alias. Make Lua the script language.



This is the result (you can copy between the lines to make a plugin file):


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, May 15, 2007, 10:22 AM -->
<!-- MuClient version 4.06 -->

<!-- Plugin "Targetting_system" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Targetting_system"
   author="Nick Gammon"
   id="eb5860ad79f9193c181f8834"
   language="Lua"
   purpose="Sets 'target' variable"
   date_written="2007-05-15 10:21:52"
   requires="4.00"
   version="1.0"
   >

</plugin>


<!--  Aliases  -->

<aliases>
  <alias
   match="target"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
do
  local target -- Lua variable to hold our target

  -- find the selection range

  local startline, endline, startcol, endcol = 
    GetSelectionStartLine (),
    GetSelectionEndLine (),
    GetSelectionStartColumn (),
    GetSelectionEndColumn ()

  -- if a single line selected, take that word  

  if startline &gt; 0 and 
     endline == startline and
     startcol &gt; 0 and
     endcol &gt; 0 then
    local word = string.sub (GetLineInfo (startline, 1), startcol, endcol - 1)

  -- sanity check on word (in case whole line selected)

    _, _, target = string.find (word, "^([A-Za-z0-9]+)$")
  end

  -- otherwise prompt for one

  if not target then

    target = utils.inputbox ("Enter the name of the desired target", 
                             "Select target")
  end -- if no target selected

  -- echo new target name
  
  if target then
    ColourNote ("white", "blue", "Target now " .. target)
    SetVariable ("target", target)  -- copy into MUSHclient variable
  end -- have a target
end -- do
</send>
  </alias>
</aliases>

</muclient>



(The added stuff, compared to the original post, is in bold).

However your problem is that the 'target' variable is local to the plugin. To use it you either need to add extra aliases which use that variable (eg. see http://mushclient.com/faq point 22) into that plugin, or grab that variable from other plugins by using GetPluginVariable:

http://www.gammon.com.au/scripts/doc.php?function=GetPluginVariable

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Thalir   (13 posts)  Bio
Date Reply #4 on Fri 03 Aug 2007 04:09 AM (UTC)
Message
How may I convert this into a function so I can put what the alias does into my script file?

I'm fine with calling a function from my alias, just couldn't write the correct lua script for this:
function clicktarget(name,output,wildcs)
[Then copy and pasted everything from Do to End here]
end

This was the error I got:
[string "Script file"]:34: 'then' expected near '&'

=================================================
Also, I'd like to save the target variable in my table, for example:
target = {}

And the function will save it into target.t1
=================================================
So my two questions are how can I modify the function to
-put it in my script file
-and save the variable into a table

Thanks
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #5 on Fri 03 Aug 2007 04:37 AM (UTC)
Message
To get rid of the error, change the instances of &gt; to > since you aren't using xml in the script file. As for the target.t1, just do exactly what you said with target.t1 = foo

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Thalir   (13 posts)  Bio
Date Reply #6 on Fri 03 Aug 2007 05:12 AM (UTC)
Message
Thank you, I got it to work in a script now!

I'm still not sure where to put the
target.t1 = foo

And what does " = foo" mean?
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #7 on Fri 03 Aug 2007 07:31 AM (UTC)
Message
Sorry, "foo" is a programming term meaning "something goes here, but it will be different in each application, so I'll just fill in the word foo." I'm not sure exactly what you're doing with the table, so I left a "foo" in there so you can fill in whatever you would need to complete your script.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Thalir   (13 posts)  Bio
Date Reply #8 on Fri 03 Aug 2007 07:47 AM (UTC)
Message
It's alright, I've solved it. Thanks for your help!
Top

Posted by Benjamin   (2 posts)  Bio
Date Reply #9 on Sun 02 Dec 2007 05:58 AM (UTC)

Amended on Sun 02 Dec 2007 06:03 AM (UTC) by Benjamin

Message
hi i added the lau version of double click to target something which worked great. So all i have to do is double click some ie rat, but what i dont understand to do is make an alias so that i staffcast scintilla at (???), what do i type in the parenthesis to get to the target. I tried %t and @t and i tried making a variable so name is t and the contents is target, but i get this error
Compile error
World: Achaea
Immediate execution
[string "Alias: "]:1: '=' expected near 'scintilla'
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #10 on Sun 02 Dec 2007 07:22 PM (UTC)
Message
You have to post more than that. You have given the error message but not what is causing the error.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


38,672 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.