Check die result from eval(someproperty) and return a true/false if a certain die face is rolled

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

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

Post Reply
Rebullet
Kobold
Posts: 14
Joined: Wed Jun 24, 2020 11:51 am

Check die result from eval(someproperty) and return a true/false if a certain die face is rolled

Post by Rebullet »

so the game we are playing is dark heresy 2nd edition and im setting up macros for everyone. i have stumbled along just fine until i reached this question.

my campaign property is filled in as such: 2d10 + [r: 2 + STB + USTB]
i roll this value in my macros with eval(getProperty("Weapon1Damage"))]
this works no problem to get me the total value.

what i need to check is if one of those 2d10 ended up with a showing 10.
if so i need to roll a 1d5 for critical damage.
it also can only happen once so if both die roll 10 i still only roll 1d5.

is there a way to do this?

User avatar
wolph42
Deity
Posts: 9703
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Check die result from eval(someproperty) and return a true/false if a certain die face is rolled

Post by wolph42 »

just to be clear you are aware that theres a W40K framework? granted its based on DH 1 but we've implemented RT, DW, OW and BC systems as well, so most rules should be covered by it!

and yes theres' obviously a way to do what you want but that would require a more step like macro with a couple of if statements and Im guessing that the '2' in '2d10' is arbitrary depending on weapon in use so a loop is required as well!

else you would get something like

Code: Select all

d1  = 1d10
d2 = 1d10
crit = if(d1==10 || d2==10, 1d5,0)

rolled damage is: d1+d2+stb+ustb
if(crit): "Crit is rolled for: "+crit+" damage"
(youll have to add the [] yourself)

Rebullet
Kobold
Posts: 14
Joined: Wed Jun 24, 2020 11:51 am

Re: Check die result from eval(someproperty) and return a true/false if a certain die face is rolled

Post by Rebullet »

so yea i figured that wh40k had framework but im not the gm. im throwing the gm macros that i create for his game.
let me be more specific tho. the campaign property weapon1damage has this : (numDice)d10 + (bonuses)
what im trying to do is seperate the numDice from the bonuses, check the rolled values and such while depending on the property itself. so i need to have a specific way to pull and seperate that data. i want the person to be able to modify his sheet and not have to worry about his macro.

taustinoc
Dragon
Posts: 428
Joined: Mon Aug 03, 2015 6:30 pm

Re: Check die result from eval(someproperty) and return a true/false if a certain die face is rolled

Post by taustinoc »

getRolled() will give you the individual die rolls as a string list.
listContains() will tell you how many times a particular result is in that string list.

If the listContains() returns more than one, you have your crit.

Rebullet
Kobold
Posts: 14
Joined: Wed Jun 24, 2020 11:51 am

Re: Check die result from eval(someproperty) and return a true/false if a certain die face is rolled

Post by Rebullet »

awesome ill try it out real quick.

Rebullet
Kobold
Posts: 14
Joined: Wed Jun 24, 2020 11:51 am

Re: Check die result from eval(someproperty) and return a true/false if a certain die face is rolled

Post by Rebullet »

this was exactly what i needed. thanks my dude. big help.
taustinoc wrote:
Thu Jun 25, 2020 1:00 pm
getRolled() will give you the individual die rolls as a string list.
listContains() will tell you how many times a particular result is in that string list.

If the listContains() returns more than one, you have your crit.

taustinoc
Dragon
Posts: 428
Joined: Mon Aug 03, 2015 6:30 pm

Re: Check die result from eval(someproperty) and return a true/false if a certain die face is rolled

Post by taustinoc »

I have a similar need for a Hero framework I've been dabbling with. Happy to help.

Rebullet
Kobold
Posts: 14
Joined: Wed Jun 24, 2020 11:51 am

Re: Check die result from eval(someproperty) and return a true/false if a certain die face is rolled

Post by Rebullet »

well i seem to have run into a strange problem. when using listcontains it seems to not see every number that matches its parameter. for instance i roll 2d10 and get 5 and 10 but when list contains searches it for 10's it finds nothing. but it works if i use more dice. if i roll 10d10 and get only one or more 10s then it sees it and works correctly. im very confused.

Rebullet
Kobold
Posts: 14
Joined: Wed Jun 24, 2020 11:51 am

Re: Check die result from eval(someproperty) and return a true/false if a certain die face is rolled

Post by Rebullet »

