Using the Chat system with lua?

Posted by Supyo on Sun 12 Jul 2009 07:26 AM — 3 posts, 14,234 views.

#0
I know there is a plugin which comes with MUSH which ables people to use the chat system easier, but how would one go about adding your hit points to when ever you chat?

I'm just learning to script using lua, so I don't even know where to start, any help would be appreciated.

*/*hp */*m */*mv *br

That's my prompt

I also am having trouble being able to send things into chat on triggers, for example

<triggers>
<trigger
enabled="y"
match="* has been blinded."
send_to="12"
sequence="100"
>
<send>ChatEverybody &quot;(%1)is blind&quot;, 1</send>
</trigger>
</triggers>

doesn't work I get

Compile error
World: Untitled world
Immediate execution
[string "Trigger: "]:1: unexpected symbol near '<'

No clue what that means.
Amended on Sun 12 Jul 2009 11:22 AM by Supyo
Australia Forum Administrator #1
First, paste the trigger in like this:

http://mushclient.com/pasting

The < and > symbols are part of the XML way that triggers are displayed. Don't type them into the trigger itself.


Second, the examples in the chat write-up are for VBscript. Lua needs brackets around function arguments, a minor change. So, change:


ChatEverybody "(%1)is blind", 1


to:


ChatEverybody ("%1 is blind", 1)



As for adding the HP to every message, I'll look into that now ...
Australia Forum Administrator #2
This plugin shows how you can add your HP to every outgoing message.

It detects outgoing chat messages, and uses your most recent prompt (if any) to amend the message by putting your HP after the quote that is normally in the message.

In other words, it changes:


Nick chats to everybody, 'hi there everyone'

to:

Nick chats to everybody, '[20] hi there everyone'


... assuming your HP are 20.

To use this, copy between the lines, paste into a text document (eg. MUSHclient's notepad) and save to disk as Add_HP_to_chat_messages.xml.

Then use File menu -> Plugins to install as a plugin.

If anyone else wants to use it, you would need to change the trigger "match" line to match your prompt.


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Monday, July 13, 2009, 7:47 AM -->
<!-- MuClient version 4.42 -->

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

<muclient>
<plugin
   name="Add_HP_to_chat_messages"
   author="Nick Gammon"
   id="32d08b53ff6acd8df946b0a1"
   language="Lua"
   purpose="Adds your HP to outgoing chat messages"
   date_written="2009-07-13 07:39:53"
   requires="4.40"
   version="1.0"
   >

</plugin>


<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   match="*/*hp */*m */*mv *br*"
   send_to="12"
   sequence="100"
  >
  <send>hp = %1</send>
  </trigger>
</triggers>

<!--  Script  -->


<script>
<![CDATA[
function OnPluginChatMessageOut (id, message, sText)

  -- providing we have not already added the HP to the message
  -- handle messages 4 (chat to everybody)  
  --                 5 (chat to one person)
  --                 6 (chat to group)
  -- and we know the HP 
  
  if not reformatting and 
     message >= 4 and 
     message <= 6 and
     tonumber (hp) then

    reformatting = true  -- stop recursing to do it again

    -- add the HP after the quote in bold (1) and green (32)
    sText = string.gsub (sText, "'\027", string.format ("'%s[%i] \027", ANSI (1, 32), hp), 1)
    
    -- send the amended message
    ChatMessage (id, message, sText)

    -- return so we don't send it twice
    reformatting = false
    return false
  end -- if

  -- send normally
  return true
end -- OnPluginChatMessageOut 


]]>
</script>


</muclient>