Context for this snipit(pusudo code): takes the existing inventory Array and extrapolatethe the item name and the range for each item.
(4th line of code is being used for troubleshooting, why i know that testing range equals 1) Then, test range's data-type and if it is an array the code will create a maximum and minimum value based off of the ranges 0 and 1 indexs.
Code: Select all
[foreach(item,inventory_list,""), CODE:{
[h: name = json.get(item,0)]
[h: range = json.get(item,11)]
[h: setLibProperty("nothing",json.type(range) == "ARRAY","Lib:LibDummy")]
[r, if(json.type(range) == "ARRAY"), CODE:
{
not_used_range = json.get(range,0)
range = json.get(range,0)
min_range = json.get(not_used_range,0)
max_range = json.get(not_used_range,1)
setLibProperty("nothing","worked","Lib:LibDummy")
};{setLibProperty("nothing","Not array","Lib:LibDummy")}]
[r,if(isNumber(range)):range = number(range);range = 0]
[h,if(json.get(item,0) == name && json.get(item,1 ) == "Weapon"), CODE:{
[h: item_count = item_count + 1]
[inventory_name_list = json.append(inventory_name_list,name)]
[h: attack_equipt = json.append(attack_equipt,item)]
};{}]
}]
Here is the full code for the script if anyone is bold enough to read through my terrible writtings. Thank you in advance for any insight and help you can provide.
Code: Select all
[h: STR=floor((Strength-10)/2)]
[h: DEX=floor((Dexterity-10)/2)]
[h: CON=floor((Constitution-10)/2)]
[h: INT=floor((intelligence-10)/2)]
[h: WIS=floor((Wisdom-10)/2)]
[h: CHA=floor((Charisma-10)/2)]
[h: WeaponName = "weaponname"]
[h: WeaponDamage = "1"]
[h: damage_type = "damagetype"]
[h: Ability = STR]
[h: min_range = 0]
[h: max_range = 0]
[h: "<----------------------------------------- Select Existing Inventory Item ------------------------------------------>"]
[h: attack_equipt = json.fromList("")]
[h: inventory_list = Inventory]
[h: inventory_name_list = json.fromList("")]
[h: new_inventory_list = json.fromList("")]
[h: delete_list_item_index = -1]
[h: item_count = 0]
[foreach(item,inventory_list,""), CODE:{
[h: name = json.get(item,0)]
[h: range = json.get(item,11)]
[h: setLibProperty("nothing",json.type(range) == "ARRAY","Lib:LibDummy")]
[r, if(json.type(range) == 1), CODE:
{
not_used_range = json.get(range,0)
range = json.get(range,0)
min_range = json.get(not_used_range,0)
max_range = json.get(not_used_range,1)
setLibProperty("nothing","worked","Lib:LibDummy")
};{setLibProperty("nothing","Not array","Lib:LibDummy")}]
[r,if(isNumber(range)):range = number(range);range = 0]
[h,if(json.get(item,0) == name && json.get(item,1 ) == "Weapon"), CODE:{
[h: item_count = item_count + 1]
[inventory_name_list = json.append(inventory_name_list,name)]
[h: attack_equipt = json.append(attack_equipt,item)]
};{}]
}]
[h: attack_equipt = setProperty("AttackEquipt",attack_equipt)]
[h: take=input("selected_item|"+inventory_name_list+"|Choose Weapon|LIST|SELECT=0")]
[h: abort(take)]
[foreach(item,AttackEquipt,""), CODE:{
[h: delete_list_item_index = delete_list_item_index + 1]
[r,if(delete_list_item_index == selected_item), CODE:
{
[h: WeaponName = json.get(item,0)]
[h: WeaponDamage = json.get(item,4)]
[h: damage_type = json.get(item,5)]
[h: Ability = json.get(item,6)]
[h: "-------------- Range in squares(1 = 5ft. 2 = 10ft. 3 = 15ft is right next to) -----------------"]
[h:range = max_range]
};{}]
[r, if(selected_item == 0), CODE:
{
[h: WeaponName = "Pebble"]
[h: WeaponDamage = 1]
[h: damage_type = "Bludgeoning"]
[h: Ability = STR]
};{}]
}]
[h: "---------------------------------------------------- weapon atribute sorting ----------------------------------------------------"]
[h: WeaponDamage_test = strfind(WeaponDamage,",")]
[h: WeaponDamage_test = getFindCount(WeaponDamage_test)]
[r: WeaponName]
[h, if(WeaponDamage_test == 1), CODE:
{
[h: x = input("two_hand|0|Are You Two Handing?|CHECK")]
[h: abort(x)]
[h, if(two_hand == 1):WeaponDamage = json.get(WeaponDamage,1);WeaponDamage = json.get(WeaponDamage,0)]
};{}]
[h:WeaponDamage = "[r:"+WeaponDamage+"]"]
[h:WeaponDamage = json.evaluate(WeaponDamage)]
[h:WeaponDamage = json.get(WeaponDamage,0)]
[h, if(Ability == "Strength"): Ability = STR;""]
[h, if(Ability == "Dexterity"): Ability = DEX;""]
[h, if(Ability == "Constitution"): Ability = CON;""]
[h, if(Ability == "intelligence"): Ability = INT;""]
[h, if(Ability == "Wisdom"): Ability = WIS;""]
[h, if(Ability == "Charisma"): Ability = CHA;""]
[h: "<----------------------------------------- Selection based on auto sorted list- ----------------------------------------->"]
[h:macro_clicked = "Template Melee Attack"]
[h: token_list = getLibProperty("TokenCombatList", "Lib:Battle")]
[h:attack_selection = json.fromList("")]
[h:id_list = json.fromList("")]
[h: attacker = getSelected()]
[h: target_ac = ""]
[h,foreach(token_single, token_list), code:
{
[h: id = json.get(token_single,0)]
[h: name = json.get(token_single,2)]
[h: image = json.get(token_single,1)]
[h: show = name+image+id]
[h: distance = getDistance(attacker, 0, id)]
[h,if(distance <= range && id != attacker): attack_selection = json.append(attack_selection,show);""]
[h: show = json.fromList(show)]
[h,if(distance <= range && id != attacker): id_list = json.append(id_list, id)]
}]
[h: continue_attack=input("junkVar|"+macro_clicked+"|Selected Power|LABEL",
"targetNum|"+attack_selection+"|Select Target|LIST|SELECT=0 ICON=TRUE ICONSIZE=70")]
[h: abort(continue_attack)]
[h: "<!- Selection based on auto sorted list- -->"]
[h:iteration = 0]
[h,foreach(token_single, id_list), code:
{
[h,if(targetNum == iteration): target_id = json.get(id_list,iteration);""]
[h:iteration = iteration + 1]
}]
[h: "<----------------------------------------- Selection based on auto sorted list- ----------------------------------------->"]
[h,foreach(token_single, token_list), code:
{
[h: unknown_target_id = json.get(token_single,0)]
[h,if(unknown_target_id == target_id): target_ac = json.get(token_single,6);""]
}]
[h:"-----------------HighLighting a single Token-----------------"]
[h:setHalo("Red", target_id)]
[h: show_distance = getDistance(attacker, 1, target_id)]]
[h:continue = input("junkVar|Target is: "+show_distance+"ft away|Selected Power|LABEL")]
[h,if(continue == 1): setHalo("None", target_id);setHalo("None", target_id)]
[h:abort(continue)]
[h:setLibProperty("SingleTokenDamageId",target_id, "Lib:Battle")]
[h:"----------------------------------------------------------The First D20 Roll----------------------------------------------------------"]
[h: Dice1 = 1d20]
[h: Dice2 = 0]
[h: Dice3 = 0]
[h: Dice = Dice1]
[h:"------------------------------------------Calling AttackAided for aided macanic calculations------------------------------------------"]
[r,if(Aided != 0), CODE:{
[macro("AttackAided@Lib:Battle"):""]
[h: Dice2 = getLibProperty("ThirdDiceResult","Lib:Attack")]
[h: Dice2 = number(Dice2)]
[h, if(Aided == 1 && Dice1 >= Dice2), CODE:
{
[h: Dice = Dice1]
[h: Dice3 = Dice2]
[h:Aided = 0]
};{
[h: Dice = Dice2]
[h: Dice3 = Dice1]
[h:Aided = 0]
}]
[h, if(Aided == -1 && Dice1 >= Dice2), CODE:
{
[h: Dice = Dice2]
[h: Dice3 = Dice1]
[h:Aided = 0]
};{
[h: Dice = Dice1]
[h: Dice3 = Dice2]
[h:Aided = 0]
}]
};{}]
[h:"------------------------------------------Calling TargetDodge for Dodge macanic calculations------------------------------------------"]
[h: target_dodge = getProperty("Dodge",target_id)]
[r,if(target_dodge != 0), CODE:{
[macro("TargetDodge@Lib:Battle"):""]
[h: Dice2 = getLibProperty("ThirdDiceResult","Lib:Attack")]
[h: Dice2 = number(Dice2)]
[r:Dice1]
[r:Dice2]
[r, if(target_dodge == 1 && Dice1 >= Dice2), CODE:
{
[r:"ran Dice = Dice2"]
[h: Dice = Dice2]
[h: Dice3 = Dice1]
};{
[r:"ran Dice = Dice1"]
[h: Dice = Dice1]
[h: Dice3 = Dice2]
}]
};{}]
[h:"-------------------------------------------------------------------------------------------------------------------------------------"]
[h:setLibProperty("SecondDiceResult",Dice3,"Lib:Attack")]
[h: CRIT = 1]
<!-->------ Only thing to change ------<-->
[h:"<---------------------------------------------------------------------------------------------------------------------------------------------->"]
[h:"<---------------------------------------------------------------------------------------------------------------------------------------------->"]
[h:"<---------------------------------------------------------------------------------------------------------------------------------------------->"]
[h:"<---------------------------------------------------------------------------------------------------------------------------------------------->"]
[h:"<---------------------------------------------------------------------------------------------------------------------------------------------->"]
[h: AttackBonus = Ability + Proficiency_Bonus]
[h: CRIT = if(Dice == 20, 2,1)]
[h:setLibProperty("SingleTokenDamageValue",WeaponDamage + Ability, "Lib:Battle")]
[h:"<---------------------------------------------------------------------------------------------------------------------------------------------->"]
[h:"<---------------------------------------------------------------------------------------------------------------------------------------------->"]
[h:"<---------------------------------------------------------------------------------------------------------------------------------------------->"]
[h: setLibProperty("Crit", CRIT,"Lib:Attack")]
[h: setLibProperty("AttackRoll", Dice,"Lib:Attack")]
[h: setLibProperty("AttackBonus", AttackBonus,"Lib:Attack")]
[h: setLibProperty("TargetAC", target_ac,"Lib:Attack")]
[h: setLibProperty("DamageRoll",WeaponDamage, "Lib:Attack")]
[h: setLibProperty("DamageBonus",Ability, "Lib:Attack")]
[h:setLibProperty("SingleTokenDamageType", damage_type, "Lib:Battle")]
[h: WeaponDamage = WeaponDamage * CRIT]
<br>
<!-- MUST NOT BE SUFFERING A CONDITION THAT PREVENTS AN ACTION BEING USED, OTHERWISE MOVE ON TO NEXT CONDITION. -->
[r, if(Incapacitated == 0 && Dead == 0 && Petrified == 0 && Stunned == 0 && Unconscious_Normal == 0 && Unconscious_Dying == 0), CODE: {
<!-- Output battle texts as long as Actions are > 0 and AttacksAvaliable is -->
[r,if(AttacksAvaliable > 0 || Actions > 0 ), CODE:{
<b>Roll 1</b>: [r:Dice] + [r:AttackBonus] = [r:Dice + AttackBonus] To Hit<br>
[macro("AttackAidedSecondRoll@Lib:Battle"):""]
[h:setLibProperty("SecondRoll",0,"Lib:Attack")]
[h:AttacksAvaliable = AttacksAvaliable - 1]
[h:Actions = 0]
[macro("AttackDamage@lib:Battle"):""]
};{
"You Have No More Attacks Left"
}]
};{
"Your Condition Prevents You from Attacking or No Targets in range"
}]