Setting up an Auto-Hit Crit detecting Macro

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
Ghosty
Kobold
Posts: 1
Joined: Tue Jun 25, 2019 11:57 am

Setting up an Auto-Hit Crit detecting Macro

Post by Ghosty »

So I've been putting together a macro that when used, brings up a list of targets in range, and rolls the stored values of the token and macro itself to run against the numbers of the target token. I've got it to where it rolls the attack roll, tells me if it hits or not, and deals damage reduced by it's DR (Damred in the macro) I want to implement the detection, rolling and application of crit roll and damage if the crit roll is successful.

Code: Select all

<b>Heavy Crossbow</b> <br>
[h: ROLL=1d20]
[h: MAGIC=2]
[h: BONUS=Atk1+DexMod+1]
[h: Tohit=ROLL+MAGIC+BONUS]
[h: CROLL1=1d20+BONUS+MAGIC]
[h:CRIT1 = if(ROLL==20, 1,0 )]
[h: P1=d(1,Pierce)]
[h: DAM1=P1+STAT+MAGIC]
[h:CritDam= Dam1*3]
[h: cond = '{ range: {upto:60, distancePerCell:0}, npc:1, visible:1, unsetStates:["Dead"] }']
[h: ids = getTokens("json", cond)]
[H: filtered = "[]"]
[H: inputList = "[]"]
[H: source = currentToken()]
[H, foreach(id,ids), code: {
   [H: canSee = canSeeToken(id,source)]
   [H, token(id), if(! json.isEmpty(canSee)), code: {
      [H: name = getName()]
      [H: distance = getDistance(id,1,source)]
      [H: filtered = json.append(filtered,name)]
      [H: inputList = json.append(inputList,strformat('<html><table><tr><td width="10px">&nbsp;</td><td><img src="%s" height="50" width="50" /></td><td style="text-align:center"><b>Distance</b><h1>%{distance}</h1></td></tr><tr><td>&nbsp;</td><td colspan="2" style="color:yellow;background-color:blue;text-align:center"><b>%s</b></td></tr></table></html>',getImage(name),replace(getName(),",","&#44;")))]
   };{}]   
}]
[H: ids = filtered]
[H, if(json.length(ids)), code: {
   [h: hasInput = input("index|"+json.toList(inputList)+"|<html><b>Target Nearby NPC</b></html>|LIST") ]
   [h, if(hasInput): currentTarget = json.get(ids, index); currentTarget = "" ]
};{
   [H: currentTarget = ""]
}]
[H: Target = currentTarget] 
[h: switchToken (Target) ]
[h:attackRoll = tohit]
[h:targetNumber = Armorclass]
[h,if(attackRoll >= targetNumber), code:
{
  [attackUsed = "yes"]
  [attackResult = "hits"]
  [damageRoll = Dam1]
};
{
  [attackUsed = "yes"]
  [attackResult = "misses"]
  [damageRoll = 0]
}]
<b>Attack Roll:</b> [r:ROLL]+[r:Bonus]=[r:Tohit] <b>{AttackResult}</b>
[r:if(Crit1==1,"<b>Crit Confirm:</B>"+Croll1,"")]<br>
[r, if(AttackResult=="hits"): output = strformat("<b>Damage: </b>%{Damageroll}<br> <b>Target:</b> %{Target}!"); output = "")]
[h: Dam = damageRoll]<br>
[h: Red = Dam - DamRed]
[h: Red = if ((Red) < 0,0, Red)]
[h: Health = Health - Red]
[h: Health = if ((Health) > HPMax, HPMax, Health)]
[h: Mortal = if((Health) <= -1,1,0)] 
[h: Staggered = if ((Health) == 0,1,0)]
[h: IsDead = if((Health) <= (-Constitution),1, 0)]
[h: Mortal = if((IsDead) >=1,0,Mortal)]
[h: state.Unconscious = Mortal]
[h: state.Dying = Mortal]
[h: state.Staggered = Staggered]
[h: state.Dead = IsDead]
Last edited by aliasmask on Tue Jun 25, 2019 12:55 pm, edited 1 time in total.
Reason: added code tags

Post Reply

Return to “Macros”