Help with Quick & Dirty Dropdown Macro

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

Tyshalle
Giant
Posts: 173
Joined: Sat Jul 10, 2010 5:45 pm
Contact:

Help with Quick & Dirty Dropdown Macro

Post by Tyshalle »

I'm trying to figure out how to create a macro that, when you push the button, a window will pop up that will allow you to choose from a list. Each item on the list will say something like:

Sledgehammer vs. Leather Armor
Sledgehammer vs. Metal Armor
Spear vs. Combat Armor

Each item on the list will have text like that so that the players can easily differentiate between them, but they will have reasonably complex calculation beneath them. I will need to write this calculation by hand. An example would be /r (1d8+4)*(0.75)-2, and each item on the list would have a different calculation beneath it.

The twist is, beneath this list, but on the same popup window, there will need to be a field in which I can input a number, say +7, +11, or whatever, and somehow the macro will need to be able to calculate out how to input that number into the calculation. For instance, using the above formula I just posted, if a player were to enter in +11, then the formula would need to be revised on the fly to: /r (1d8+4+11)*(0.75)-2

Is what I'm looking to do even remotely possible? And can it be done in a way that a coding idiot like me might be able to work with it?

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

Re: Help with Quick & Dirty Dropdown Macro

Post by Xaelvaen »

There's a post here on the forums 'basic coding + initiative', and buried near the middle of it are the basics of dropdown window information collection. Also, some links to the proper wiki locations. I'll give you a basic rundown here, though.

This example will not have any 'valid' information, but I think you'll be able to plug it in just fine.

Code: Select all

[h: itemList="Warhammer,Longsword,Shortsword,Dagger"]
[h: status=input(
"chooseWeapon|" +itemList +"|Choose your Weapon|LIST|SELECT=0",
"setBonus|0|Attack Bonus|TEXT|WIDTH=3")]
[h: abort(status)]
[h: chosenWeapon=listGet(itemList,chooseWeapon)]
Attacking with [r: chosenWeapon +" with a bonus of " +setBonus]


This will show you a basic way to get information from a list and process it. Check out the aforementioned post for more detailed examples, and the wiki will be infinitely helpful. [wiki]http://www.lmwcs.com/rptools/wiki/input[/wiki]
"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

Tyshalle
Giant
Posts: 173
Joined: Sat Jul 10, 2010 5:45 pm
Contact:

Re: Help with Quick & Dirty Dropdown Macro

Post by Tyshalle »

Very cool, thanks a lot, this is definitely helping.

One thing I can't figure out, though, using the example you pasted, is how to assign specific weapons specific values. For instance, if I wanted the Longsword to roll a 2d8, but the Shortsword a 1d6, then how do I assign those values within the macro, and have it roll those dice at the end?

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

Re: Help with Quick & Dirty Dropdown Macro

Post by aliasmask »

You make a second list where the order matches up with the weapon. You then do a [wfunc]listGet[/wfunc] bases on the weapon selected and do an [wfunc]eval[/wfunc]. I would keep the input variable and the name of item selected as separate variables though. You can include a variable in the the string to be evaluated for the mod as well, which can be entered in the input.

Tyshalle
Giant
Posts: 173
Joined: Sat Jul 10, 2010 5:45 pm
Contact:

Re: Help with Quick & Dirty Dropdown Macro

Post by Tyshalle »

Hm, I'm not sure I completely understand. The two wiki entries you listed aren't very clear out of context, though this probably is because I have no idea how to code anything.

So right now I've managed to get it so that you'll push the macro button, and it'll ask you to pick your weapon, and the attack bonus, and then you hit OK, and a second menu will popup and ask you to pick your opponent's armor from a list. The result is that it will say: "Attacking with Brass Knuckles with a bonus of 0 vs. Leather Armor".

Code: Select all

[h: itemList1="Brass Knuckles,Club"]
[h: status=input(
"chooseWeapon|" +itemList1 +"|Choose your Weapon|LIST|SELECT=0",
"setBonus|0|Attack Bonus|TEXT|WIDTH=3")]
[h: itemList2="Leather Armor,Metal Armor"]
[h: status=input(
"chooseArmor|" +itemList2 +"|Choose your Armor|LIST|SELECT=0")]
[h: abort(status)]
[h: chosenWeapon=listGet(itemList1,chooseWeapon)]
[h: chosenArmor=listGet(itemList2,chooseArmor)]
Attacking with [r: chosenWeapon +" with a bonus of " +setBonus] vs. [r: chosenArmor]



