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"> </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> </td><td colspan="2" style="color:yellow;background-color:blue;text-align:center"><b>%s</b></td></tr></table></html>',getImage(name),replace(getName(),",",",")))]
};{}]
}]
[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]