Help w/stat rolling script

Posted by Brie on Mon 11 Aug 2003 05:17 PM — 6 posts, 25,385 views.

#0
I'm really stuck and I'm not sure what I'm doing wrong. Any help would be appreciated.

This is the output from the mud:

Your character's base stats have been rerolled...
                     New             Previous
Strength              14                   14
Dexterity             14                   16
Intelligence          13                   12
Wisdom                12                   13
Charisma               9                   11
Constitution          18                   16
Luck                  15                   13


This is a script that a friend sent me:



<triggers>
  <trigger
   enabled="y"
   match="Charisma              *"
   name="ccha"
   script="checkcha"
   send_to="12"
   sequence="100"
   other_text_colour="black"
   other_back_colour="black"
  >
  </trigger>
  <trigger
   enabled="y"
   match="Constitution          *"
   name="ccon"
   script="checkcon"
   send_to="12"
   sequence="100"
   other_text_colour="black"
   other_back_colour="black"
  >
  </trigger>
  <trigger
   enabled="y"
   match="Dexterity             *"
   name="cdex"
   script="checkdex"
   send_to="12"
   sequence="100"
   other_text_colour="black"
   other_back_colour="black"
  >
  </trigger>
  <trigger
   enabled="y"
   match="Intelligence          *"
   name="cint"
   script="checkint"
   send_to="12"
   sequence="100"
   other_text_colour="black"
   other_back_colour="black"
  >
  </trigger>
  <trigger
   enabled="y"
   match="Luck                  *"
   name="clck"
   script="checklck"
   send_to="12"
   sequence="100"
   other_text_colour="black"
   other_back_colour="black"
  >
  </trigger>
  <trigger
   enabled="y"
   match="Strength              *"
   name="cstr"
   script="checkstr"
   send_to="12"
   sequence="100"
   other_text_colour="black"
   other_back_colour="black"
  >
  </trigger>
</triggers>

dim rerollstats

sub checkstr(strtriggerName, trig_line, arrWildCards)
	
	rerollstats = 0
	
	dim str	
	str = 16		
	if arrWildCards(1) >= str then
		rerollstats = 1
	end if
end sub
		
sub checkdex(strtriggerName, trig_line, arrWildCards)
		
	dim dex
	dex = 16

	if arrWildCards(1) >= dex then
		rerollstats = 1
	end if
end sub

sub checkint(strtriggerName, trig_line, arrWildCards)
	
	dim int
	int = 0
		
	if arrWildCards(1) >= int then
		rerollstats = 1
	end if
end sub

sub checkwis(strtriggerName, trig_line, arrWildCards)
	
	dim wis
	wis = 0	
		
	if arrWildCards(1) >= wis then
		rerollstats = 1
	end if
end sub

sub checkcha(strtriggerName, trig_line, arrWildCards)
	
	dim cha
	cha = 0	
		
	if arrWildCards(1) >= cha then
		rerollstats = 1
	end if
end sub

sub checkcon(strtriggerName, trig_line, arrWildCards)
	
	dim con
	con = 0
		
	if arrWildCards(1) >= con then
		rerollstats = 1
	end if

end sub	

sub checklck(strtriggerName, trig_line, arrWildCards)
	
	dim lck
	lck = 12
		
	if arrWildCards(1) >= lck then
		rerollstats = 1
	end if

	reroll()
end sub

sub reroll()

	if rerollstats = 1 then
		world.send "reroll"
		rerollstats = 0
	else
		world.send "touch orb"
	end if
end sub




For some reason it just keeps sending reroll to the mud, even if the ouput is well over 16 on str and dex. I played around with it a bit and couldn't get it to work, so I attempted to code one based off other forum posts. I don't know how to script really, so I'm not surprised it doesn't work.. but here's what I came up with.



<triggers>
  <trigger
   enabled="y"
   match="(Strength|Dexterity|Intelligence|Wisdom|Charisma|Constitution|Luck)\s*(\d+)\s*(\d+)$"
   name="Stats"
   script="checkstats"
   send_to="12"
   sequence="100"
   other_text_colour="black"
   other_back_colour="black"
  >
  </trigger>
</triggers>



dim rerollstats

