help with a trigger/script

Posted by Zebra on Wed 26 Mar 2003 11:06 PM — 6 posts, 20,847 views.

#0
I have a question regarding the setting of a variable with a trigger.
The mud i play uses a 'graphical' way to show the hp, mental and stats.
I would like to convert this input to a number so i can use it in my hp script. I have no idea how to do this, im a newbie to scripting so i turn to you for a hint.

here is some copy paste from the 'graphical' interface they use:

Mental      not feeling very well 
|%%%%%%%%%%%%%%>                                          |
Physical    not feeling very well |%%%%%%%%%%%%%%%%%%%%%%%%%>                               |
Mental      degraded              |%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%>                 |
Physical    hurt                  |%%%%%%%%%%%%%%%%%%%%%%%%%%%%>                            |
Mental      degraded              |%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%>                          |

So what it basically comes down to is to make a trigger which triggers on the second '>' from the left and gives back the amount of spaces on the right of the '>' till the '|' and puts it in a variable. Or the amount of % would be even better.
I just have no idea how to get back this amount from this trigger.

If you post a script of how to do this could you specify the steps you are taking so i can apply them myself with other simular things.

Well i hope one of you guys can give me hand with this.

*edit: I cant get it to display it right, you have to imagine that in between the ..%%> and the | there are spaces..:)

You need to use [code] - I've added that in for you. - Nick Gammon
Amended on Thu 27 Mar 2003 03:55 AM by Nick Gammon
Australia Forum Administrator #1
You want a trigger like this:


<triggers>
  <trigger
   enabled="y"
   match="^(Mental|Physical) +.*\|(\%*)\&gt;( *)\|$"
   name="Physical"
   regexp="y"
   script="DoPhysical"
   sequence="100"
  >
  </trigger>
</triggers>



The script would look like this:


sub DoPhysical (name, line, wildcards)
dim amount_used
dim amount_unused

  amount_used = len (wildcards(2))
  amount_unused = len (wildcards(3))
  world.note wildcards (1) & " : " & _
             CStr (amount_used) & " units used"
  world.note wildcards (1) & " : " & _
             CStr (amount_unused) & " units not used"

end sub



The number of '%' symbols is in wildcards (2) - the second wildcard, and the number of spaces is in wildcards (3) - the third wildcard. I use "len" to find out how many there are.

I get a result like this:


Physical    not feeling very well |%%%%%%%%%%%%>                               |
Physical : 12 units used
Physical : 31 units not used


Amended on Thu 27 Mar 2003 04:21 AM by Nick Gammon
#2
Thankx a lot Nick, i made it work with your suggestions!

Now this is what i made with it, a graphical status display version 0.1.
It shows my mental and physical in the bars you desribed in another topic. Just have to post my creation here!
Pleae be aware that this is my first vernture into the world of coding and it is very probable that it can be done a lot simpler.

CODE:

sub DoPhysical (name, line, wildcards)
dim amount_used
dim amount_unused
dim max_amount
dim hp_me1
dim hp
max_amount = 40
amount_used = len (wildcards(2))
amount_unused = len (wildcards(3))
hp_me1 = 100 * ( amount_used / max_amount )
' world.note wildcards (1) & " : " & CStr (amount_used) & " units used"
' world.note wildcards (1) & " : " & CStr (hp_me1) & "%"
world.SetVariable "hp_me" , hp_me1
world.InfoClear
world.InfoFont "Arial", 12, 1 ' 12 point Arial *bold*
DoGaugehp " HP: ", world.getvariable ("hp_me"), "green", "red"
DoGaugemp " MP: ", world.getvariable ("mp_me"), "blue" , "purple"
world.note hp_me1
end sub

sub DoMental (name, line, wildcards)
dim amount_used
dim amount_unused
dim max_amount
dim mp_me1
dim mp
max_amount = 40
amount_used = len (wildcards(2))
amount_unused = len (wildcards(3))
mp_me1 = 100 * ( amount_used / max_amount )
' world.note wildcards (1) & " : " & CStr (amount_used) & " units used"
' world.note wildcards (1) & " : " & CStr (mp_me1) & "%"
world.SetVariable "mp_me" , mp_me1
end sub

sub Doreset (name, line, wildcards)
world.SetVariable "hp_me" , 0
world.SetVariable "mp_me" , 0
end sub

sub DoGaugehp (sPrompt, iCurrent, sGoodColour, sBadColour)
dim pc, count, hp_me1
'
' Do prompt in black Arial
'
world.InfoColour "black"
world.InfoFont "Arial", 10, 0
world.Info sPrompt
'
' Use Webdings for gauge (black square)
'
world.InfoFont "Webdings", 10, 0
hp_me1 = Cint (world.getvariable("hp_me"))
pc = CInt ((hp_me1) / 4)
'
' Below 40% warn by using different colour
'
if hp_me1 < 40 then
world.InfoColour sBadColour
else
world.InfoColour sGoodColour
end if
'
' Draw active part of gauge
'
for count = 1 to pc
world.Info "g"
next
'
' Draw rest of gauge in grey (ie. unfilled bit)
'
world.InfoColour "black"
while count < 25
count = count + 1
world.Info "g"
wend
end sub