That's currently what I've got. So if I want to fix it so that say, Brass Knuckles does 1d4 damage, and Club does 1d6, and Leather Armor subtracts 1 damage, and Metal Armor subtracts 2, how would I input this? You said make a second list that matches up to a first. So I assume right under the first line, I'd input something like

Code: Select all

[h: itemList3="1d4,1d6"]
but then how do I make listGet link them? The wiki entry on this is very confusing to me.

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

Re: Help with Quick & Dirty Dropdown Macro

Post by aliasmask »

I mean something like this:

Code: Select all

[h: itemList1="Brass Knuckles,Club"]
[h: itemList1Damage = "1d4,1d6"]
[h: itemList2="Leather Armor,Metal Armor"]
[h: abort(input(
"chooseWeapon|" +itemList1 +"|Choose your Weapon|LIST|SELECT=0",
"setBonus|0|Attack Bonus|TEXT|WIDTH=3",
"chooseArmor|" +itemList2 +"|Choose your Armor|LIST|SELECT=0"))]
[h: chosenWeapon=listGet(itemList1,chooseWeapon)]
[h: chosenDamage = listGet(itemList1Damage,chooseWeapon)]
[h: chosenArmor=listGet(itemList2,chooseArmor)]
Attacking with [r: chosenWeapon +"("+chosenDamage+") with a bonus of " +setBonus] vs. [r: chosenArmor] dealing <b>[r: eval(chosenDamage)]</b> damage.

Tyshalle
Giant
Posts: 173
Joined: Sat Jul 10, 2010 5:45 pm
Contact:

Re: Help with Quick & Dirty Dropdown Macro

Post by Tyshalle »

Very cool. I was able to take that and give the armor types different Damage Reductions, and then I just added the string to the eval(), so that it looks like this now:

Code: Select all

[h: itemList1="Brass Knuckles,Club"]
[h: itemList1Damage = "1d4,1d6"]
[h: itemList2="Leather Armor,Metal Armor"]
[h: itemList2DR="-1,-2"]
[h: abort(input(
"chooseWeapon|" +itemList1 +"|Choose your Weapon|LIST|SELECT=0",
"setBonus|0|Attack Bonus|TEXT|WIDTH=3",
"chooseArmor|" +itemList2 +"|Choose your Armor|LIST|SELECT=0"))]
[h: chosenWeapon=listGet(itemList1,chooseWeapon)]
[h: chosenDamage = listGet(itemList1Damage,chooseWeapon)]
[h: chosenArmor=listGet(itemList2,chooseArmor)]
[h: chosenDR = listGet(itemList2DR,chooseArmor)]
Attacking with [r: chosenWeapon +"("+chosenDamage+") with a bonus of " +setBonus] vs. [r: chosenArmor] dealing <b>[r: eval(chosenDamage+chosenDR)]</b> damage.


However, this doesn't seem to add the attack bonus to these values. It only takes weapon damage and the armor's Damage Reduction into account. I tried adding setBonus to the eval, so that it read: eval(chosenDamage+setBonus+chosenDR), but this somehow made things incredibly wonky. It came up with really weird values, where a 1d4 + 2 - 1 would somehow equal 37, or something incredibly high like that. So how do I get it to take the Attack Bonus into account with the rest of the calculation?

Also, is there some text I can throw in here to make it show not only the calculation but what the result of the dice roll is? It's hard to check my work when I can't see how it's arriving at these numbers.

Thanks a ton for all the help.

Tyshalle
Giant
Posts: 173
Joined: Sat Jul 10, 2010 5:45 pm
Contact:

Re: Help with Quick & Dirty Dropdown Macro

Post by Tyshalle »

Okay so I'm tinkering around a bit more, and here's what I'm realizing about setBonus in the code from the previous post. If it's a hard number, then the results seem to be randomized. Like, it doesn't matter if the weapon damage is 1d1, and the Armor modifier is -2. If the setBonus is 4, then the result should be 3 every single time. There should be no randomization with the die being 1d1. Yet with that exact situation, I have gotten the results of 11, 4, 12, 6, 1, 6, 10 on just a few quick rolls.

Here's the exact code I'm working with right now:

Code: Select all

