Register forum user name Search FAQ

Gammon Forum

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 things: Timestamps and health loss

Two things: Timestamps and health loss

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


Pages: 1  2 3  

Posted by Simimi   (40 posts)  Bio
Date Reply #15 on Tue 21 Aug 2007 01:50 AM (UTC)

Amended on Tue 21 Aug 2007 02:42 AM (UTC) by Simimi

Message
Hey Noc, I'm Simimi, also from Lusternia. Let me see if I can get this to work for myself and I'll see what I can do for you. It is best to use a regular expression for the prompt, this is the one I use for my prompt, along with that it does.


^(\d+)h, (\d+)m, (\d+)e, (\d+)p, (\d+)en, (\d+)w (e?l?r?x?k?d?b?p?s?S?i?)(\<\>)?\-$

The last little bit is for people with Cubixes, so dun worry about it. I'm going to play with this real quick and see what I can do because it is something I would like for my system also.

Here is some testing on it done in game... I added an ego block to the previous code. I'll try to make it into a plugin if you like, so it can be called by a script file instead of being in the trigger box itself.


Forren makes a fist and punches towards you, releasing a blast of pure elemental energy that slams into you, searing your flesh.
Your magic tome warms as it absorbs a charge.
2833h, 3106m, 3507e, 10p, 15345en, 14430w elrx-<10:08:1.308> <-639H>

107h, 3106m, 3507e, 10p, 15345en, 14422w lrx-<10:08:11.331> <+274H><+75M>

A blinding pain explodes behind your eyes, which begin to tear up with blood.
Your magic tome warms as it absorbs a charge.
2420h, 2008m, 1668e, 10p, 15345en, 14430w elrx-<10:12:21.431> <-869H><-1098M><-1072E>


Let me see if I can figure out what Nick said about calling the script function from the script.

Well I get an error when I put this information into a script file about syntax with the use of the '%'.


function mytrigger (name, line, wildcards, styles)

time_now = GetInfo (232) % 60
      
      for _, v in ipairs(styles) do
        ColourTell (RGBColourToName (v.textcolour), 
                    RGBColourToName (v.backcolour), 
                    v.text)  
      end

      ColourTell("silver", "", os.date("&lt;%%H:%%M:") .. string.format ("%%0.3f&gt; ", time_now))
      
      health = %1
      health_diff = nil

      if old_health and health ~= old_health then
        health_diff = health - old_health
      end

      old_health = health

      mana = %2
      mana_diff = nil

      if old_mana and mana ~= old_mana then
        mana_diff = mana - old_mana
      end

      old_mana = mana

      ego = %3
      ego_diff = nil

      if old_ego and ego ~= old_ego then
        ego_diff = ego - old_ego
      end

      old_ego = ego

      if health_diff or mana_diff or ego_diff then 
        if health_diff then
          ColourTell ("silver", "", "&lt;")
          local c
          if health_diff &lt; 0 then
            c = "salmon"
          else
            c = "lightgreen"
          end
          ColourTell (c, "", string.format ("%%+iH", health_diff))
          ColourTell ("silver", "", "&gt;")
        end
        if mana_diff then
          ColourTell ("silver", "", "&lt;")
          local c
          if mana_diff &lt; 0 then
            c = "salmon"
          else
            c = "lightgreen"
          end
          ColourTell (c, "", string.format ("%%+iM", mana_diff))
          ColourTell ("silver", "", "&gt;")
        end
        if ego_diff then
          ColourTell ("silver", "", "&lt;")
          local c
          if ego_diff &lt; 0 then
            c = "salmon"
          else
            c = "lightgreen"
          end
          ColourTell (c, "", string.format ("%%+iE", ego_diff))
          ColourTell ("silver", "", "&gt;")
        end
      end

      Note ("")
end


This causes an error on line 13 that reads;
[string "Script file"]:13: unexpected symbol near '%'


So the trigger can not make a call to the function.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #16 on Tue 21 Aug 2007 06:38 AM (UTC)
Message
You are mixing a couple of techniques here. If you do "send to script" then %1 is wildcard 1, straight from the current trigger invocation.

However if you call a function in a script file, which is precompiled, you don't use %1 but use wildcards [1] instead. Ditto for %2 and so on.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Simimi   (40 posts)  Bio
Date Reply #17 on Tue 21 Aug 2007 05:48 PM (UTC)
Message
Well, now it gives different errors related to the same problem, my mixing of styles (I had no idea you could use [1] in a script for a wildcard... idea nevr occured to me to use wild cards in my script! Saves me a lot of time that one does!)


