Is it possible to automate some combat results in Maptool?

If you have searched the other User Creations subforums and an answer to your question has not been found, please post here!

Moderators: dorpond, trevor, Azhrei, Gamerdude

User avatar
Bone White
Great Wyrm
Posts: 1124
Joined: Tue Aug 23, 2011 11:41 am
Location: Cornwall, UK

Re: Is it possible to automate some combat results in Maptoo

Post by Bone White »

madmaxneo wrote:"targetNum|"Tokens|tokenList|pick target|LIST|SELECT=0 ICON=TRUE ICONSIZE=30")]
You have three double quotation mark characters (") within the line, remove the erroneous one:

Code: Select all

"targetNum|"Tokens|tokenList|pick target|LIST|SELECT=0 ICON=TRUE ICONSIZE=30")]

madmaxneo
Giant
Posts: 148
Joined: Thu Jun 20, 2013 5:04 pm
Location: NW Indiana

Re: Is it possible to automate some combat results in Maptoo

Post by madmaxneo »

I did, this is my result:

Code: Select all

[h:status=input(
"targetNum|Tokens|tokenList|pick target|LIST|SELECT=0 ICON=TRUE ICONSIZE=30")]
Now I get an "error in body of roll" for that line.
I also tried this:

Code: Select all

[h:status=input(
"targetNum|Tokens|"+tokenList+"|pick target|LIST|SELECT=0 ICON=TRUE ICONSIZE=30")]
But it asks for a value for tokenList


Btw, why did you post the same code twice? There is no difference in the codes you posted....

Bruce

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Is it possible to automate some combat results in Maptoo

Post by wolph42 »

madmaxneo wrote:I've tried a few different variations of that code and was unable to get it to work.
Here is what I have tried:
Try 1

Code: Select all

[H: abort(input(strformat("Tokens|tokenList|pick target|LIST|VALUE=STRING")))]
Try 2

Code: Select all

[h:status=input(
"targetNum|"Tokens|tokenList|pick target|LIST|SELECT=0 ICON=TRUE ICONSIZE=30")]
And I tried the code exactly as is from the wiki with the images in it and it could not find an image list.
Try 1 Will list a pull down menu but it only has "TokenList" in the pull down menu, then it asks for a value for target. If I enter a name separate boxes will pop up asking for values of all the inputs.
Try 2 Basically prints out the whole macro into the chat window.
Try 3 I put the code in Try 1 in my working attack macro, and it produced a drop down list with the same result in try 1.

Btw, I added the closing ) in the macro and it seems to work fine now, except it asks for a value for target, and then the subsequent inputs.

Bruce
dude come on, some brains when copying a suggestion. You use input the whole time correctly and with a suggestion from me you all of a sudden depart from your own code style
Try 1

Code: Select all

[H: abort(input(strformat("Tokens|tokenList|pick target|LIST|VALUE=STRING")))]
should obviously be:

Code: Select all

[tokenList = getVisibleTokenNames()]
[H: abort(input(strformat("target|"+tokenList+"|pick target|LIST|VALUE=STRING")))]
I do not always *pre-chew* everything, in this case I just showed you where the LIST option is used.

madmaxneo
Giant
Posts: 148
Joined: Thu Jun 20, 2013 5:04 pm
Location: NW Indiana

Re: Is it possible to automate some combat results in Maptoo

Post by madmaxneo »

I got that to work in my old code to a certain point. It selects the target but doesn't adjust the damage taken.
When I try using it with your corrected code it starts asking for a value for MiscDB.

Bruce

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Is it possible to automate some combat results in Maptoo

Post by wolph42 »

madmaxneo wrote:I got that to work in my old code to a certain point. It selects the target but doesn't adjust the damage taken.
When I try using it with your corrected code it starts asking for a value for MiscDB.

Bruce
could you post your most *final* code here so I(we) can have a look at it again.
Basically if it asks for MiscDB then its not assigned anywhere, which means you either forgot it or the code throws an (invisible) error.

madmaxneo
Giant
Posts: 148
Joined: Thu Jun 20, 2013 5:04 pm
Location: NW Indiana

Re: Is it possible to automate some combat results in Maptoo

Post by madmaxneo »

Here is the code as I placed it.

Code: Select all

[H: WpnList                = ""]
[H,COUNT(10): WpnList    = listAppend(WpnList, getStrProp(eval("Weapon"+roll.count), "WpnName"))]
[H: WpnNum                = getStrProp(Private, "DefaultWpn", 0)]

[H: abort(input(
    "WpnNum | " + WpnList + " | Select weapon to use | LIST | SELECT    = " + WpnNum
))]

[H: Private                = setStrProp(Private, "DefaultWpn", WpnNum)]
 
[H: varsFromStrProp(eval("Weapon" + WpnNum), "suffixed")]
[tokenList = getVisibleTokenNames()]
[H: abort(input(strformat("target|"+tokenList+"|pick target|LIST|VALUE=STRING")))]
[H: abort(input(
        "target |"    + getVisibleTokenNames()                    + "|Choose Target",
    "MiscOB |"    + StrProp(eval("Weapon" + WpnAttackBonus_)    + "|Offensive bonus",
    "MiscDB |"    + StrProp(eval("Weapon" + WpnDefenseBonus_)    + "|Defensive bonus",
    "MiscCTT |"    + StrProp(eval("Weapon" + WpnKeyword_)        + "|Critical Type",
    "MiscFMB |"    + StrProp(eval("Weapon" + WpnFumble_)        + "|Fumble Range"
)))))]

[h: OpDB    = getProperty(DB, target)]
[h: bonus    = MiscOB - OpDB]

[H: rolls    = ""]
[H: roll    = 100]
[H, while(roll >= 96), code:{
    [H: roll        = 1d100]
    [H: rolls        = listAppend(rolls,roll)]
    [H: total        = eval(strformat("sum(%{rolls}+bonus)"))]
}]

[H: RollTotal        = eval(strformat("sum(%{rolls})"))]
[H: local.TempDB        = MiscDB+DB]
[h: setProperty("TempDB", local.TempDB, target)]

[h: message    = strformat("
    attacks with <b>%{WpnName_}</b> 
    <i>Rolls: %{rolls} Bonus: %{MiscOB} - %{OpDB}</i> The total is: %{total}
    <span style    = 'color:red'>(DB is now: %{local.TempDB})</span>
    %s",
    if(RollTotal <= MiscFMB, "<b>You Fumbled!</b>", "Damage: <b>" + table(MiscCTT, Total) + "</b> <i>"+MiscCTT+"</i>"
)]

[r:message] 
If I enter a value for MiscOB it returns
   Error in body of roll.       Statement options (if any): h       Statement Body : bonus = MiscOB - OpDB
I get the same error when I mix it with my original code.
Bruce

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Is it possible to automate some combat results in Maptoo

Post by wolph42 »

then most likely it goes wrong here:

[h: OpDB = getProperty(DB, target)]

you can figure that out by e.g. adding
[broadcast(strformat("The OPDB value is: %{OpDB} and the MiscOB is %{MiscOB}"))]

so you know what there actual values are.

After all e.g. [bonus = 5 -"a"] will render exactly the error you get, although most likely the value will be "".

its around this time that I start suggesting that you start reading the debug article I wrote in the wiki (link in sig.)

madmaxneo
Giant
Posts: 148
Joined: Thu Jun 20, 2013 5:04 pm
Location: NW Indiana

Re: Is it possible to automate some combat results in Maptoo

Post by madmaxneo »

wolph42 wrote:then most likely it goes wrong here:

[h: OpDB = getProperty(DB, target)]

you can figure that out by e.g. adding
[broadcast(strformat("The OPDB value is: %{OpDB} and the MiscOB is %{MiscOB}"))]

so you know what there actual values are.

After all e.g. [bonus = 5 -"a"] will render exactly the error you get, although most likely the value will be "".

its around this time that I start suggesting that you start reading the debug article I wrote in the wiki (link in sig.)
Unfortunately I really don't have the time to read that debugging article right now. I've been real busy lately and I am trying to keep my game afloat. I had to switch to online gaming because we have no real place to play at for more than 2 hours. One of my players can't get online, another just got a new job driving rigs, not sure when he will be back. So I am currently left with two players, one of which is a great player and the other is a little hard to deal with at times (He is a teen). Not to mention I just started at a new job and my hours are odd. I haven't had time to read much of anything. I am trying to tweak Maptools so it runs smoother for my players and hopefully get more people interested in Maptools because there are a lot of people that want to play but can only play online. To be honest I have not really had the time to mess with Maptools like I want to and was before.

I am assuming you are referring to the code bonus = MiscOB - OpDB, in your (bonus = 5 -"a"), here is my response.
I am not sure how the (bonus = 5 -"a") is rendering that error because there is no "a" in the OpDB, as that is refering to the opponents Defensive bonus (DB on the token). MiscOB works fine in my old code, and OpDB is an entry the player has to input in my old code, and that works fine. In the new code it has to look it up on the token, so it is messing up in there somewhere. Essentially it seems the code is not getting the values from the token chosen as the target in the drop down list. That is where I think it is going wrong.

I added that broadcast code and it did nothing different, I still get the same error. Is there a specific place I need to place the broadcast lines in my code?


Bruce

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Is it possible to automate some combat results in Maptoo

Post by wolph42 »

The "a" was an example of how it *can*go wrong, the broadcast shows you the value regardless whether the macro bugs out AS LONG as it's executed BEFORE the error. So place the broadcast before/above the erroneous line, run it and check the chat to see what actual values are. This means that the code will still fail but at least then you know why.

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: Is it possible to automate some combat results in Maptoo

Post by CoveredInFish »

Sounds like the tokens to do not hold the values you expect (and you can check that out if you follow wolphs advice).

Let me explain something: MapTool has no typed variables/properties, so you can store different data in the same variable/property. But some operations require the data to be of a specific kind (eg a number or a text). Sometimes (as in some specific cases) MT tries to be smart and converts the data, sometimes not. A property with an undefined value returns "" (or empty string) and MT cannot convert this into a number. The minus operator requires numbers.

EDIT: and spotted something else

Code: Select all

[H: total        = eval(strformat("sum(%{rolls}+bonus)"))]
will be evaluated as e.g. sum(7,15,42+bonus) what maybe (?) causes error.
Shouldnt this be (or similar)

Code: Select all

[H: total        = eval(strformat("sum(%{rolls})+bonus)"))]

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Is it possible to automate some combat results in Maptoo

Post by wolph42 »

CoveredInFish wrote:EDIT: and spotted something else
nice catch!

I guess

Code: Select all

[H: total        = eval(strformat("sum(%{rolls},bonus)"))]
would also work and might be just that 0.00000001 s faster :mrgreen:

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Is it possible to automate some combat results in Maptoo

Post by Full Bleed »

madmaxneo wrote:Unfortunately I really don't have the time to read that debugging article right now. I've been real busy lately and I am trying to keep my game afloat.
Don't take this the wrong way, but you may be putting your energy in the wrong place if this is what you are trying to accomplish.

The level of automation that you are shooting for is really not a necessity to play a table top game. It's a convenience. And, as you've found, getting that convenience to work perfectly in some game systems is not always a simple matter. Some times it's easier to just let your players pick up dice, roll them (or click a simple dice macro roll in MT that displays a result) and then resolve things the old fashion way... like you'd do if you all *were* sitting around a table.

In the meantime, have your players use paper to track and resolve things MT doesn't. And then, as time allows (and participation demands), spend some time getting in some of the nifty automation. I suggest one *tiny* feature at a time. Slowly grow your framework in a way that allows you the time to actually understand what it's doing and how it's doing it. Not having enough time to read articles designed to do just that is a red flag. You're trying to skip very necessary steps in the quest to get from point A to point Z. You might only need to get to B to actually play your game. Because, I can tell you now, you're going to run into issues in a game with automation you don't really understand... and nothing kills a game like the GM wasting time trying to figure out what's wrong with his code while the players sit around twiddling their thumbs.

I didn't automate attacks in my framework for a VERY long time. And even now, it has limitations (i.e. it's really not built to attack multiple targets at once and I still manually roll all monster/opponent attacks because there are far more variables than the ones players have... and I like to roll dice old school!) And an in-game character sheet was also one of the last things I put in because it was really unnecessary (but has now evolved quite nicely over time to do things I never thought I'd have it do).

Truth is, I think your game will be better off if you put more time and energy into the game itself. Online game automation is a strawman for running a great game. It's a crutch that can just as easily ruin a session... and I hate to see you wasting all this "limited" time and energy on something that's not going to "save" your game or make your players walk away wanting more. The content of the game itself will pay WAY bigger dividends than automated attacks.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

madmaxneo
Giant
Posts: 148
Joined: Thu Jun 20, 2013 5:04 pm
Location: NW Indiana

Re: Is it possible to automate some combat results in Maptoo

Post by madmaxneo »

Now that was tricky. A macro deity met me on skype and went through the whole process of the code needed to have the targets DB subtracted from the attack then automatically apply the damage to the target. That took about 4 or 5 hours to do. He wrote the code and explained himself as he went on, debugged errors, rewrote some of my code, debugged errors, rewrote some of his code, rewrote, and so on....I learned a lot but still know squat.
After all this and he went on his way, I decided to check the automated attack stuff with the PC's and I ran into a really weird problem. The macro would not work with one certain PC as the target. But it worked fine with every other PC as a target. The code would not find that particular PC's DB for some reason. I checked and double checked all the stats and nothing was out of place. I then decided to simply recreate his character. I reloaded the token and entered only the basic combat stuff and it worked just fine. So I entered the rest of the character info, then it wouldn't work anymore. I kept getting this weird macro error. So I went back to the old token to see if I could figure out where it was going wrong and guess what, it worked fine.... My thoughts were WTF??? I didn't change anything. I also had an old problem with this particular token and using the teleport pads from Wolph42's BoT. They would not work with this same token, but now they do!! Any thought on this? Or do I have Gremlins????

Bruce

User avatar
Bone White
Great Wyrm
Posts: 1124
Joined: Tue Aug 23, 2011 11:41 am
Location: Cornwall, UK

Re: Is it possible to automate some combat results in Maptoo

Post by Bone White »

This will be hard to tell without actually looking at the token and your macros. Either upload your campaign (without large maps/images), such as to dropbox, or get your contact to take a look for us.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Is it possible to automate some combat results in Maptoo

Post by wolph42 »

In my bot (latest version) there is a diagnose button, run that for your campaign file with that token in it. Let me know the result.

Post Reply

Return to “Requests for HELLLLP!”