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
➜ Lua
➜ Two Plugins
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Rene
(46 posts) Bio
|
Date
| Mon 05 Feb 2018 01:04 AM (UTC) |
Message
| 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. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Mon 05 Feb 2018 06:08 AM (UTC) |
Message
| 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.
 |
To save and install the SendOncePerSession plugin do this:
- Copy between the lines below (to the Clipboard)
- Open a text editor (such as Notepad) and paste the plugin into it
- Save to disk on your PC, preferably in your plugins directory, as SendOncePerSession.xml
- Go to the MUSHclient File menu -> Plugins
- Click "Add"
- Choose the file SendOncePerSession.xml (which you just saved in step 3) as a plugin
- Click "Close"
|
<?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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Rene
(46 posts) Bio
|
Date
| Reply #2 on Mon 05 Feb 2018 06:19 AM (UTC) |
Message
| 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? | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #3 on Mon 05 Feb 2018 06:22 AM (UTC) |
Message
| You'll have to explain that in greater detail. :) |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Rene
(46 posts) Bio
|
Date
| Reply #4 on Mon 05 Feb 2018 09:40 PM (UTC) |
Message
| 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. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #5 on Tue 06 Feb 2018 01:15 AM (UTC) |
Message
| OK, so you just want to capture something you sent to the MUD? This might be easier:
 |
To save and install the RememberName plugin do this:
- Copy between the lines below (to the Clipboard)
- Open a text editor (such as Notepad) and paste the plugin into it
- Save to disk on your PC, preferably in your plugins directory, as RememberName.xml
- Go to the MUSHclient File menu -> Plugins
- Click "Add"
- Choose the file RememberName.xml (which you just saved in step 3) as a plugin
- Click "Close"
|
<?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. |
- 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.
14,801 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top