RPTools.net

Discussion and Support

Skip to content

It is currently Sun Oct 22, 2017 2:20 pm 






Reply to topic  [ 24 posts ]  Go to page 1, 2  Next

Previous topic | Next topic 

  Print view

Author Message
User avatar  Offline
RPTools Team
 
Joined: Thu Jun 01, 2006 1:05 pm
Posts: 5538
Location: Buffalo, NY
 Post subject: Modfiy to add advantage/disadvantage
PostPosted: Tue Aug 15, 2017 10:08 am 
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:
/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


Top
 Profile  
 
User avatar  Offline
Dragon
 
Joined: Wed Aug 31, 2011 8:49 pm
Posts: 495
Location: Somewhere between Heaven and Hell
 Post subject: Re: Modfiy to add advantage/disadvantage
PostPosted: Tue Aug 15, 2017 4:11 pm 
Code:
/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

Image


Top
 Profile  
 
User avatar  Offline
RPTools Team
 
Joined: Thu Jun 01, 2006 1:05 pm
Posts: 5538
Location: Buffalo, NY
 Post subject: Re: Modfiy to add advantage/disadvantage
PostPosted: Tue Aug 15, 2017 9:31 pm 
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


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7887
Location: Bay Area
 Post subject: Re: Modfiy to add advantage/disadvantage
PostPosted: Tue Aug 15, 2017 11:50 pm 
I would do it slightly different and simplify it. Code to follow.

Code:
<!-- 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)] 

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9413
Location: Netherlands
 Post subject: Re: Modfiy to add advantage/disadvantage
PostPosted: Wed Aug 16, 2017 3:01 am 
@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:
"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:
[H: broadcast(json.toList(output,"<BR>"),outputType)]
for this one
[H: broadcast(json.toList(output,"<BR>"),eval("bot_"+outputType+"()"))]
 

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
User avatar  Offline
RPTools Team
 
Joined: Thu Jun 01, 2006 1:05 pm
Posts: 5538
Location: Buffalo, NY
 Post subject: Re: Modfiy to add advantage/disadvantage
PostPosted: Wed Aug 16, 2017 7:30 am 
@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


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7887
Location: Bay Area
 Post subject: Re: Modfiy to add advantage/disadvantage
PostPosted: Wed Aug 16, 2017 8:40 am 
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:
<!-- 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.


starter lib token.rptok [168.82 KiB]
Downloaded 8 times
dorpond adv roll.txt [1.74 KiB]
Downloaded 7 times

_________________
Downloads:
Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9413
Location: Netherlands
 Post subject: Re: Modfiy to add advantage/disadvantage
PostPosted: Wed Aug 16, 2017 9:21 am 
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.

Quote:
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.

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
User avatar  Offline
RPTools Team
 
Joined: Thu Jun 01, 2006 1:05 pm
Posts: 5538
Location: Buffalo, NY
 Post subject: Re: Modfiy to add advantage/disadvantage
PostPosted: Wed Aug 16, 2017 9:34 am 
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


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7887
Location: Bay Area
 Post subject: Re: Modfiy to add advantage/disadvantage
PostPosted: Wed Aug 16, 2017 9:43 am 
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.

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
RPTools Team
 
Joined: Thu Jun 01, 2006 1:05 pm
Posts: 5538
Location: Buffalo, NY
 Post subject: Re: Modfiy to add advantage/disadvantage
PostPosted: Wed Aug 16, 2017 9:55 am 
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


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9413
Location: Netherlands
 Post subject: Re: Modfiy to add advantage/disadvantage
PostPosted: Wed Aug 16, 2017 10:13 am 
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.).

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7887
Location: Bay Area
 Post subject: Re: Modfiy to add advantage/disadvantage
PostPosted: Wed Aug 16, 2017 10:16 am 
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.

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9413
Location: Netherlands
 Post subject: Re: Modfiy to add advantage/disadvantage
PostPosted: Wed Aug 16, 2017 3:03 pm 
apparently we also forgot the 'VALUE=STRING' option in the input()

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7887
Location: Bay Area
 Post subject: Re: Modfiy to add advantage/disadvantage
PostPosted: Wed Aug 16, 2017 3:14 pm 
wolph42 wrote:
apparently we also forgot the 'VALUE=STRING' option in the input()


Yep.

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

_________________
Downloads:


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 24 posts ]  Go to page 1, 2  Next

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: No registered users and 1 guest





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman