Assigning a variable to a specific roll result.

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
hastesword
Kobold
Posts: 2
Joined: Sun Oct 12, 2014 1:00 am

Assigning a variable to a specific roll result.

Post by hastesword »

Hey,guys this is my first post.
I had a question that's giving me some trouble, I'm running a Shadowrun game and I need a macro that tells me the number of hits, a character got on a test and then compare it to the results of another characters test, and if either test got a glitch. Relatively easy, but I need a variable to store the number of hits, usually for this I would use the success() function for the number of dice that get a 5 or a 6, but success() does not allow me to account for the number of 1's, but the sr4()function tells me not just the number of hits and 1s but also of a roll is a glitch. So my question is for a variable X how do I make X equal to the number of hits, or if a roll is a glitch in a sr4() roll or any roll that returns more than one value.
Thank you very much for your help.

User avatar
Irrlicht
Dragon
Posts: 426
Joined: Mon Feb 09, 2009 10:53 am

Re: Assigning a variable to a specific roll result.

Post by Irrlicht »

I don't know how Shadowrun's exact mechanics are, but if I have understood what you need, you can use a count() roll option.

Code: Select all

[h: roll = "1d6"]
[h: numOfRolls = 5]

[h: numOfOnes = 0]
[h: numOfSuccesses = 0]

[h, count(numOfRolls), code: {
   [h: evalRoll = eval(roll)]
   [h, if(evalRoll == 1): numOfOnes = numOfOnes + 1]
   [h, if(evalRoll >= 5): numOfSuccesses = numOfSuccesses + 1]
}]

1s: [r: numOfOnes]
<br>
Successes: [r: numOfSuccesses]

"There are many ways my Son, to find where the souls of Demons remain...
But it takes only one second of despair and of doubt until, at last, your Soul they will gain..."

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Assigning a variable to a specific roll result.

Post by aliasmask »

I'm not familiar with the system but after looking at the output of Xsr4gT dice expression I think I understand what you want.

Code: Select all

[H: abort(input("numDice|1|Number of Dice|Text","T|0|T value|Text"))]
[H: result = eval(strformat("%{numDice}sr4g%{T}"))]
[H: hitsRegex = "Hits: ([0-9]+)"]
[H: hits = getGroup(strfind(result,hitsRegex),1,1)]
[H: hasGlitch = getFindCount(strfind(result,"Glitch"))]
[R: result]
[R, if(hasGlitch): "<br>There is a Glitch"]
[R: strformat("<br>There are %{hits} hit(s)")] 
The number of Hits is stored and hasGlitch is true or false.

hastesword
Kobold
Posts: 2
Joined: Sun Oct 12, 2014 1:00 am

Re: Assigning a variable to a specific roll result.

Post by hastesword »

Irrlicht wrote:I don't know how Shadowrun's exact mechanics are, but if I have understood what you need, you can use a count() roll option.

Code: Select all

[h: roll = "1d6"]
[h: numOfRolls = 5]

[h: numOfOnes = 0]
[h: numOfSuccesses = 0]

[h, count(numOfRolls), code: {
   [h: evalRoll = eval(roll)]
   [h, if(evalRoll == 1): numOfOnes = numOfOnes + 1]
   [h, if(evalRoll >= 5): numOfSuccesses = numOfSuccesses + 1]
}]

1s: [r: numOfOnes]
<br>
Successes: [r: numOfSuccesses]

thanks man that's great and pretty elegant also super easy.

Post Reply

Return to “Macros”