sub checkstats(strtriggerName, trig_line, arrWildCards)
	
	rerollstats = 0
	
	dim str, dex, int, wis, cha, con, lck
	str = 18
	dex = 18
	int = 0
	wis = 0
	cha = 0
	con = 0
	lck = 12

	if arrWildCards(2) >= str and _
	if arrWildCards(2) >= dex and _
	if arrWildCards(2) >= int and _
	if arrWildCards(2) >= wis and _
	if arrWildCards(2) >= cha and _
	if arrWildCards(2) >= con and _
	if arrWildCards(2) >= lck then
		rerollstats = 1
	end if

	reroll()

end sub
		
sub reroll()

	if rerollstats = 1 then
		world.send "reroll"
		rerollstats = 0
	else
		world.send "touch orb"
	end if

end sub



The last script gives me an error message at this line: if arrWildCards(2) >= dex and _

So.. can please someone enlighten me to the error of my ways? Thanks again.
Canada #1
I believe the super IF checking you do is not using the correct VB syntax. You would likely want it to be more like this:

	if (arrWildCards(2) >= str) and _
	   (arrWildCards(2) >= dex) and _
	   (arrWildCards(2) >= int) and _
	   (arrWildCards(2) >= wis) and _
	   (arrWildCards(2) >= cha) and _
	   (arrWildCards(2) >= con) and _
	   (arrWildCards(2) >= lck) then
		rerollstats = 1
	end if

Now, that might get your script working, technically, but I believe the logic is wrong. Remember, you are calling this same script once for each attribute presented to you. What will happen is the script will be called 7 times, but each iteration will wipe out the value of "rerollstats", and what you end up doing is checking the value of "luck" for all your stats. In other words, if "luck" was 13, then your script will check if str is => 13, and dex => 13, and int => 13, etc...

I would either go back to the method handed to you by a friend (One trigger for each attribute), or else use one trigger and make a check in the script to see which attribute it was.

For example:

<triggers>
  <trigger
   enabled="y"
   match="(Strength|Dexterity|Intelligence|Wisdom|Charisma|Constitution|Luck)\s*(\d+)\s*(\d+)$"
   name="Stats"
   script="Store_Stats"
   send_to="12"
   sequence="100"
  >
  </trigger>
</triggers>

Dim Str, Dex, Int, Wis, Cha, Con, Lck

Sub Store_Stats (TriggerName, TriggerLine, arrWildcards)
   Select Case arrWildcards(1)
      Case "Strength"
        Str = arrWildcards(2)
      Case "Dexterity"
        Dex = arrWildcards(2)
      Case "Intelligence"
        Int = arrWildcards(2)
      Case "Wisdom"
        Wis = arrWildcards(2)
      Case "Charisma"
        Cha = arrWildcards(2)
      Case "Constitution"
        Con = arrWildcards(2)
      Case "Luck"
        Lck = arrWildcards(2)
        Check_Stats
   End Select
End Sub

Sub Check_Stats
	if (Str => 18) and _
	   (Dex => 18) and _
	   (Int => 0) and _
	   (Wis => 0) and _
	   (Cha => 0) and _
	   (Con => 0) and _
	   (Lck => 12) then
	     World.Send "touch orb"
	else
	     World.Send "reroll"
	end if
End Sub
Canada #2
BTW: Two logic errors in your friends original script:
"1" means the value is acceptable, but he rerolls if the value is "1"
Any SINGLE attribute meeting your requirements sets the value to "1"

I won't bother to advise a fix for that method.
#3
Thank you very much :)
Australia Forum Administrator #4
You also have a problem with the trigger match. The original was matching on:


match="Charisma              *"


However what the MUD sends is:

   
Charisma               9                   11


That means the wildcard will be "9 11" which will not give the right results.
#5
I was helping someone set this script up and realized there are a couple of errors in Magnum's trigger. First, it sends to script instead of world. Second, it's not set up as a regular expression.

It should look like this instead:


<triggers>
  <trigger
   enabled="y"
   match="(Strength|Dexterity|Intelligence|Wisdom|Charisma|Constitution|Luck)\s*(\d+)\s*(\d+)$"
   name="Stats"
   regexp="y"
   script="Store_Stats"
   sequence="100"
  >
  </trigger>
</triggers>