here is the code for the area where the issue is. i have a couple of lines to show me what numbers are being stored but do nothing else.

Code: Select all

[COUNT(numberOfHits, ""),CODE:
{
<br>
[h: didCrit = 0]
[h: hitLocation = 1d100]
[h: critDamage = ""]

[h:switchToken(targetName)]

[h: armor = if(hitLocation >= 1 && hitLocation <= 10, armorHead, armor)]
[h: armor = if(hitLocation >= 11 && hitLocation <= 20, armorRightArm, armor)]
[h: armor = if(hitLocation >= 21 && hitLocation <= 30, armorLeftArm, armor)]
[h: armor = if(hitLocation >= 31 && hitLocation <= 70, armorBody, armor)]
[h: armor = if(hitLocation >= 71 && hitLocation <= 85, armorRightLeg, armor)]
[h: armor = if(hitLocation >= 86 && hitLocation <= 100, armorLeftLeg, armor)]

[h: clearRolls()]
[h: penetration = armor - weaponPen]

[h:switchToken(currentT)]

[h: damageByWeapon = eval(getProperty("Weapon1Damage"))]<br>
[r: getRolled()]
[r: listContains(getRolled(), 10)]
[r: didCrit = if(listContains(getRolled(), 10) >= 1, 1, didCrit)]<br>
[h: remainingArmor = if(penetration > 0, penetration, 0)]

<!-- output -->
[h:switchToken(targetName)]
[r: "The "]
[r: weaponName]
[r: " deals "]
<b><font color="blue">[r: damageByWeapon - (remainingArmor + TB)]</color></b>
[r: " "]
<b><font color="green">[r: damageType]</color></b>
[r: " to target's "] 

[r: if((hitLocation >= 1 && hitLocation <= 10),"head.","")]
[r: if((hitLocation >= 11 && hitLocation <= 20),"right arm.","")]
[r: if((hitLocation >= 21 && hitLocation <= 30),"left arm.","")]
[r: if((hitLocation >= 31 && hitLocation <= 70),"body.","")]
[r: if((hitLocation >= 71 && hitLocation <= 85),"right leg.","")]
[r: if((hitLocation >= 86 && hitLocation <= 100),"left leg.","")]

[h: critPreText = "Sadly, there was no Righteous Fury"]
[h: critPostText = " in this attack."]

[h, if(didCrit == true), code:
{
	[h: critDamage = roll(1, 5)]
	[h: critPreText = "The " + weaponName + " also deals "]
	[h: critPostText = " critical " + damageType + " to target's "]
	[h: critPostText = if((hitLocation >= 1 && hitLocation <= 10), critPostText + "head.",critPostText)]
	[h: critPostText = if((hitLocation >= 11 && hitLocation <= 20), critPostText + "right arm.",critPostText)]
	[h: critPostText = if((hitLocation >= 21 && hitLocation <= 30), critPostText + "left arm.",critPostText)]
	[h: critPostText = if((hitLocation >= 31 && hitLocation <= 70), critPostText + "body.",critPostText)]
	[h: critPostText = if((hitLocation >= 71 && hitLocation <= 85), critPostText + "right leg.",critPostText)]
	[h: critPostText = if((hitLocation >= 86 && hitLocation <= 100), critPostText + "left leg.",critPostText)]
};{""}]
<br>
[r: critPreText]
<b><font color="red">[r: critDamage]</color></b>
[r: critPostText]

}]
and i get outcomes like this:
[6] 0 0 The Chainsword deals 8 Rending Damage to target's left leg. Sadly, there was no Righteous Fury in this attack.
[1] 0 0 The Chainsword deals 3 Rending Damage to target's left arm. Sadly, there was no Righteous Fury in this attack.
[10] 0 0 The Chainsword deals 12 Rending Damage to target's body. Sadly, there was no Righteous Fury in this attack.
[3] 0 0 The Chainsword deals 5 Rending Damage to target's body. Sadly, there was no Righteous Fury in this attack.
[1] 0 0 The Chainsword deals 3 Rending Damage to target's left leg. Sadly, there was no Righteous Fury in this attack.

Phergus
Deity
Posts: 7108
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: Check die result from eval(someproperty) and return a true/false if a certain die face is rolled

Post by Phergus »

As you found in your other post on the same issue, Wiki: getRolled() returns a JSON array.

You'll want to use Wiki: json.indexOf(), Wiki: json.count() or other functions to check for values.

Post Reply

Return to “Macros”