Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Message
| This plugin should tell you which triggers are unused, over time.
 |
To save and install the Show_Unused_Triggers 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 Show_Unused_Triggers.xml
- Go to the MUSHclient File menu -> Plugins
- Click "Add"
- Choose the file Show_Unused_Triggers.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="Show_Unused_Triggers"
author="Nick Gammon"
id="dd839eeea8735913421b7194"
language="Lua"
purpose="Shows unused triggers"
save_state="y"
date_written="2019-04-22 08:02:08"
requires="5.00"
version="1.0"
>
<description trim="y">
<![CDATA[
Shows a list of unused triggers over multiple sessions.
Usage:
show unused triggers --> Shows unused triggers
clear unused triggers --> Clears counts from previous client sessions
]]>
</description>
</plugin>
<!-- Aliases -->
<aliases>
<alias
match="show unused triggers"
enabled="y"
sequence="100"
script="ShowUnusedTriggers"
>
</alias>
<alias
match="clear unused triggers"
enabled="y"
sequence="100"
script="ClearUnusedTriggers"
>
</alias>
</aliases>
<script>
<![CDATA[
require "serialize" -- needed to serialize table to string
trigger_counts = trigger_counts or {} -- ensure table exists, if not loaded from variable
-- on plugin install, convert variable into Lua table
function OnPluginInstall ()
assert (loadstring (GetVariable ("trigger_counts") or "")) ()
end -- function OnPluginInstall
-- on saving state, convert Lua table back into string variable
function OnPluginSaveState ()
-- add the counts from last session to the ones for this session
local new_counts = { }
local plugins = GetPluginList() or {}
table.insert (plugins, "") -- add main world to plugins list
for _, pluginID in pairs (plugins) do
local tl = GetPluginTriggerList(pluginID) or {}
for id, name in ipairs (tl) do
local matchText = GetPluginTriggerInfo (pluginID, name, 1)
local count = GetPluginTriggerInfo (pluginID, name, 21) + (trigger_counts [matchText] or 0)
new_counts [matchText] = count
end -- for
end -- of each plugin
-- save the updated counts
SetVariable ("trigger_counts",
"trigger_counts = " .. serialize.save_simple (new_counts))
end -- function OnPluginSaveState
function ShowUnusedTriggers (name, line, wildcards)
local plugins = GetPluginList() or {}
table.insert (plugins, "") -- add main world to plugins list
local counter = 0
for _, pluginID in pairs (plugins) do
local tl = GetPluginTriggerList (pluginID) or {}
local pluginName = "main world file"
if pluginID ~= "" then
pluginName = GetPluginInfo (pluginID, 1)
end -- of not main world file
for id, name in ipairs (tl) do
local matchText = GetPluginTriggerInfo (pluginID, name, 1)
local count = GetPluginTriggerInfo (pluginID, name, 21) + (trigger_counts [matchText] or 0)
if count == 0 then
ColourNote ("green", "", string.format ("Trigger '%s' in %s has not been used. Match text: ", name, pluginName))
ColourNote ("darkgray", "", " " .. matchText)
counter = counter + 1
end -- if
end -- for
end -- of each plugin
ColourNote ("orange", "", string.format ("%d unused triggers found.", counter))
end -- ShowUnusedTriggers
function ClearUnusedTriggers (name, line, wildcards)
trigger_counts = { } -- no previous counts
ColourNote ("orange", "", "Trigger counts from previous sessions cleared")
end -- ClearUnusedTriggers
]]>
</script>
</muclient>
Type in "show unused triggers" to see a list of triggers with a use count of zero. The plugin saves the counts for each session and reloads them next time (in the plugin save-state file) so that the counter will be cumulative. In other words, if a trigger is used today, then it will also be considered as having been used if you list them tomorrow.
You can type "clear unused triggers" to clear that saved information.
This plugin inspects all plugins, and the main world file triggers. This lets you check everything you have installed.
Example output:
Trigger '*trigger1102' in ATCP_Mapper has not been used. Match text:
There's water ahead of you. You'll have to * to make it through.
Trigger '*trigger1104' in ATCP_Mapper has not been used. Match text:
You'll have to swim to make it through the water in that direction.
Trigger '*trigger1106' in ATCP_Mapper has not been used. Match text:
^There is a door in the way
Trigger '*trigger1108' in ATCP_Mapper has not been used. Match text:
Now now\, don\'t be so hasty\!$
Trigger '*trigger1110' in ATCP_Mapper has not been used. Match text:
^You cannot walk through
Trigger '*trigger1112' in ATCP_Mapper has not been used. Match text:
As you stroll in, you feel your feet slipping on something slimy.
Trigger '*trigger1114' in ATCP_Mapper has not been used. Match text:
The door is locked.
Trigger '*trigger1116' in ATCP_Mapper has not been used. Match text:
You are regaining balance and are unable to move.
Trigger '*trigger1118' in ATCP_Mapper has not been used. Match text:
You are surrounded by a pocket of air and so must move normally through water.
Trigger '*trigger1120' in ATCP_Mapper has not been used. Match text:
You fumble about drunkenly.
Trigger '*trigger1122' in ATCP_Mapper has not been used. Match text:
You are asleep and can do nothing. WAKE will attempt to wake you.
Trigger '*trigger1124' in ATCP_Mapper has not been used. Match text:
You must be standing first.
Trigger '*trigger1126' in ATCP_Mapper has not been used. Match text:
You need to use a boat, fly, or swim underwater to go there.
Trigger '*trigger1128' in ATCP_Mapper has not been used. Match text:
You can't * while sitting.
Trigger '*trigger1130' in ATCP_Mapper has not been used. Match text:
^You dream about
Trigger '*trigger1132' in ATCP_Mapper has not been used. Match text:
There is no exit in that direction.
Trigger '*trigger1134' in ATCP_Mapper has not been used. Match text:
Alas, you cannot go that way.
Trigger '*trigger924' in main world file has not been used. Match text:
hello
18 unused triggers found.
The "match text" display lets you find a trigger, even if it is unnamed. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|