[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  Prompt plugin
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Prompt plugin

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


Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Thu 01 Jun 2006 04:06 AM (UTC)
Message
The plugin below terminates prompts with newlines (taking into account some special cases) and appends coloured stat change hints to prompts.

It's designed for Achaea, but can be easily ported to almost any other game. All you need to do to make it work with your prompt is change this plugin's only trigger. Inside that trigger, you would need to capture every stat number that you want to keep track of into a named wildcard. The wildcard's name will become the stat's label in its respective hint.

For example, the current trigger is:


^(?P<h>\d+)h, (?P<m>\d+)m(?:, (?P<e>\d+)e|)(?:, (?P<w>\d+)w|) (?P<str>c?e?x?k?d?b?)-$


Here we have wildcards labeled "h", "m", "e", "w", and "str". The latter ("str") is not tracked or displayed, since it contains a non-numeric value, but its value is stored into an MXP entity for reference from outside the plugin (just as values of the first four wildcards).

Wildcards containing numeric values are tracked, and whenever there is a change in any of them, they appear after the prompt as "[+123h]", "[-23m]", etc.

The above trigger also does some conditional matching, from which you can see that a varying number of stats can be kept track of.

So, to summarize:


  • you can track and display any number of prompt stats, by capturing their numeric values into named wildcards;
  • you can expose the values above, as well as any other values present in the prompt, as MXP entities accessible outside the plugin;
  • to save non-numeric values in entities you also capture them into named wildcards.


Additional details are available in plugin's description.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #1 on Thu 01 Jun 2006 04:09 AM (UTC)
Message

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

<!-- Plugin "PromptProcessor" generated by Plugin Wizard -->

<muclient>
<plugin
   name="PromptProcessor"
   author="Keldar"
   id="9f182a333c462078704116cd"
   language="Lua"
   purpose="Terminates prompts with newlines and displays stat changes"
   save_state="y"
   date_written="2006-05-29"
   requires="3.74"
   version="1.0"
   >
 <description trim="y">
<![CDATA[
Terminates prompts with newlines and appends information about stat changes
to them.

hintprompt on|off    -   turn stat hints on and off.

fixprompt on|off     -   turn newline termination on and off.

Note: Stat hints may not always work consistently if newline termination is
switched off.

Additionally,  the plugin saves the current values of all stats present in
the prompt in MXP entities. The entity names are of the form "prompt:currN",
where "N" is an uppercase version of the stat's label in the prompt. For example,
if health is represented as "1234h" in the prompt then its value (1234) will be
saved in entity named "prompt:currH". To retrieve a stat value do:

GetEntity("prompt:currN")

]]>
    </description>

</plugin>


<!--  Triggers  -->

<triggers>
  <trigger
   enabled="n"
   name="prompt"
   match="^(?P&lt;h&gt;\d+)h, (?P&lt;m&gt;\d+)m(?:, (?P&lt;e&gt;\d+)e|)(?:, (?P&lt;w&gt;\d+)w|) (?P&lt;str&gt;c?e?x?k?d?b?)-$"
   omit_from_output="y"
   regexp="y"
   script="displayPrompt"
   sequence="100"
  >
  </trigger>
</triggers>

<!--  Variables  -->

<variables>
  <variable name="fixprompt">1</variable>
  <variable name="hintprompt">1</variable>
</variables>


<aliases>
<alias enabled="y" match="^hintprompt (on|off)$" regexp="y" script="SetHints" />
<alias enabled="y" match="^fixprompt (on|off)$" regexp="y" script="SetFixes" />
</aliases>


<!--  Script  -->


<script>
<![CDATA[

function tprint (t, indent, done)
  done = done or {}
  indent = indent or 0
  for key, value in pairs (t) do
    Tell (string.rep (" ", indent)) -- indent it
    if type (value) == "table" and not done [value] then
      done [value] = true
      Note (tostring (key), ":");
      tprint (value, indent + 2, done)
    else
      Tell (tostring (key), "=")
      print (value)
    end
  end
end


colour_map = {}


function RGBToName(col)
   local ansi = colour_map[col]
   if ansi == nil then
      ansi = RGBColourToName(col)
      colour_map[col] = ansi
   end
   return ansi
end

table.extend = function(tab1,tab2) 
   table.foreach(tab2, function (i,v) table.insert(tab1, v) end)
end


function displayPrompt(name, output, wildcs, styles)
    PromptProcessor.repl1(styles, wildcs)
    echoPrompt(styles)
end

function showStyles(n,o,w,styles)
	tprint (styles)
end

[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #2 on Thu 01 Jun 2006 04:09 AM (UTC)
Message


function echoPrompt(prompt)
   local args = {}  -- a table to hold ColourNote arguments

   -- pack the styles into the args table
   table.foreach(prompt, function (i, style) 
      table.extend(args, {RGBToName(style.textcolour), RGBToName(style.backcolour), style.text})
   end)

   ColourNote(unpack(args))
end


function findInStyles(styles, pat)
	for i, style in ipairs(styles) do
		local first, last = string.find(style.text, pat)
		if first then
			return first, last, i
		end
	end
	return nil
end

rgb_map = {}

function toRGB(col_name)
	if col_name == "" or col_name == nil then return 0 end
	local rgb = rgb_map[col_name]
	if rgb == nil then
		rgb = ColourNameToRGB(col_name)
		rgb_map[col_name] = rgb
	end
	return rgb
end

function makeStyle(fore, back, txt)
	return {textcolour = toRGB(fore), backcolour = toRGB(back), text=txt}
end

PromptProcessor = {
    replFunc = nil,
    achaea = false,
    fix = nil}

PromptProcessor.repl1 = function(prompt, wildcs) 
	local change, txt
	local fore, back = ""
	local style = {}
	local wildcs = filterWildcs(wildcs)
	for k,v in pairs(wildcs) do
		if PromptProcessor["last_"..k] then
			change = tonumber(wildcs[k]) - PromptProcessor["last_"..k]
			if change > 0 then
				txt = "+" .. tostring(change) .. k
				fore = "lime"
			elseif change < 0 then
				txt = tostring(change) .. k
				fore = "red"
			end
			if change ~= 0 then
				table.insert(prompt, makeStyle("silver", "", "["))
				table.insert(prompt, makeStyle(fore,back,txt))
				table.insert(prompt, makeStyle("silver", "", "]"))
			end
		end
                if tonumber(v) ~= nil then
                    PromptProcessor["last_"..k] = tonumber(v)
                end
                SetEntity("prompt:curr" .. string.upper(k), v)
	end
	return prompt
end
    

function SetHints(name, output, wildcs)
    if wildcs[1] == "on" then
        EnableTrigger("prompt", true)
        if name ~= "mute" then
        AnsiNote(ANSI(33), "[", ANSI(36), "PromptCatcher", ANSI(33), "]: ", ANSI(37), "You will now see hints in your prompt.", ANSI(0))
        end
        SetVariable("hintprompt", 1)
    elseif wildcs[1] == "off" then
        EnableTrigger("prompt", false)
        if name ~= "mute" then
        AnsiNote(ANSI(33), "[", ANSI(36), "PromptCatcher", ANSI(33), "]: ", ANSI(37), "You will no longer see hints in your prompt.", ANSI(0))
        end
        SetVariable("hintprompt", 0)
    end
end


  
function SetFixes(name, output, wildcs)
    if wildcs[1] == "on" then
        PromptProcessor.fix = true
        if name ~= "mute" then
            AnsiNote(ANSI(33), "[", ANSI(36), "PromptCatcher", ANSI(33), "]: ", ANSI(37), "Your prompts will now be fixed with newlines.", ANSI(0))
        end
        SetVariable("fixprompt", 1)
    elseif wildcs[1] == "off" then
        PromptProcessor.fix = false
        if name ~= "mute" then
            AnsiNote(ANSI(33), "[", ANSI(36), "PromptCatcher", ANSI(33), "]: ", ANSI(37), "Your prompts will no longer be fixed with newlines.", ANSI(0))
        end
        SetVariable("fixprompt", 0)
    end 
end

    
if tonumber(GetVariable("fixprompt")) == 1 then
    SetFixes("mute", "", {"on"})
else
    SetFixes("mute", "", {"off"})
end


if tonumber(GetVariable("hintprompt")) == 1 then
    SetHints("mute", "", {"on"})
else
    SetHints("mute", "", {"off"})
end



terminated = false


function OnPluginPacketReceived(packet)
--local start = GetInfo(232)
    if PromptProcessor.fix then  -- fix prompts only if this option is set
    local pat = "\27%[%d?;?%d%dm\13\10"
    if terminated and (string.sub(packet, 1,2) == "\13\10") then 
            packet = string.sub(packet, 3, -1)
            terminated = false
    elseif (string.find(packet, pat) == 1) then
            i,j = string.find(packet, pat)
            packet = string.sub(packet, 1, j-2) .. string.sub(packet, j+1, -1)
            terminated = false
    end
    packet = string.gsub(packet, "-\255\249\13\10", "-\13\10")
    packet = string.gsub(packet, "-\255\249", "-\13\10")
    terminated = true
    end

--local timing = GetInfo(232) - start
--AppendToNotepad("test", "Timing: " .. tostring(timing) .. "\r\n")
    
    return packet
end


function debugPrompt(n,o,w,s)
	w = filterWildcs(w)
	tprint(w)
end


function filterWildcs(w)
	local tab = {}
	for k,v in pairs(w) do
		if type(k) == "string" and v and v ~= "" then
			tab[k] = v
		end
	end
	return tab
end
]]>
</script>


</muclient>

[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #3 on Thu 01 Jun 2006 04:11 AM (UTC)
Message
You'll need to copy both posts above, concatenate them together in a text editor, and save as an XML file - the plugin's too large for a single post.
[Go to top] top

Posted by Nexes   (65 posts)  [Biography] bio
Date Reply #4 on Mon 03 Jul 2006 10:42 PM (UTC)
Message
Wow, this version is a lot more complicated than the one you posted on Achaea.cjb.net O.o

Now, my only question is this: does it also catch prompts that are split across two packets?

Because I know your previous ones don't and I wanted to fix that. From looking over it, it doesn't look like it does since it doesn't save the prevous packet.
[Go to top] top

Posted by Nick Gammon   Australia  (21,405 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Tue 04 Jul 2006 01:41 AM (UTC)
Message
Quote:

You'll need to copy both posts above ...


Ked, I have removed the length restriction for your posts.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Mpa   (9 posts)  [Biography] bio
Date Reply #6 on Sat 08 Jul 2006 12:33 AM (UTC)
Message
If I have this lua plugin installed, on the other hand, my main script is a python script; is there a way for the python script to access the value of the "str" MXP entity ?

I am thinking something like :

world.execute("activedefenses ", GetEntity("prompt:currstr"))

The "activedefenses" alias would then pass the value of prompt:currstr to the script.

A more direct way would be nice but I am not familiar with MXP and I dont know Lua at all so the plugin is greek to me.
[Go to top] top

Posted by Nick Gammon   Australia  (21,405 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Sat 08 Jul 2006 01:11 AM (UTC)
Message
http://www.gammon.com.au/scripts/doc.php?function=GetEntity

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Mpa   (9 posts)  [Biography] bio
Date Reply #8 on Sat 08 Jul 2006 07:04 AM (UTC)
Message
Oh, I did try that and didnt get anything so I assumed it was due to variable scope. I checked again and it was because the variable is named "currSTR" instead of "currstr".

Thanks Nick !
[Go to top] top

Posted by Dekar   (2 posts)  [Biography] bio
Date Reply #9 on Thu 12 Oct 2006 02:02 PM (UTC)
Message
I am having trouble with changing the trigger for the plugin to be used in Aetolia. The prompt is as follows:

H:1000 M:1000 E:1000 W:1000 B:100% [eb]

I've tried to change the trigger but to no avail. This is what I came up with:

^H\:(?P&lt;h&gt;\d+) M\:(?P&lt;m&gt;\d+)(?: E\:(?P&lt;e&gt;\d+)|)(?: W\:(?P&lt;w&gt;\d+)|) B\:(?P&lt;b&gt;\d+) \[(?P&lt;str&gt;c?e?s?a?d?b?)\]$

Any ideas? Thanks in advance

[Go to top] top

Posted by Nick Gammon   Australia  (21,405 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Thu 12 Oct 2006 11:19 PM (UTC)
Message
It's a bit confusing the way your trigger has the &lt; and that in it. If you copied directly from the trigger match box, they shouldn't be there. If you copied the entire trigger in XML format, it looks better if you paste the whole thing.

Anyway, apart from that, you left out the % sign. This worked for me:


Match:
^H\:(?P<h>\d+) M\:(?P<m>\d+)(?: E\:(?P<e>\d+)|)(?: W\:(?P<w>\d+)|) B\:(?P<b>\d+)% \[(?P<str>c?e?s?a?d?b?)\]$


You might leave out the trailing $ too, if the prompt has other things on the line after it, otherwise it is OK there.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Dekar   (2 posts)  [Biography] bio
Date Reply #11 on Fri 13 Oct 2006 02:17 PM (UTC)
Message
Ah I see, I feel stupid now. Thanks it works beautifully.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #12 on Mon 16 Oct 2006 08:24 AM (UTC)
Message
Since this floated up anyways: the current incarnation of that plugin is at http://www.freewebs.com/keldar/promptprocessor.htm
[Go to top] 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.


6,570 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]