Help with stat roll matching

Posted by Boen310 on Wed 09 Nov 2022 02:09 PM — 11 posts, 26,526 views.

#0
Trying to create a stat roller where its matching on words and the value after(word)....here is the sample output

Your basic stats:
Strength: good Power: excellent
Dexterity: good Intelligence: very good
Agility: very good Wisdom: good
Constitution: very good Charisma: good

Luck: very good Unused: very good


Currently I am using this but am not having any luck

Trigger:
^/s*(Strength|Dexterity|Constitution|Wisdom|Agility)\s+\ (good|very good|excellent)

Send:
#switch (%2)
("good") {Goodcnt = @Goodcnt + 1}
("very good") {VGcnt = @VGcnt + 1}
("excellent") {EXCcnt = @EXCcnt + 1}
{}

Then second trigger:
^Do you want to reroll this char$

Sending:
#show @EXCcnt
#IF (@EXCcnt > 4) (#show @EXCcnt;#3#beep) {y}
EXCcnt = 0
VGcnt = 0
Goodcnt = 0


Any help would be apprecaited.
PS tried [code] [/code] as top output isn't mono spaced
Amended on Wed 09 Nov 2022 11:15 PM by Boen310
#1
You aren't very clear on what isn't working, but I suspect it's the following.

The code you are using seems to be zscript, commonly used by zMUD/CMUD. In order to use it in MUSHclient, you'll need to emulate the same functions in a language that MUSHclient can utilize.

In Lua code, you could do something akin to:


if ("%2" == "good") then
   SetVariable("Goodcnt", GetVariable("Goodcnt") + 1)
elseif ("%2" == "very good") then
   SetVariable("VGcnt", GetVariable("VGcnt") + 1)
elseif ("%2" == "excellent") then
   SetVariable("EXCcnt", GetVariable("EXCcnt") + 1)
end


That would be your first trigger, send to script. For your second trigger, you would do:


if (GetVariable("EXCcnt") > 4) then
   Note(GetVariable("EXCcnt"))
   Sound("ding.wav") -- or whatever sound you want to play
   Send("y") -- Assuming you want to reroll if excellent count is greater than 4; perhaps you meant 'n' instead?
   SetVariable("Goodcnt", 0)
   SetVariable("VGcnt", 0)
   SetVariable("EXCcnt", 0)
end


Also, make sure that Regular Expression is ticked in each of your trigger boxes. The triggers you supplied are in regex form, and should be flagged as such.
Amended on Wed 09 Nov 2022 05:50 PM by AdInfinitum
#2
Thank you for the update to the code. Was what found for something and modified. I can't seem to get anything to trigger. Copied what you gave for both and sent first to Script and sent second to World and it never triggers

Output:

Your basic stats:
Strength:           excellent      Power:        very good
Dexterity:          very good      Intelligence: very good
Agility:            very good      Wisdom:       very good
Constitution:       very good      Charisma:     very good

Luck:       very good      Unused:     excellent


Trigger:


^/s*(Strength|Dexterity|Constitution|Wisdom|Agility)\s+\ (good|very good|excellent)
Australia Forum Administrator #3
Template:what
Please help us by showing:
  • A copy of the trigger, alias or timer you were using (see Copying XML)
  • The error message, if any, that you got
#4
Boen310 said:

Thank you for the update to the code. Was what found for something and modified. I can't seem to get anything to trigger. Copied what you gave for both and sent first to Script and sent second to World and it never triggers

Output:

Your basic stats:
Strength:           excellent      Power:        very good
Dexterity:          very good      Intelligence: very good
Agility:            very good      Wisdom:       very good
Constitution:       very good      Charisma:     very good

Luck:       very good      Unused:     excellent


Trigger:


^/s*(Strength|Dexterity|Constitution|Wisdom|Agility)\s+\ (good|very good|excellent)



Your trigger is missing a colon, which seems to exist in your output. Additionally, there are two other errors with your trigger line. When you start a trigger line with a "^", it means to start looking at the start of the line and nowhere else. This means, at the very least, that "Wisdom" will never be captured. Additionally, your "/s" is supposed to be "\s". Your trigger line probably needs to be:

(Strength|Dexterity|Constitution|Wisdom|Agility):\s+\ (good|very good|excellent)


Once again, make sure that you have Regular Expression ticked, otherwise it will not work.

Also, BOTH triggers need to be Send to script if using the code.

If all this fails, please follow what Nick asked above. It really helps to have you display what your triggers are by providing the XML of it, and doubly so when you give us the error message if one is provided.
#5

Trigger1:

(Strength|Dexterity|Constitution|Wisdom|Agility):\s+\ (good|very good|excellent)

Send1:

if ("%2" == "good") then
   SetVariable("Goodcnt", GetVariable("Goodcnt") + 1)
elseif ("%2" == "very good") then
   SetVariable("VGcnt", GetVariable("VGcnt") + 1)
elseif ("%2" == "excellent") then
   SetVariable("EXCcnt", GetVariable("EXCcnt") + 1)
end

Trigger2:
Do you want to reroll this char

Send2:
if (GetVariable("EXCcnt") > 4) then
   Note(GetVariable("EXCcnt"))
   Sound("ding.wav")
   Send("n")
   SetVariable("Goodcnt", 0)
   SetVariable("VGcnt", 0)
   SetVariable("EXCcnt", 0)
end


Both to Script

Getting this error now:

Run-time error
World: Duris
Immediate execution
[string "Trigger: "]:2: attempt to perform arithmetic on a nil value
stack traceback:
        [string "Trigger: "]:2: in main chunk


The value of 2 here [string "Trigger: "]:2: changes between 1,2,4,6
Amended on Thu 10 Nov 2022 04:57 PM by Boen310
#6
I see what the issue is. You do not have Goodcnt, VGcnt, and EXCcnt set prior to running the script. To counter that, make the following change:


if ("%2" == "good") then
   SetVariable("Goodcnt", (GetVariable("Goodcnt") or 0) + 1)
elseif ("%2" == "very good") then
   SetVariable("VGcnt", (GetVariable("VGcnt") or 0) + 1)
elseif ("%2" == "excellent") then
   SetVariable("EXCcnt", (GetVariable("EXCcnt") or 0) + 1)
end


If the variable does not exist, it'll assume 0 and add 1 to it. Otherwise, it will take the variable's count and add 1 to it.

Hopefully this solves it all.
#7

Run-time error
World: Duris
Immediate execution
[string "Trigger: "]:1: attempt to compare number with string
stack traceback:
        [string "Trigger: "]:1: in main chunk


made changes and get this now.
#8
This is what happens when you try to respond while at work. Despite being a number, variables are saved as type "string". The change for the second trigger needs to be:


if (GetVariable("EXCcnt") > 4) then


changed to:


if (tonumber(GetVariable("EXCcnt")) > 4) then


If there are more failures, please highlight the triggers in the GUI and click the 'Copy' button located near the bottom right of the button group. Then come here and 'paste' the actual XML.
#9
I turned on tracing if that is what you mean and this is the output from that. This is made after your latest change. It run this and does not continue to keep rolling.



Your basic stats:
Strength:           very good      Power:        very good
TRACE: Matched trigger "(Strength|Dexterity|Constitution|Wisdom|Agility):\s+\ (good|very good|excellent)"
Dexterity:          very good      Intelligence: good
TRACE: Matched trigger "(Strength|Dexterity|Constitution|Wisdom|Agility):\s+\ (good|very good|excellent)"
Agility:            very good      Wisdom:       very good
TRACE: Matched trigger "(Strength|Dexterity|Constitution|Wisdom|Agility):\s+\ (good|very good|excellent)"
Constitution:       very good      Charisma:     very good
TRACE: Matched trigger "(Strength|Dexterity|Constitution|Wisdom|Agility):\s+\ (good|very good|excellent)"

Luck:       very good      Unused:     very good


                Lame: 0-9 Poor:10-21 Below Avg:22-33 
                Avg:34-67 Above Avg:68-79 Good:80-85
                            Very good:86+:
 
Place your bonuses as you think will fit your playing style, as well as benefit 
TRACE: Matched trigger "Place your bonuses as you think will fit your playing style, as well as benefit"
7
n
your character.  Your stats will be further modified within the game by equipment 
and spells, and can be permanently modified as well.
Do you want to reroll this char (y/n) [y]:  

Accepting these stats.


If looking for something else please let me know as I did not see that option. Thank you for assisting.
Amended on Thu 10 Nov 2022 07:50 PM by Boen310
Australia Forum Administrator #10

I don’t see how your trigger will match both items on the same line (eg. Strength and Power).

You probably need to go about it differently:

  • When you see the line “Your basic stats:” activate (enable) another trigger

  • This second trigger matches “*” (ie, everything).

  • In the code, do a regular expression match (using Lua “string.match” function) for all the words (Strength, Power, Dexterity etc.).

  • If one matches note what value you got

  • When you see the line “Do you want to reroll this char” then respond accordingly and turn the trigger I mentioned above off.