[string "Script file"]:13: unexpected symbol near '['
13:    health = [1]

If I remove the equals I get an error on 14, such that;

[string "Script file"]:14: '=' expected near 'health_diff'
13: health [1]
14:      health_diff = nil


Hrm... As I change things the errors kind of cascade down in that manner, must be a lot that needs rewriting, or I am just not understanding something about this syntax issue.
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #18 on Tue 21 Aug 2007 07:03 PM (UTC)
Message
It should be
health = wildcards[1]

That's what the wildcards argument to the mytrigger function is doing. It's creating a table with the wildcards in it.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Simimi   (40 posts)  Bio
Date Reply #19 on Tue 21 Aug 2007 08:12 PM (UTC)
Message
Then, after changing that line, the error goes to line 44, which reads:

 if health_diff &lt; 0 then
with the error;

[string "Script file"]:44: 'then' expected near '&'
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #20 on Tue 21 Aug 2007 08:38 PM (UTC)
Message
if this is within the script file, the '&lt;' should be a '<'. When copying the trigger, MUSHclient converts it into xml, requiring '<' and '>' to become '&lt;' and '&gt;' respectively. You will need to fix this for all your comparisons, as well as in your ColourTell calls.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #21 on Tue 21 Aug 2007 10:56 PM (UTC)
Message
Use MUSHclient's internal notepad, Convert menu -> Unconvert HTML Special.

However you shouldn't have the &lt; stuff in your script if you copied it from within the "send" box of the trigger. But, if you have copied the trigger to the clipboard it has to convert < to &lt; > to &gt; and so on, because the symbols < and > are themselves used to indicate the start of things (like triggers).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gore   (207 posts)  Bio
Date Reply #22 on Wed 22 Aug 2007 12:07 AM (UTC)

Amended on Wed 22 Aug 2007 12:16 AM (UTC) by Gore

Message
For what it's worth, here is my script to reprocess and echo the prompt in Lusternia

