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, 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.
 Entire forum ➜ MUSHclient ➜ General ➜ Help with an alias creating alias plugin

Help with an alias creating alias plugin

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


Posted by Dacheeba   (2 posts)  Bio
Date Thu 24 Nov 2011 01:51 AM (UTC)
Message
AddAlias documentation is a little confusing, so I was hoping someone here could help me.

I am trying to make a plugin that will add aliases within itself. Particularly, the aliases must be sent to script.

Basically, I want to let the user define an alias on the fly that works with another plugin. The alias command input would be:


mobrecon (numerical argument) (string argument using "|")


The plugin should then create an alias that looks like the following, but should keep the aliases within the plugin.


<alias
   match="^x(thi|thie|thiev|thieve|thieves)"
   enabled="y"
   group="mobrecon"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>Execute("mobstat 546567")</send>
  </alias>


Any help much appreciated.
Top

Posted by Daniel P   USA  (97 posts)  Bio
Date Reply #1 on Mon 26 Dec 2011 03:17 PM (UTC)
Message
I had a lot of trouble with AddAlias() and AddTrigger() within a PLUGIN. Because unfortunately they're not (to my knowledge) stored in the state files. So when you close out everything, all of those aliases which you dynamically added will disappear.

My best solution, which isn't very pretty at all, is to store the scripts and these aliases/triggers in the world file. That way they'll be saved.

As for syntax, here is the one I use for my trigger adding script:


AddTrigger("house"..GetVariable("housenum"),"%1","",41,custom_colour.CustomOther,0,"","",100,0)
SetTriggerOption("house"..GetVariable("housenum"),"repeat","1")


This creates a new trigger with the Label (name) as house## and specifies the wildcard in the match ('add house *') as the match text of the trigger. The third argument is the send text, which, since this is simply a trigger to colour my output, I've left blank. 41 is the sum of all the flags I wish to use: regexp (32), Keep Evaluating (8), and Enabled (1). The table for these are in the AddTrigger/AddAlias help files. Then you've got a few other options like foreground colour, wildcard (usually left as 0), Sound file to play when the trigger is matched, and what script to run if you're into running scripts from the little "Script" box between "Label" and "Group".

However, AddAlias/AddTrigger don't hardly do ANYTHING. The real power comes in when you use the SetAliasOption() and SetTriggerOption() functions. This is where you'll set your send_to value. In my case, I used SetTriggerOption("house##","repeat","1") to turn on the "repeat on same line" flag; one that wasn't included in the AddTrigger flag table.

In your case, you want to set your send_to to "script" (or 12). So after creating your alias with AddAlias("name","match","send"), you'll use SetAliasOption("name","send_to",12)

Hope that helps some.
Top

Posted by Nick Gammon   Australia  (23,057 posts)  Bio   Forum Administrator
Date Reply #2 on Mon 26 Dec 2011 07:27 PM (UTC)
Message
Dacheeba said:

AddAlias documentation is a little confusing, so I was hoping someone here could help me.

I am trying to make a plugin that will add aliases within itself. Particularly, the aliases must be sent to script.



Plugins are supposed to be read-only, like an executable file. Programs don't normally modify themselves.

Plugins can be shared between multiple worlds, so it isn't particularly useful for one world to modify the behaviour in another one.

Having said that, you can save anything you like into a plugin's variables (which get saved in its "state" file).

So, a plugin could add aliases, and then during the OnPluginSaveState plugin callback, serialize all its (new) aliases into a variable. You would use ExportXML to do that.

Then to get them back you read them back with ImportXML (done when the plugin loads).

In any case, I suggest you read up on the addxml plugin, which simplifies adding triggers, aliases etc.

http://www.gammon.com.au/forum/?id=7123

- 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.


13,180 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.