Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Help with if logic

Hello, So I just upgraded to mentor status and I have absolutely no java experience. I'm hoping someone can help me put something together. I'm hoping to end up with if logic using selected token and selected target that would be a d20 + attack bonus v AC and if hit would roll for damage + weapon bonus and to take it a step further if possible have the damage deduct from the target's HP. Critical hit is max damage, critical miss is half damage dealt back to the attacking token. I know that a combination of the powercards and token mod scripts would get me where I want to be but after looking at this stuff it's become very clear that Java is way over my head. I'm also using a homebrew set of rules that is very basic and I'm not using a typical set of attributes. I also don't need it to look pretty. Thanks in advance for any assistance
1433047519
Gen Kitty
Forum Champion
I'm willing to help you learn how to use Powercards and Tokenmod for this, if you want.
This would actually be much easier to accomplish as a pure api script and not a hacked together powercard/tokenmod combo.
1433060114
Gen Kitty
Forum Champion
Possibly, but the two scripts already exist :>
GenKitty said: Possibly, but the two scripts already exist :> Yeah, but it would be pretty easy to build a script to take that information, do some logic before powercards ever sees it, and then send it through to the PowerCard.process function for output to chat.
1433210770

Edited 1433210911
OK, I'm circling back to this now after a failed attempt at trying to get the group initiative script to work. I'm going to just stick with the initiative marker and roll for monsters individually. Now that I've actually taken the time to read the post for the power cards I see that i will have to set up abilities for the script to call. Will something like this work? It seems to be rolling through but not adding the bonuses and I'm guessing that it's going to say "Hit" no matter what the attack roll is, is it possible to swap out the d8 for a selected token reference like selected|Damage? !power @{selected|token_name} Attempts To Hit @{target|token_name} {{ --Attack|[[1d20 + [selected|Attack Bonus] + [selected|Weapon Bonus]]] vs AC --Hit|[[1d8 + [selected|Damage Bonus] + [selected|Weapon Bonus]]]}} I'd still like to get to the token mod step to automatically deduct the damage but I figure that can wait until I get this to work.
!power {{ --emote|@{selected|token_name} attempts to strike @{target|token_name} --name|Attack --Attack:|[[ 1d20 + @{selected|Attack Bonus} + @{selected|Weapon Bonus} ]] vs AC --Hit:|[[ @{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus} ]] damage }}
1433296019