sub DoGaugemp (sPrompt, iCurrent, sGoodColour, sBadColour)
dim count, mp_me1, pc2
'
' Do prompt in black Arial
'
world.InfoColour "black"
world.InfoFont "Arial", 10, 0
world.Info sPrompt
'
' Use Webdings for gauge (black square)
'
world.InfoFont "Webdings", 10, 0
mp_me1 = Cint (world.getvariable("mp_me"))
pc2 = Cint ((mp_me1) / 4)
'
' Below 40% warn by using different colour
'
if mp_me1 < 40 then
world.InfoColour sBadColour
else
world.InfoColour sGoodColour
end if
'
' Draw active part of gauge
'
for count = 1 to pc2
world.Info "g"
next
'
' Draw rest of gauge in grey (ie. unfilled bit)
'
world.InfoColour "black"
while count < 25
count = count + 1
world.Info "g"
wend
end sub

Well if you have any remarks on what i can improve, im always welcoming criticism.

Other question:
Could someone point me in the right direction of how to make a database which has to be filled with triggers ( i want to be able to list what monsters i killed, when, over different periods, what equipment they had and what how much money i made on them).
Just point me in the right direction, maybe a howto on creating databases with mushqlient?
( i dont have experience with Acces or other database programs so please dont point me to a knowledgebase or something..)

Tonight i will rewrite the above script so i can also see my partymembers hp and mana in thesame bar as mine.

Zebra worships Nick for creating MUSHClient...i love it!
Australia Forum Administrator #3
A couple of plugins use a database. You may be able to work out the general technique simply by reading the plugin. Once of them, for instance, maintains a list of MUDs. A fairly simple modification would change it to maintain a list of triggers.

This is simpler in many ways than using variables and remembering to save/load them, however you need to learn a bit about SQL to do it successfully. Basic SQL isn't too bad, it has been around for a while. You can try searching for some keywords on the 'Net, such as:

CREATE TABLE (creates a new table)
INSERT INTO (puts data into a table)
SELECT ... FROM (gets data from a table)
UPDATE ... SET (update a row in a table)
#4
Thankx for the pointers Nick, i will surely give that a try.

I reworked the code allready to also display my partymembers hp and mental.

I have two more questions which are more general axpression questions, i have (tried to) read the general expressions file which came with MUSHclient but cant really figure it out.

1:
Sometimes when you give a lot of commands there appears a "> " in front of the mentalbar how would i implement this in the trigger you allready made for me to also react when that happens?

> Mental not feeling very w..etc

instead of:

Mental not feeling very w

2:
To get the situation from my teammembers i need to process another bar like this one:

| Zaphod | %%%%%%%%%%%%%%%%%%%%%%%%%% | %%%%%%%%%%%%%%%%%%%%%%%%%% |

with the name, hp and mental situation of the teammembers, thesame as above applies here.

The scripting part i understand i just can get my triggers to match the right expressions...

Could you help me out one more time?

Thankx, and keep up the good work!

Z
Australia Forum Administrator #5
Quote:

Sometimes when you give a lot of commands there appears a "> " in front of the mentalbar how would i implement this in the trigger you already made for me to also react when that happens?


At the start of the trigger (after the ^) put this:


(?:> )*


This will match on zero or more instances of "> ". The ?: is used to stop the matching code appearing as a wildcard (so wildcard 1 is still wildcard 1).

Thus the match text would look like this:


   match="^(?:> )*(Mental|Physical) +.*\|(\%*)\&gt;( *)\|$"





Quote:

To get the situation from my teammembers i need to process another bar like this one:

| Zaphod | %%%%%%%%%%%%%%%%%%%%%%%%%% | %%%%%%%%%%%%%%%%%%%%%%%%%% |



Take a look at the regularexpressions.txt file that came with MUSHclient. You just need to break this like that down into the component parts, like this:

  • ^ - start of line
  • \| - match on "|" symbol (escaped with a backslash, just in case)
  • (.+) - match one one or more characters (eg, Zaphod)
  • \| - match on "|" symbol again - put a space before and after if you are expecting those
  • (\%*) - match on zero or more percent signs
  • \| - match on "|" symbol again - put a space before and after if you are expecting those
  • (\%*) - match on zero or more percent signs
  • \| - match on "|" symbol again
  • $ - match end-of-line


Put it all together and something like this should do it:


^\|(.+) \| (\%*) \| (\%*) \|$


You may need to tweak the spaces a bit, but that is the general idea.

The things inside round brackets become wildcards, so you would get three of them:

  1. Name, eg. Zaphod
  2. First batch of percent symbols
  3. Second batch of percent symbols