Modfiy to add advantage/disadvantage

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

dorpond
RPTools Team
Posts: 5530
Joined: Thu Jun 01, 2006 2:05 pm
Location: Buffalo, NY

Modfiy to add advantage/disadvantage

Post by dorpond »

Hey team, it has been a long while since I revisited making macros, but I have this macro that I need help modifying.

The macro works fine as is - it simply asks what the save value is, and then allows you to pick the save you wish to roll. It support token multiselect so I can select many of my monsters and voila, at a glance I can see who failed by the state change (which later goes away when I apply the damage on those tokens via a different macro).

Where this doesn't work is when I need to roll on advantage or disadvantage. For those who are not familiar with those rules, rolling at advantage allows me to roll twice and take the highest value, and disadvantage I roll twice and take the lowest value.

Sometimes my monsters have to roll at advantage or disadvantage, and there lies my issue: my current macro doesn't suffice.

So could someone help me write it so that it allows me to specify if the roll has advantage/disadvantage, and execute the code accordingly?

This is way beyond my coding ability, I must admit :(

Code: Select all

/self

[h: abort(input("DC |0| What is the DC? | TEXT"))]

[h:saveList = "STR Save, DEX Save, CON Save, INT Save, WIS Save, CHR Save"]

[h:status=input(
"listType|"+saveList+"|What save to do you want to roll?|RADIO|SELECT=0 VALUE=STRING" )]
[h:abort(status)]

[h: tokenList = getSelected()]
[foreach(tokenID, tokenList, ""), CODE: {
   [h: switchToken(tokenID)]

[h,switch(listType),CODE:

    case "STR Save":
{
 [h:d20roll = 1d20]
 [h:saveValue = StrSave]
};

    case "DEX Save":
{
 [h:d20roll = 1d20]
 [h:saveValue = DexSave]
};

    case "CON Save":
{
 [h:d20roll = 1d20]
 [h:saveValue = ConSave]
};

    case "INT Save":
{
 [h:d20roll = 1d20]
 [h:saveValue = IntSave]
};

    case "WIS Save":
{
 [h:d20roll = 1d20]
 [h:saveValue = WisSave]
};

    case "CHR Save":
{
 [h:d20roll = 1d20]
 [h:saveValue = ChrSave]
};]

[H, if(d20roll+saveValue < DC): state.DCFail = 1]

[r:token.name] makes a [r:listType] and gets a [t:d20roll+saveValue].<BR>

}]

How to use my bundled artwork (MT1.3B60+): http://forums.rptools.net/viewtopic.php?f=8&t=11759

User avatar
Xaelvaen
Dragon
Posts: 498
Joined: Wed Aug 31, 2011 9:49 pm
Location: Somewhere between Heaven and Hell

Re: Modfiy to add advantage/disadvantage

Post by Xaelvaen »

Code: Select all

/self

[h: abort(input("DC |0| What is the DC? | TEXT"))]

[h:saveList = "STR Save, DEX Save, CON Save, INT Save, WIS Save, CHR Save"]
[h: advantageList="Advantage,Normal,Disadvantage"]

[h:status=input(
"listType|"+saveList+"|What save to do you want to roll?|RADIO|SELECT=0 VALUE=STRING",
"setAdvantage|" +advantageList +"|Advantage?|RADIO| ORIENT=H SELECT=1" )]
[h:abort(status)]

[h: tokenList = getSelected()]
[foreach(tokenID, tokenList, ""), CODE: {
   [h: switchToken(tokenID)]



[h,switch(listType),CODE:

    case "STR Save":
{
[h: normald20roll=1d20]
[h: advantaged20roll=keep(2,20,1)]
[h: droll=1d20]
[h: disadvantaged20roll=min(normald20roll,droll)]
 [h:d20roll = if(setAdvantage==0,advantaged20roll,if(setAdvantage==2,disadvantaged20roll,normald20roll))]
 [h:saveValue = StrSave]
};

    case "DEX Save":
{
[h: normald20roll=1d20]
[h: advantaged20roll=keep(2,20,1)]
[h: droll=1d20]
[h: disadvantaged20roll=min(normald20roll,droll)]
 [h:d20roll = if(setAdvantage==0,advantaged20roll,if(setAdvantage==2,disadvantaged20roll,normald20roll))]
 [h:saveValue = DexSave]
};

    case "CON Save":
{
[h: normald20roll=1d20]
[h: advantaged20roll=keep(2,20,1)]
[h: droll=1d20]
[h: disadvantaged20roll=min(normald20roll,droll)]
 [h:d20roll = if(setAdvantage==0,advantaged20roll,if(setAdvantage==2,disadvantaged20roll,normald20roll))]
 [h:saveValue = ConSave]
};

    case "INT Save":
{
[h: normald20roll=1d20]
[h: advantaged20roll=keep(2,20,1)]
[h: droll=1d20]
[h: disadvantaged20roll=min(normald20roll,droll)]
 [h:d20roll = if(setAdvantage==0,advantaged20roll,if(setAdvantage==2,disadvantaged20roll,normald20roll))]
 [h:saveValue = IntSave]
};

    case "WIS Save":
{
[h: normald20roll=1d20]
[h: advantaged20roll=keep(2,20,1)]
[h: droll=1d20]
[h: disadvantaged20roll=min(normald20roll,droll)]
 [h:d20roll = if(setAdvantage==0,advantaged20roll,if(setAdvantage==2,disadvantaged20roll,normald20roll))]
 [h:saveValue = WisSave]
};

    case "CHR Save":
{
[h: normald20roll=1d20]
[h: advantaged20roll=keep(2,20,1)]
[h: droll=1d20]
[h: disadvantaged20roll=min(normald20roll,droll)]
 [h:d20roll = if(setAdvantage==0,advantaged20roll,if(setAdvantage==2,disadvantaged20roll,normald20roll))]
 [h:saveValue = ChrSave]
};]

[H, if(d20roll+saveValue < DC): state.DCFail = 1]

[r:token.name] makes a [r:listType] and gets a [t:d20roll+saveValue].<BR>

}]


Untested, but that should do the trick.
"An arrogant person considers himself perfect. This is the chief harm of arrogance. It interferes with a person's main task in life - becoming a better person." - Leo Tolstoy

dorpond
RPTools Team
Posts: 5530
Joined: Thu Jun 01, 2006 2:05 pm
Location: Buffalo, NY

Re: Modfiy to add advantage/disadvantage

Post by dorpond »

Thank you so much!

I tested it out, but I get this:
line 1:2: unexpected char: '['

I looked through all the code but I have no idea what it is upset with. Any ideas?

Thanks again

[edit]
FYI, I get the first question of DC, and then I get the Save Option Screen in addition to the radio buttons on the bottom, but no matter what I pick, I get that result above.
How to use my bundled artwork (MT1.3B60+): http://forums.rptools.net/viewtopic.php?f=8&t=11759

User avatar
aliasmask
Deity
Posts: 8624
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Modfiy to add advantage/disadvantage

Post by aliasmask »

I would do it slightly different and simplify it. Code to follow.

Code: Select all

<!-- set some basic values -->
[
H: saveDC = 0]
[
H: tokenList = getSelected()]
[
H: statNameList = "STR,DEX,CON,INT,WIS,CHR"]
[
H: advantageColorCode = "black,blue,red"]
[
H: output = ""]

<!--
 get user input -->
[
H: abort(input("saveDC|0|Enter Save DC|TEXT",
    "rollAdvantage|No Advantage,Advantage,Disadvantage|Select Advantage|RADIO|ORIENT=H",
    strformat("statName|%{statNameList}|Choose Stat Save|RADIO|VALUE=STRING"),
    "outputType|All,Self,GM|Output to Who?|RADIO|SELECT=1 ORIENT=H"
))]

<!--
 get token data, rolls and saving throw modifier -->
[
H, foreach(tokenId,tokenList), code: {
    [H: switchToken(tokenId)]
    
    
<!-- get advantage roll -->
    [H: saveRoll = 1d20]
    [H, if(rollAdvantage == 1): saveRoll = max(1d20,saveRoll)]
    [H, if(rollAdvantage == 2): saveRoll = min(1d20,saveRoll)]
    
    
<!-- get token stat save roll modifier. note: token name is not case sensitive -->
    [H: statModifier = getProperty(statName+"Save")]
    
    
<!-- calc total -->
    [H: rollTotal = statModifier + saveRoll]
    [H: rollColor = listGet(advantageColorCode,rollAdvantage)]
    
    
<!-- set state DCFail value. Probably shouldnt do it here, but its easier -->
    [H, if(rollTotal < saveDC): state.DCFail = 1; state.DCFail = 0]
    
    
<!-- save output for each token -->
    [H: output = json.append(output,strformat('%{token.name} makes a %{statName} Save and gets a <span title="Roll: %{saveRoll}; Mod: %{statModifier}"><b color="%{rollColor}">%{rollTotal}</b></span>.'))]
}]

<!--
 Display Output -->
[
H: broadcast(json.toList(output,"<BR>"),outputType)]

<!--
 you can remove this line if you make a function of this with hidden output, or you can remove all the comments for final macro -->
[
H: abort(0)] 

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

Re: Modfiy to add advantage/disadvantage

Post by wolph42 »

@AM: the broadcast types 'self' and 'all' don't exist (they should, but don't). Only 'gm' exists, so the broadcast will fail on test (=no output).