Edited 1433296301
OK, I'm getting there, !power {{ --emote|@{selected|token_name} attempts to strike @{target|token_name} --name|Attack --Attack:|[[ [$Atk] 1d20 + @{selected|Attack Bonus} + @{selected|Weapon Bonus} ]] vs AC --Hit:|[[ @{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus} ]] damage --?? $Atk.base == 1 ?? !CritFail:|Critical Failure --?? $Atk.total < [[@{target|AC}]] ?? !Miss:|You missed. --?? $Atk.total >= [[@{target|AC}]] AND $Atk base <> 1 AND $Atk base <> 20 ?? Hit:|[[ [NH] d@{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus} --?? $Atk.base == 20 ?? Critical Hit:|[[1*@{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus} }} I installed the powercards 3 script and pieced together the above macro to add conditional logic so it's at least telling me if I hit or miss. Two questions. If the attack roll misses(without being a crit fail, see below), is there a way to just end the macro so it doesn't roll damage at all? Also, if crit hit, it's rolling the damage, is there a way to just take max damage? If crit fail my rules have half damage being dealt back to the attacker. The last item on my wish list is whether or not there's a way to tie in the token mod script to have any applicable damage be deducted from the target's HP. Thanks again for the help.
Remove the --Hit line and use conditionals to show/hide the damage. For crit fail, add some dice rolls there and divide it by two... !power {{ --emote|@{selected|token_name} attempts to strike @{target|token_name} --name|Attack --Attack:|[[ [$Atk] 1d20 + @{selected|Attack Bonus} + @{selected|Weapon Bonus} ]] vs AC --?? $Atk.base == 1 ?? !CritFail:|Critical Failure! [[ floor((1d@{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus})/2) ]] --?? $Atk.total < [[@{target|AC}]] ?? !Miss:|You missed. --?? $Atk.total >= [[@{target|AC}]] AND $Atk base <> 1 AND $Atk base <> 20 ?? Hit:|[[ [NH] 1d@{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus} ]] --?? $Atk.base == 20 ?? Critical Hit:|[[1*@{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus} }}
Thanks, now it's not rolling for damage at all though?
It'll only roll damage if you hit.
yeah, it's not though. It's basically just rolling the attack, if miss it says you missed if hit it's just showing the attack value "vs AC".
Are the last two lines saying if roll value is > = AC and not = 1 and not = 20, Hit and roll and if roll value is = 20 critical hit and roll?
1433298271

Edited 1433302505
Ah, that's because the Atk.base id's in the hit line are wrong... here's the correct version: !power {{ --emote|@{selected|token_name} attempts to strike @{target|token_name} --name|Attack --Attack:|[[ [$Atk] 1d20 + @{selected|Attack Bonus} + @{selected|Weapon Bonus} ]] vs AC --?? $Atk.base == 1 ?? !CritFail:|Critical Failure! [[ floor((1d@{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus})/2) ]] --?? $Atk.total < [[@{target|AC}]] ?? !Miss:|You missed. --?? $Atk.total >= [[@{target|AC}]] AND $Atk.base <> 1 AND $Atk.base <> 20 ?? Hit:|[[ [NH] 1d@{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus} ]] --?? $Atk.base == 20 ?? Critical Hit:|[[1*@{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus} ]] }}
Great, was missing ]] at the end of the critical hit but once I found it it works perfectly now. Thanks.
Cool.
Next question, is there a way to combine the token mod and the script above so that damage done will be automatically reduced? Crit fail would reduce the attacking token's HP/Bar1 value. I tried combining the token mod macro that I saw that would be used to add HP if someone is healed but instead I'm subtracting and using the damage formula above to get the amount. !power {{ --emote|@{selected|token_name} attempts to strike @{target|token_name} --name|Attack --Attack:|[[ [$Atk] 1d20 + @{selected|Attack Bonus} + @{selected|Weapon Bonus} ]] vs AC --?? $Atk.base == 1 ?? !CritFail:|Critical Failure![[!token-mod --set bar1_value|[[{@{selected|bar1} - [[ floor((1d@{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus})/2) ]], @{selected|bar1|Max}d1}kl1]] --ids @{selected|token_id}]] --?? $Atk.total < [[@{target|AC}]] ?? !Miss:|You missed. --?? $Atk.total >= [[@{target|AC}]] AND $Atk.base <> 1 AND $Atk.base <> 20 ?? Hit:|[[!token-mod --set bar1_value|[[{@{target|Target|bar1} - [[ [NH] 1d@{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus}]], @{target|Target|bar1|Max}d1}kl1]] --ids @{target|Target|token_id}]]}} --?? $Atk.base == 20 ?? Critical Hit:|[[!token-mod --set bar1_value|[[{@{target|Target|bar1} - [[1*@{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus}]], @{target|bar1|Max}d1}kl1]] --ids @{target|token_id}]]}} I'm getting an error that says No attribute was found for @{selected|bar1|Max}. Bar 1 is HP which is assigned on the PC's but not assigned on NPC's/mooks. I've tried attacking from either direction and I get the same error. Is what I want to do even possible?
1433360819
The Aaron
Pro
API Scripter
It won't work like that I'm afraid. You can't nest API commands like that. What people have done in the past is separate the two into separate commands, then run power cards with my PCPP front end with some special embedded syntax. I need to check that PCPP still works with PC3.
1433372361

Edited 1433372523
Tristan K. said: I'm getting an error that says No attribute was found for @{selected|bar1|Max}. Bar 1 is HP which is assigned on the PC's but not assigned on NPC's/mooks. I've tried attacking from either direction and I get the same error. Is what I want to do even possible? Use max, not Max. And no, there is currently no way to pass information from powercards to token mod without creating something like what Aaron said.
Gotcha, well the conditional macro is working perfectly with the powercards so that's a huge improvement as far as im concerned. Thanks again for your help
Tristan K. said: Gotcha, well the conditional macro is working perfectly with the powercards so that's a huge improvement as far as im concerned. Thanks again for your help It's a personal thing... I don't like automation in a tabletop rpg setting. Too many ways for too many mistakes to screw up a lot of tokens.
1433377305
Gen Kitty
Forum Champion
HoneyBadger said: It's a personal thing... I don't like automation in a tabletop rpg setting. Too many ways for too many mistakes to screw up a lot of tokens. *high-5s HB* That is one of the things I DISlike about 4e. Soooo many temp bonuses and penalties to keep track of. x.x Conditionals using raw dice rolls, however, are wonderful things!
All of that nonsense is why I'm working on a homebrew system. It's pretty basic in general but my friends and I aren't really able to play all that frequently or for as long each session as when we were kids so I'm hoping that if I can automate as much of the mechanics as possible that we can get more accomplished in game. To each his own I guess.
There's actually another script I wrote called AlterBar that you could integrate into PowerCards easy enough once variables that you can reference are put in.
Great, took a quick look and will play with it a little more tonight but would i nest my damage roll into the alterbar command and then replace that with the damage roll in my conditional macro?
No, it won't work without re-writing parts of the powercard script itself. You'd have to create your own version to combine them.
ah, I see. I guess I'll have to stick with what I have so far until I can take the time to study up on java. Thanks again for your help, this stuff will definitely help speed up my game.
1433459538