function prompt (name,output,wildcard)
  hp.prev = hp.cur            -- Set Previous values for
  mp.prev = mp.cur            -- Computing differences
  ep.prev = ep.cur
  pp.prev = pp.cur
  hp.cur = tonumber(wc[1])
  mp.cur = tonumber(wc[2])
  ep.cur = tonumber(wc[3])
  pp.cur = tonumber(wc[4])
  
  local defs = wc[5]
  
  aff.prone = (string.find (defs, "p") ~= nil)
  bal.bal = (string.find (defs, "x") ~= nil)
  bal.eq = (string.find (defs, "e") ~= nil)
  bal.la = (string.find (defs, "l") ~= nil)
  bal.ra = (string.find (defs, "r") ~= nil)
  
  sipqueue()
  
  -- What color to echo health/mana/ego values as, the %'s
  -- aren't exact to lusty, lusty used 33%, 66% i think
  -- instead of 25%, 75%

  if hp.cur > .70 * hp.max then   
    hp.col = "green"            
  elseif hp.cur > .25 * hp.max then
    hp.col = "gold"             
  elseif hp.cur > 0 * hp.max then
    hp.col = "red"
  else
    hp.col = "silver"
  end
  
  if mp.cur > .70 * mp.max then
    mp.col = "green"
  elseif mp.cur > .25 * mp.max then
    mp.col = "gold"
  elseif mp.cur > 0 * mp.max then
    mp.col = "red"
  else
    mp.col = "silver"
  end
  
  if ep.cur > .70 * ep.max then
    ep.col = "green"
  elseif ep.cur > .25 * ep.max then
    ep.col = "gold"
  elseif ep.cur > 0 * ep.max then
    ep.col = "red"
  else
    ep.col = "silver"
  end
  
  if pp.cur > 7 then
    pp.col = "green"
  elseif pp.cur > 2 then
    pp.col = "gold"
  elseif pp.cur > 0 then
    pp.col = "red"
  else
    pp.col = "silver"
  end
  
  hp.per = math.floor (100 * ( hp.cur / hp.max ))
  mp.per = math.floor (100 * ( mp.cur / mp.max ))
  ep.per = math.floor (100 * ( ep.cur / ep.max ))
   
  ColourTell (hp.col, color.bg, hp.cur)
  ColourTell ("silver", color.bg, "(")
  ColourTell (hp.col, color.bg, hp.per)
  ColourTell ("silver", color.bg, ")")
  ColourTell (hp.col, color.bg, "h, ")
  
  ColourTell (mp.col, color.bg, mp.cur)
  ColourTell ("silver", color.bg, "(")
  ColourTell (mp.col, color.bg, mp.per)
  ColourTell ("silver", color.bg, ")")
  ColourTell (mp.col, color.bg, "m, ")
  
  ColourTell (ep.col, color.bg, ep.cur)
  ColourTell ("silver", color.bg, "(")
  ColourTell (ep.col, color.bg, ep.per)
  ColourTell ("silver", color.bg, ")")
  ColourTell (ep.col, color.bg, "e, ")
  
  ColourTell (pp.col, color.bg, pp.cur .. "p ")
  
  ColourTell ("silver", color.bg, defs .. "-")
  
  -- Computing differences and echoing based on whether it's   
  -- gain or loss
  if hp.cur ~= hp.prev then
    hp.diff = hp.cur - hp.prev
    if hp.diff > 0 then
      ColourTell ("coral", color.bg, "[")
      ColourTell ("limegreen", color.bg, "+" .. hp.diff .. "h")
      ColourTell ("coral", color.bg, "]")
    elseif hp.diff < 0 then
      ColourTell ("coral", color.bg, "[")
      ColourTell ("red", color.bg, hp.diff .. "h")
      ColourTell ("coral", color.bg, "]")
    end
  end
  if mp.cur ~= mp.prev then
    mp.diff = mp.cur - mp.prev
    if mp.diff > 0 then
      ColourTell ("steelblue", color.bg, "[")
      ColourTell ("limegreen", color.bg, "+" .. mp.diff .. "m")
      ColourTell ("steelblue", color.bg, "]")
    elseif mp.diff < 0 then
      ColourTell ("steelblue", color.bg, "[")
      ColourTell ("red", color.bg, mp.diff .. "m")
      ColourTell ("steelblue", color.bg, "]")
    end
  end
  if ep.cur ~= ep.prev then
    ep.diff = ep.cur - ep.prev
    if ep.diff > 0 then
      ColourTell ("lightgreen", color.bg, "[")
      ColourTell ("limegreen", color.bg, "+" .. ep.diff .. "e")
      ColourTell ("lightgreen", color.bg, "]")
    elseif ep.diff < 0 then
      ColourTell ("lightgreen", color.bg, "[")
      ColourTell ("red", color.bg, ep.diff .. "e")
      ColourTell ("lightgreen", color.bg, "]")
    end
  end
  if pp.cur ~= pp.prev then
    pp.diff = pp.cur - pp.prev
    if pp.diff > 0 then
      ColourTell ("violet", color.bg, "[")
      ColourTell ("limegreen", color.bg, "+" .. pp.diff .. "p")
      ColourTell ("violet", color.bg, "]")
    elseif pp.diff < 0 then
      ColourTell ("violet", color.bg, "[")
      ColourTell ("red", color.bg, pp.diff .. "p")
      ColourTell ("violet", color.bg, "]")
    end
  end
  Note ("")
  
  -- Hp: Coral
  -- Mp: Steelblue
  -- Ep: lightgreen
  -- Pp: violet

end


Quote:
Luciden raises a palm which glows with a tiny pinpoint of light. The light turns into a sparkling
current of energy that slams into you, dissolving your flesh.
2426(64)h, 3537(97)m, 3396(106)e, 10p elrx-[-707h]
You take a drink from a beryl vial.
The potion heals and soothes you.
3058(81)h, 3537(97)m, 3396(106)e, 10p elrx-[+632h]


On my achaean system, I use a timestamp, but it's just a second counter that I use for timing things. [16.05t] etc, it goes up to 60 then resets to 0

Sorry if this doesn't help at all
Top

Posted by Simimi   (40 posts)  Bio
Date Reply #23 on Wed 22 Aug 2007 04:14 AM (UTC)
Message
Wow Nick, that saves me a lot of time. Every time I come to this forum I learn something new! Thanks for the help Gore. I collect examples of other people's work so I can learn from them, so this helps me immensely!

Well after working through this, using the converter, and changing the wildcards, we get this error.



[string "Script file"]:6: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
	[C]: in function 'ipairs'
	[string "Script file"]:6: in function 'mytrigger'
	[string "Trigger: "]:1: in main chunk




