Two Plugins

Posted by Rene on Mon 05 Feb 2018 01:04 AM — 6 posts, 20,654 views.

#0
So I have two plugins that I sometimes run simultaneously that both have aliases that do the same thing, i.e. capture a command I send on logon to store my characters name. However they both are set to echo_alias="y" so that the command will get sent to the MUD, the problem being when they are both running it gets sent twice. Is there a way to make it not send twice? Yes, I know I can manually make one of them not echo_alias, but then if I use just that one it will not send the command and often I use them individually. Any suggestions?
Thanks.
Australia Forum Administrator #1
There are a few ways you could do this, but probably the simplest is to make a third plugin whose job is to send something only once per session.

Template:saveplugin=SendOncePerSession
To save and install the SendOncePerSession plugin do this:
  1. Copy the code below (in the code box) to the Clipboard
  2. Open a text editor (such as Notepad) and paste the plugin code into it
  3. Save to disk on your PC, preferably in your plugins directory, as SendOncePerSession.xml
    • The "plugins" directory is usually under the "worlds" directory inside where you installed MUSHclient.
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file SendOncePerSession.xml (which you just saved in step 3) as a plugin
  7. Click "Close"
  8. Save your world file, so that the plugin loads next time you open it.



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="SendOncePerSession"
   author="Nick Gammon"
   id="e8c07b9486ffa778be42be3c"
   language="Lua"
   purpose="Sends something to the MUD once per connection"
   date_written="2018-02-05 16:59:57"
   requires="5.00"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Usage:

  CallPlugin ("e8c07b9486ffa778be42be3c", "SendToWorld", "something")
  
  This will send "something" to the current world once per connection.
  Once you disconnect and reconnect you can send it again.
  
]]>
</description>

</plugin>


<!--  Script  -->


<script>
<![CDATA[
sentThings = { }

function OnPluginConnect ()
  sentThings = { }  -- we haven't sent anything yet
end -- function

function SendToWorld (what)

  -- see if we already sent it
  if sentThings [what] then
    return
  end -- if already done

  Send (what)  -- send it
  sentThings [what] = true  -- remember we sent it

end -- SendToWorld 
]]>
</script>

</muclient>



Now in your alias that you have in your other plugins, call this plugin like this:


  CallPlugin ("e8c07b9486ffa778be42be3c", "SendToWorld", "something")


Where "something" is the thing you only want sent once. The plugin checks if it has already sent it this session, and if so, doesn't send it again.
#2
Quite a workaround. Is it possible to have an alias work like a trigger where it ignores the text and lets it be sent regular, but it triggers on the words being inputted?
Australia Forum Administrator #3
You'll have to explain that in greater detail. :)
#4
I mean that it shouldn't intercept the text sent to the MUD and just trigger on the words selected to record the text entered, that way I would not have to make the plugin re-send the text, similar to a trigger on the MUDs output, this would trigger on the input.
Australia Forum Administrator #5
OK, so you just want to capture something you sent to the MUD? This might be easier:

Template:saveplugin=RememberName
To save and install the RememberName plugin do this:
  1. Copy the code below (in the code box) to the Clipboard
  2. Open a text editor (such as Notepad) and paste the plugin code into it
  3. Save to disk on your PC, preferably in your plugins directory, as RememberName.xml
    • The "plugins" directory is usually under the "worlds" directory inside where you installed MUSHclient.
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file RememberName.xml (which you just saved in step 3) as a plugin
  7. Click "Close"
  8. Save your world file, so that the plugin loads next time you open it.



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="RememberName"
   author="Nick Gammon"
   id="8bc26701e42113bb048c48d3"
   language="Lua"
   purpose="Remembers something sent to the MUD"
   date_written="2018-02-06 12:06:32"
   requires="5.00"
   version="1.0"
   >

</plugin>

<!--  Script  -->

<script>
<![CDATA[
function OnPluginConnect ()
  justConnected = true
end -- function

--
--  MUSHclient is definitely sending 'sText' to the MUD
--
function OnPluginSent (sText)

  -- only do it after connecting
  if not justConnected then
    return
  end -- if
  
  local name = string.match (sText, "^My name is (%a+)$")
  if name then  -- if matched
    myName = name
    justConnected = false
    ColourNote ("orange", "", "Detected name: " .. myName)  -- debugging
  end -- if

end -- function
]]>
</script>


</muclient>



This is examining everything you send to the MUD, and uses string.match to see if it is the special thing you want. If so, it remembers it, and then sets a flag so it doesn't do it again this session (you could omit that part if you want).

Since this isn't an alias as such, the original text you send is going to be sent to the MUD anyway.

You would need to change the string.match regular expression to be whatever-it-is that you send, that you want to remember. If it happens to be the very first thing you send, then omit the test and just save the first thing that this matches on.