Help with an alias creating alias plugin

Posted by Dacheeba on Thu 24 Nov 2011 01:51 AM — 3 posts, 18,382 views.

#0
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.
USA #1
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.
Australia Forum Administrator #2
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