function mytrigger (name, line, wildcards, styles)

time_now = GetInfo (232) % 60

      for _, v in ipairs(styles) do
        ColourTell (RGBColourToName (v.textcolour),
                    RGBColourToName (v.backcolour),
                    v.text)
      end

      ColourTell("silver", "", os.date("<%%H:%%M:") .. string.format ("%%0.3f> ", time_now))

      health = wildcards[1]
      health_diff = nil

      if old_health and health ~= old_health then
        health_diff = health - old_health
      end

      old_health = health

      mana = wildcards[2]
      mana_diff = nil

      if old_mana and mana ~= old_mana then
        mana_diff = mana - old_mana
      end

      old_mana = mana

      ego = wildcards[3]
      ego_diff = nil

      if old_ego and ego ~= old_ego then
        ego_diff = ego - old_ego
      end

      old_ego = ego

      if health_diff or mana_diff or ego_diff then
        if health_diff then
          ColourTell ("silver", "", "<")
          local c
          if health_diff < 0 then
            c = "salmon"
          else
            c = "lightgreen"
          end
          ColourTell (c, "", string.format ("%%+iH", health_diff))
          ColourTell ("silver", "", ">")
        end
        if mana_diff then
          ColourTell ("silver", "", "<")
          local c
          if mana_diff < 0 then
            c = "salmon"
          else
            c = "lightgreen"
          end
          ColourTell (c, "", string.format ("%%+iM", mana_diff))
          ColourTell ("silver", "", ">")
        end
        if ego_diff then
          ColourTell ("silver", "", "<")
          local c
          if ego_diff < 0 then
            c = "salmon"
          else
            c = "lightgreen"
          end
          ColourTell (c, "", string.format ("%%+iE", ego_diff))
          ColourTell ("silver", "", ">")
        end
      end

      Note ("")
end


Appears the trigger is an issue, and all it is doing is calling the function "mytrigger"
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #24 on Wed 22 Aug 2007 07:11 AM (UTC)
Message
All it is doing? Can you paste the trigger please? See http://mushclient.com/copying

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Simimi   (40 posts)  Bio
Date Reply #25 on Wed 22 Aug 2007 07:31 AM (UTC)

Amended on Wed 22 Aug 2007 07:37 AM (UTC) by Simimi

Message
I'm pretty sure this is the same as it was for the other thread. I am mixing the systems. I've never seen a trigger not call a function from a script file before...

<triggers>
<trigger
enabled="y"
match="^(\d+)h, (\d+)m, (\d+)e, (\d+)p, (\d+)en, (\d+)w (e?l?r?x?k?d?b?p?s?S?i?)(\&lt;\&gt;)?\-$"
regexp="y"
script="mytrigger"
sequence="100"
>
</trigger>
</triggers>

my output like that is:

3289h, 3106m, 2923e, 10p, 15345en, 14430w elrx-<%H:%M:%0.3f>

Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #26 on Wed 22 Aug 2007 08:17 AM (UTC)
Message
The lines like the following should only have the %% for % within a trigger's 'send to' function. There is no parser stripping them out from the script file.
ColourTell("silver", "", os.date("<%H:%M:") .. string.format ("%0.3f> ", time_now))

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Simimi   (40 posts)  Bio
Date Reply #27 on Wed 22 Aug 2007 06:42 PM (UTC)
Message
Got it working, and here is the plugin!
http://forums.lusternia.com/index.php?act=attach&type=post&id=1518

Under Authors it states "Simimi/NickGammon/ShaunBiggs" I hope that is right and proper with the two of you?

I plan on setting up a website for these plugins at some point in the near future. Thanks so much for your help, it is very much greatly appreciated!
Top

Posted by Natasi   (79 posts)  Bio
Date Reply #28 on Wed 22 Aug 2007 08:06 PM (UTC)
Message
Is there a way to possibly set this up in VBscript? I would just need the Time with the milliseconds if possible.
Top

Posted by Simimi   (40 posts)  Bio
Date Reply #29 on Wed 22 Aug 2007 08:42 PM (UTC)
Message
if you use the plugin you can run it as is in Lua, while your system is in VBscript without a problem.
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.


155,436 views.

This is page 2, subject is 3 pages long:  [Previous page]  1  2 3  [Next page]

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

Go to topic:           Search the forum


[Go to top] top

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