@Dorpond: IF you use the BoT you can (in AMs code) replace the following lines in his code:

Code: Select all

"outputType|All,Self,GM|Output to Who?|RADIO|SELECT=1 ORIENT=H"
for this one:
"outputType|all,self,gm|Output to Who?|RADIO|SELECT=1 ORIENT=H"
(so lower case)
 

and

Code: Select all

[H: broadcast(json.toList(output,"<BR>"),outputType)]
for this one
[H: broadcast(json.toList(output,"<BR>"),eval("bot_"+outputType+"()"))]
 

dorpond
RPTools Team
Posts: 5530
Joined: Thu Jun 01, 2006 2:05 pm
Location: Buffalo, NY

Re: Modfiy to add advantage/disadvantage

Post by dorpond »

@Wolph42, no I'm not using BoT; I'm using a framework that I made in the old days and have just been tweaking it as new edition rules have been released. I have a game tonight and I was hoping to have a better working macro than what I currently have. This seems more complicated than I hoped though...

@Aliasmask, thanks for putting the time into this! I tried it though and I get this: line 1:1: unexpected char: 0xA0

Guys, call me an idiot here, but when it says Line 1:1, how does that help me exactly? Where is 1:1? I am not a coder so what does <Value>:<Value> actually mean?

Also, not sure if this makes or breaks this conversation a little, but I am using Jamz branch 1.4.3.20