[h: itemList1="Brass Knuckles,Club"]
[h: itemList1Damage = "1d1,1d6"]
[h: itemList2="Leather Armor,Metal Armor"]
[h: itemList2DR="-2,-2"]
[h: abort(input(
"chooseWeapon|" +itemList1 +"|Choose your Weapon|LIST|SELECT=0",
"setBonus|0|Attack Bonus|TEXT|WIDTH=3",
"chooseArmor|" +itemList2 +"|Choose your Armor|LIST|SELECT=0"))]
[h: chosenWeapon=listGet(itemList1,chooseWeapon)]
[h: chosenDamage = listGet(itemList1Damage,chooseWeapon)]
[h: chosenArmor=listGet(itemList2,chooseArmor)]
[h: chosenDR = listGet(itemList2DR,chooseArmor)]
Attacking with [r: chosenWeapon +"("+chosenDamage+") with a bonus of " +setBonus] vs. [r: chosenArmor] dealing <b>[r: eval(chosenDamage+setBonus+chosenDR)]</b> damage.


I know it's something to do with setBonus, because when I remove setBonus from eval(), this randomization goes away completely.

Also, I mentioned this in my previous post, but is there a line of code I can drop in somewhere to see exactly what the dice rolled?


EDIT: Putting parenthesis around and a plus sign in front of setBonus seems to fix the randomization. For instance, (+0). I'm not sure why that is the case, but there's gotta be an easier way to do this than to force my players to type (+#) in that box every time.

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

Re: Help with Quick & Dirty Dropdown Macro

Post by aliasmask »

Unfortunately, eval only works on strings and if your string is a number, it crashes. I never thought of putting () around it though.. good idea. I usually just do this "0"+##... that way it forces the number to be a string for the eval. I think you can use [wfunc]string[/wfunc] as well.

Tyshalle
Giant
Posts: 173
Joined: Sat Jul 10, 2010 5:45 pm
Contact:

Re: Help with Quick & Dirty Dropdown Macro

Post by Tyshalle »

Err, wait, huh? So are you saying what I'm looking to do isn't possible?

Also further working with this, adding parenthesis doesn't work, it seems to just ignore everything else but the setBonus.

Tyshalle
Giant
Posts: 173
Joined: Sat Jul 10, 2010 5:45 pm
Contact:

Re: Help with Quick & Dirty Dropdown Macro

Post by Tyshalle »

Okay, I managed to figure out exactly how to do it, and it's pretty much all done. Just in case anyone is curious how I did it, here's the code:

Code: Select all

[h: itemList1="Brass Knuckles,Club"]
[h: itemList1Damage = "(+1d1+1,(+1d6"]
[h: itemList2="Leather Armor,Metal Armor"]
[h: itemList2DR1="-1),-20)"]
[h: itemList2DR2="*0.5,*0.75"]
[h: itemList3="+0,+1,+2,+3,+4,+5"]
[h: itemList3mod="+1d1-1,+1d1+0,+1d1+1,+1d1+2,+1d1+3,+1d1+4"]
[h: abort(input(
"chooseWeapon|" +itemList1 +"|Choose your Weapon|LIST|SELECT=0",
"chooseArmor|" +itemList2 +"|Choose your Armor|LIST|SELECT=0",
"chooseAccuracy|" +itemList3 +"|Accuracy Bonus|LIST|SELECT=0"))]
[h: chosenWeapon=listGet(itemList1,chooseWeapon)]
[h: chosenDamage = listGet(itemList1Damage,chooseWeapon)]
[h: chosenArmor=listGet(itemList2,chooseArmor)]
[h: chosenDR1 = listGet(itemList2DR1,chooseArmor)]
[h: chosenDR2 = listGet(itemList2DR2,chooseArmor)]
[h: chosenAccuracy = listGet(itemList3,chooseAccuracy)]
[h: chosenAccuracymod = listGet(itemList3mod,chooseAccuracy)]
Attacking with [r: chosenWeapon +"("+chosenDamage+") with a bonus of " +chosenAccuracy] vs. [r: chosenArmor] dealing <b>[r: eval(chosenDamage+chosenAccuracymod+chosenDR1+chosenDR2)]</b> damage.


The only thing it's missing, which I need, is some kind of code to show me the results of the itemList1Damage rolls. Is there any way to get that?

User avatar
Oriet
Cave Troll
Posts: 30
Joined: Mon Dec 05, 2011 10:58 am
Location: Somewhere that's not there, but not really here.
Contact:

Re: Help with Quick & Dirty Dropdown Macro

Post by Oriet »

Tyshalle wrote:Okay, I managed to figure out exactly how to do it, and it's pretty much all done. Just in case anyone is curious how I did it, here's the code:

Code: Select all

[h: itemList1="Brass Knuckles,Club"]
[h: itemList1Damage = "(+1d1+1,(+1d6"]
[h: itemList2="Leather Armor,Metal Armor"]
[h: itemList2DR1="-1),-20)"]
[h: itemList2DR2="*0.5,*0.75"]
[h: itemList3="+0,+1,+2,+3,+4,+5"]
[h: itemList3mod="+1d1-1,+1d1+0,+1d1+1,+1d1+2,+1d1+3,+1d1+4"]
[h: abort(input(
"chooseWeapon|" +itemList1 +"|Choose your Weapon|LIST|SELECT=0",
"chooseArmor|" +itemList2 +"|Choose your Armor|LIST|SELECT=0",
"chooseAccuracy|" +itemList3 +"|Accuracy Bonus|LIST|SELECT=0"))]
[h: chosenWeapon=listGet(itemList1,chooseWeapon)]
[h: chosenDamage = listGet(itemList1Damage,chooseWeapon)]
[h: chosenArmor=listGet(itemList2,chooseArmor)]
[h: chosenDR1 = listGet(itemList2DR1,chooseArmor)]
[h: chosenDR2 = listGet(itemList2DR2,chooseArmor)]
[h: chosenAccuracy = listGet(itemList3,chooseAccuracy)]
[h: chosenAccuracymod = listGet(itemList3mod,chooseAccuracy)]
Attacking with [r: chosenWeapon +"("+chosenDamage+") with a bonus of " +chosenAccuracy] vs. [r: chosenArmor] dealing <b>[r: eval(chosenDamage+chosenAccuracymod+chosenDR1+chosenDR2)]</b> damage.


The only thing it's missing, which I need, is some kind of code to show me the results of the itemList1Damage rolls. Is there any way to get that?

Yes, actually, there is. The easy way would be to change:
[r: eval(chosenDamage+chosenAccuracymod+chosenDR1+chosenDR2)]
to:
[t: eval(chosenDamage+chosenAccuracymod+chosenDR1+chosenDR2)]
This will then give a tooltip that will show how it evaluated the output when you hover your mouse over the damage amount. Note that it will not tell you how it calculated the values of the variables, simply what the variables are called and what number was assigned to them.

There are other ways to display even more info with a hover over, but that also requires a lot more coding and knowledge of HTML, and is probably more than you're looking for at the moment. In general I've found tooltips to work for simple macros well enough, but after a certain amount of fanciness and complexity of passing around and altering variables a lot before the output you need other ways of doing it. For the last attack macros I've been working on I've been utilising HTML tables to output the results, with <span title="pop-up stuff"> tags to say how I got the final result.
Kill them all, and let the Game Master grant the exp!

ImageImage

Tyshalle
Giant
Posts: 173
Joined: Sat Jul 10, 2010 5:45 pm
Contact:

Re: Help with Quick & Dirty Dropdown Macro

Post by Tyshalle »

Hm, that's handy in that it shows the variables, which helps me check my work in terms of equipment stats. It doesn't seem to show me the results of the dice rolls, though. So basically if I have a dice that rolls 1d8+4, I'd like to see the result of the dice roll in the mouseover. Is there an easy way to get it to do that?

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

Re: Help with Quick & Dirty Dropdown Macro

Post by Xaelvaen »

Alrighty; eval() is only needed to take a text/string result and get something from it. In example, 1d10 from a list selection is just a random word; 1d10. So you stick it into eval to get it to understand you mean roll that 1d10.

That being said, only stick anything that needs to be rolled into your eval, and the tooltip will display just the result of the roll for the eval tooltip. Anything that just uses basic math (such as +1, +2, /2, etc) can literally just be added into the results.

In example, roll=eval("1d10"). So in your tooltip, you can do [t: roll] and it will just display what was rolled. Anything you want to do to that number afterward can simply be done without eval (usually).

Code: Select all

[h: roll=eval("1d10")]
[h: mods=4]
[h: DR=".33"]
[t: (roll +mods)*DR]


In the example's tooltip, you can clearly see what the die roll was all on its own. Hopefully this can help you integrate it into your own code =)
Last edited by Xaelvaen on Wed Dec 28, 2011 10:00 am, edited 1 time in total.
"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

User avatar
Azhrei
Site Admin
Posts: 12061
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: Help with Quick & Dirty Dropdown Macro

Post by Azhrei »

Xaelvaen wrote:In example, roll=eval(1d10).

He meant to say roll=eval("1d10") (note the double quotes to make it a string).

Post Reply

Return to “Macros”