Edited 1433464417
Oh man, it just dawned on me that, while API commands sent via sendChat aren't processed as such, sendChat can still generate buttons which can execute commands. I don't know PowerCards well enough to know if this will work, but you might be able to do something like: !power {{ ... --?? $Atk.total >= [[@{target|AC}]] AND $Atk.base <> 1 AND $Atk.base <> 20 ?? Hit:|[Apply Regular Damage](!token-mod ...) --?? $Atk.base == 20 ?? Critical Hit:|[Apply Critical Damage](!token-mod ...) }} If that doesn't work, you could do a similar (but less attractively formatted) thing using ExtendedExpressions (split across multiple lines for clarity, but should all be on one line): !extend Attacking (`(1d20[hitroll]+@{selected|Attack Bonus}+@{selected|Weapon Bonus})[tohit]` vs AC) `"\n"` `(${hitroll} == 1 ? "[Critical Miss for " + ((1d@{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus}) / 2)[fumbdmg] + " Damage](!token-mod --ids @{selected|token_id} --set bar1_value|" + (@{selected|bar1} - ${fumbdmg}) + ")" : (${tohit} < @{target|AC} ? "Miss" : (${hitroll} < 20 ? "[Hit for " + (1d@{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus})[dmg] + " Damage](!token-mod --ids @{target|token_id} --set bar1_value|" + (@{target|bar1} - ${dmg}) + ")" : "[Critical Hit for " + (@{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus})[critdmg] + " Damage](!token-mod --ids @{target|token_id} --set bar1_value|" + (@{target|bar1} - ${critdmg}) + ")")))` (the token-mod part of this isn't tested, but should be pretty close).
1433503500
The Aaron
Pro
API Scripter
Clever!
The only issue I have with the API buttons and it's a big reason and the reason I don't use them at all... you can click them multiple times and they keep executing whatever is assigned to them. There should be a way to make them a once and done.
manveti said: Oh man, it just dawned on me that, while API commands sent via sendChat aren't processed as such, sendChat can still generate buttons which can execute commands. I don't know PowerCards well enough to know if this will work, but you might be able to do something like: !power {{ ... --?? $Atk.total >= [[@{target|AC}]] AND $Atk.base <> 1 AND $Atk.base <> 20 ?? Hit:|[Apply Regular Damage](!token-mod ...) --?? $Atk.base == 20 ?? Critical Hit:|[Apply Critical Damage](!token-mod ...) }} Can't do that at the moment... but when I get around to adding variables you can reference in other parts of the power card... this is something you will definitely be able to do.
I meant to try this last night but I needed to do some story work for this weekend's game. I'm going to give it a try tonight, would I first install the extended expressions script and then use the !extend macro that manveti posted above as is? I read something on the extended expressions post about using command shell but it looks like the newer version of extended expressions has addressed the issue.
Actually, Aaron could probably add a new option to TokenMod that could look for the Roll ID's if the Rolls object was passed to TokenMod.
1433511926
The Aaron
Pro
API Scripter
HoneyBadger said: Actually, Aaron could probably add a new option to TokenMod that could look for the Roll ID's if the Rolls object was passed to TokenMod. You're talking about the one and done problem? I was considering adding a parameter where you could pass an identifier and ignore commands that are issued again with the same identifier (& player). Could use the current time stamp for it pretty easily. In the beta of the API buttons, it would trash all the HTML inside a button. I had a proof of concept that made a button, and the button disappeared after being clicked. :). Something like that or where it could be disabled after first fire would be cool.
The Aaron said: HoneyBadger said: Actually, Aaron could probably add a new option to TokenMod that could look for the Roll ID's if the Rolls object was passed to TokenMod. You're talking about the one and done problem? I was considering adding a parameter where you could pass an identifier and ignore commands that are issued again with the same identifier (& player). Could use the current time stamp for it pretty easily. In the beta of the API buttons, it would trash all the HTML inside a button. I had a proof of concept that made a button, and the button disappeared after being clicked. :). Something like that or where it could be disabled after first fire would be cool. Both actually... in PowerCards, all the rolls with [$ID] as a label get stored in a separate object called Rolls. This could easily be passed to token mod.
Tristan K. said: I meant to try this last night but I needed to do some story work for this weekend's game. I'm going to give it a try tonight, would I first install the extended expressions script and then use the !extend macro that manveti posted above as is? I read something on the extended expressions post about using command shell but it looks like the newer version of extended expressions has addressed the issue. Yep (although I didn't test the !token-mod part, so I can't promise the buttons that command generates will work as-is). ExtendedExpressions doesn't require CommandShell (there was a bug early on that broke the non-CommandShell pathway, but that got fixed), but it is still recommended.
If that doesn't work, you could do a similar (but less attractively formatted) thing using ExtendedExpressions (split across multiple lines for clarity, but should all be on one line): !extend Attacking (`(1d20[hitroll]+@{selected|Attack Bonus}+@{selected|Weapon Bonus})[tohit]` vs AC) `"\n"` `(${hitroll} == 1 ? "[Critical Miss for " + ((1d@{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus}) / 2)[fumbdmg] + " Damage](!token-mod --ids @{selected|token_id} --set bar1_value|" + (@{selected|bar1} - ${fumbdmg}) + ")" : (${tohit} < @{target|AC} ? "Miss" : (${hitroll} < 20 ? "[Hit for " + (1d@{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus})[dmg] + " Damage](!token-mod --ids @{target|token_id} --set bar1_value|" + (@{target|bar1} - ${dmg}) + ")" : "[Critical Hit for " + (@{selected|Damage} + @{selected|Damage Bonus} + @{selected|Weapon Bonus})[critdmg] + " Damage](!token-mod --ids @{target|token_id} --set bar1_value|" + (@{target|bar1} - ${critdmg}) + ")")))` (the token-mod part of this isn't tested, but should be pretty close). copied the extended expressions script and the macro above, getting an error that says "(From ExExp): Error: Unrecognized token: s" any suggestions? Thanks again.
Are any of the referenced attributes (Attack Bonus, AC, Damage, Damage Bonus, Weapon Bonus) non-numeric? The error message is saying that there's an 's' (or possibly a word beginning with 's') somewhere it expects a number, operator, or some other expression component. I can look into keeping track of where we are in the expression when parsing it to better pinpoint the location of detected errors. In the meantime, you can get a bit more detail by adding s.s.split(" ", 1)[0] onto the end of the error message on line 220: return "Error: Unrecognized token: " + s.tok.text + s.s.split(" ", 1)[0] ;
1433556546

Edited 1433556564
Nope, everything is numeric, I added that and now it's saying unrecognized token "selected|Damage". Is it likely because the { s elected|Damage}? Is there another way to write that into the macro?
That's consistent with the selected token either not having an associated character or that character not having a "Damage" attribute. If you select the relevant token and enter "@{selected|Damage}" into the chat, you'll probably get a message saying either "No character was found for 'selected'" or "No attribute was found for @{selected|Damage}", followed by a "selected|Damage" line coming from you as if you had left off the "@{" and "}".
1433558571

Edited 1433558585
nope, I get the value, 12
Just to see what would happen I just went in and replaced all of the "@{selected|Damage}" with 1d12 and it's still giving me the same error.
That could also be the "Damage Bonus" attribute. The ".split(" ", 1)[0]" part means "just the part up to the first space"; deleting that part (so you're just adding s.s) will make the error message give you the whole tail of the command. But either "Damage" or "Damage Bonus" isn't making it through. For reference, I've been testing with two characters: Attacker (selected): (unlinked) Bar 1: 42 Attack Bonus: 5 AC: 18 Damage: 8 Damage Bonus: 3 Weapon Bonus: 2 Defender (target): (unlinked) Bar 1: 26 Attack Bonus: 3 AC: 15 Damage: 6 Damage Bonus: 2 Weapon Bonus: 1 (I'm sure those numbers aren't necessarily meaningful, but all that really matters is that they're all numbers). Using those characters, and copying in the command from your quote above (pasting in each line, then adding a space before pasting in the next line, and so on) gives results like: Attacking ([24] vs AC) [Hit for 6 Damage](!token-mod --ids -Jp3ingl4K220I6Otx3S --set bar1_value|20)
Ill check my spacing and see what happens
got it, i thought that I had read somewhere that there was a way to get the button to go away once you clicked on it, is that correct and can you point me in that direction.
this is working great, thanks guys
just noticed that when rolling if i don't select the target after the damage roll and I click on the damage button, it deducts from both attacker and target, if i select the target and then click the button it only deducts from the target as desired. either way, still awesome
1433639997
The Aaron
Pro
API Scripter
TokenMod applies it's commands to both the selected and any specified tokens. I realized this might not be intended while working on CharMod the other day. I plan to add an option to ignore selected.
Gotcha, well we're playing now and it's working pretty great anyway.
1433648986
The Aaron
Pro
API Scripter
Good deal! =D
Yup, it worked really well for the most part, a couple of times it seemed to deduct the wrong value and a couple of times it actually added back a value but all in all everything was great . Between the initiative marker and even just using the conditional macro and manually applying the damage it was great, thanks for the help