Thanks again, team!
How to use my bundled artwork (MT1.3B60+): http://forums.rptools.net/viewtopic.php?f=8&t=11759

User avatar
aliasmask
Deity
Posts: 8624
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Modfiy to add advantage/disadvantage

Post by aliasmask »

dorpond wrote:@Aliasmask, thanks for putting the time into this! I tried it though and I get this: line 1:1: unexpected char: 0xA0


This is a cut/paste error having to do with copying the code from the forum. I'll see about attaching a text file. Let me know if you have the same problem with the text file.

wolph42 wrote:@AM: the broadcast types 'self' and 'all' don't exist (they should, but don't). Only 'gm' exists, so the broadcast will fail on test (=no output).

When I wrote that I wondered about that. Also, with my code I have my own special output where those are also valid along with "owner" and "others". If he already has BoT then that's a good solution. If not, he can add my "starter lib token" and use this line of code:

Code: Select all

<!-- Display Output -->
[H: xx.lib.output.basic(json.toList(output,"<BR>"),outputType)]


There's other good stuff on that token and is worth a look at for those wanting to start coding. It's all in the comments and notes of token. Like with all lib tokens, you have to either save and restart campaign or go to token and click onCampaignLoad to get the function to work. This only needs to be done once when first dropped on to map.

edit: Fixed type-o in the starter lib that would cause an error if using the "self" option. Re-uploaded file.
Attachments
starter lib token.rptok
(168.82 KiB) Downloaded 31 times
dorpond adv roll.txt
(1.74 KiB) Downloaded 35 times

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

Re: Modfiy to add advantage/disadvantage

Post by wolph42 »

well, installing the bot is now as simple as dragging two tokens onto a map; save reload and hitting OK 2 times.
But I see that AM has already provided you with what you need for this function.

but when it says Line 1:1, how does that help me exactly? Where is 1:1? I am not a coder so what does <Value>:<Value> actually mean?


basically it means: in your code the first line and of the first line the first character. So Line 5:3 means 5th line 3rd character. 1:1 is thus the first characer it encounters (and as AM mentioned this is an illegal character that you inadvertantly c/p from the forum.

dorpond
RPTools Team
Posts: 5530
Joined: Thu Jun 01, 2006 2:05 pm
Location: Buffalo, NY

Re: Modfiy to add advantage/disadvantage

Post by dorpond »

wolph42 wrote: basically it means: in your code the first line and of the first line the first character. So Line 5:3 means 5th line 3rd character. 1:1 is thus the first characer it encounters (and as AM mentioned this is an illegal character that you inadvertantly c/p from the forum.


So that copy/paste could be plaguing the code I got from Xaelvaen too? His code was complaining about 1:2 and on line one, all I have is /self in that line.

So is there a right way to copy and paste forum code them for future reference? Can I paste it into notepad first and then copy that and paste it into the macro?
How to use my bundled artwork (MT1.3B60+): http://forums.rptools.net/viewtopic.php?f=8&t=11759

User avatar
aliasmask
Deity
Posts: 8624
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Modfiy to add advantage/disadvantage

Post by aliasmask »

I use notepad++ to type my code which has a feature to show all the characters including the CR LF characters. I was able to get a clean copy/paste by using the "select" link above the code (using the envision board style) but that has stopped working awhile ago. I'm not sure how code shows up for other styles.

dorpond
RPTools Team
Posts: 5530
Joined: Thu Jun 01, 2006 2:05 pm
Location: Buffalo, NY

Re: Modfiy to add advantage/disadvantage

Post by dorpond »

I guess I am confused. I took Xaelvaen's code and as a test, remove line 1 altogether, because it was Maptool was complaining about line 1:2: unexpected char: '['

My line 1 was /self - so now it is nuked completely, but yet when I run the moacro, I still get line 1:2: unexpected char: '['

I am confused. :P

So I took that code and copied it into Notepad++ to see if there was anything inside the code I couldn't see, but there is nothing in line 1 that remotely has a '[' character in it.

I feel like I am in Noob 101 class :)
How to use my bundled artwork (MT1.3B60+): http://forums.rptools.net/viewtopic.php?f=8&t=11759

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

Re: Modfiy to add advantage/disadvantage

Post by wolph42 »

i checked xaelvan's code and although its a bit messy, there's nothing wrong with it.
Note by the way, that the line 1:2 does reflect on the script however its rendered by java after it went through the parser, so I'm not sure there is much coherence between the error mesage and the script as you perceive it. I usually ignore such messages and simply debug. (to do that read debug article linked in sig.).

User avatar
aliasmask
Deity
Posts: 8624
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Modfiy to add advantage/disadvantage

Post by aliasmask »

If you use /self it has to be the very first line of code else it blows up. I don't recommend this because it's intended for typed chat commands and doesn't belong in a macro, imo.


User avatar
aliasmask
Deity
Posts: 8624
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Modfiy to add advantage/disadvantage

Post by aliasmask »

wolph42 wrote:apparently we also forgot the 'VALUE=STRING' option in the input()


Yep.

Code: Select all

"outputType|All,Self,GM|Output to Who?|RADIO|SELECT=1 ORIENT=H VALUE=STRING"

Post Reply

Return to “Macros”