Help with weapon attack macro

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

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Help with weapon attack macro

Post by ralstad »

Hello all,

I am having an issue I have tried using the wiki and create the macro for multiple attack with a weapon and am having all sort of problems. I would like the macro to check to see if a weapon has a second, third and fourth attack then roll for each attack.
I have done an abbreviated token properties like this
*@Weapon 1
*@Weapon 1 Dmg
*@Weapon 1 Att 1
*@Weapon 1 Att 2
*@Weapon 1 Att 3
*@Weapon 1 Att 4
*@Weapon 1 Error
*@Weapon 1 Threat

The macro I am trying to use is this

Code: Select all

<b>Attack:</b> [t:1d20+Weapon 1 Att 1]<br>
[h: dmg = Weapon 1 Dmg]
<b>Damage:</b> [t: dmg+5]
[h,if(Weapon 1 Att 2 > 0),CODE:
{
    [roll = 1d20]
    [attack2 = Weapon 1 Att 2]
    <b>Attack 2:</b> [Hit = roll + attack2]
};
{
    ""
}]
Could someone please help me get this working. It is suppose to check for all 4 possible attacks. If it could check for a threat or error that would be even more great.

ralstad

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Help with weapon attack macro

Post by aliasmask »

MT variable names can't have spaces.

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Help with weapon attack macro

Post by ralstad »

Thanks Alias I figured that was one of my problems but still having a problem with the if part. Here is the new code so far.

Code: Select all

[h: att1 = getProperty("Wpn 1 Att 1")]
[h: wpndmg1 = getProperty("Wpn 1 Dmg")]
[h: bns1 = getProperty("Wpn 1 Dmg Bns")]
[h: roll1 = 1d20]
[h: dmg1 = eval(wpndmg1)]
[h: att2 = getProperty("Wpn 1 Att 2")]
[h: roll2 = 1d20]
<b>Attack:</b> [t: roll1+att1]<br>
<b>Damage:</b> [t: dmg1+bns1]<br>
[h,if(att2 > 0),CODE:{

    <b>Attack 2:</b> [t:  roll2 + att2]
};
{
    ""
}]
Thanks anyone for helping

I figured it out!!!!!!!!! :)

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Help with weapon attack macro

Post by ralstad »

OK got it to stop popping an error but it isn't listing the second attack result. Any suggestions. Here is code.

Code: Select all

[h: att1 = getProperty("Wpn 1 Att 1")]
[h: wpndmg1 = getProperty("Wpn 1 Dmg")]
[h: bns1 = getProperty("Wpn 1 Dmg Bns")]
[h: roll1 = 1d20]
[h: dmg1 = eval(wpndmg1)]
[h: att2 = getProperty("Wpn 1 Att 2")]
[h: roll2 = 1d20]
<b>Attack:</b> [t: roll1+att1]<br>
<b>Damage:</b> [t: dmg1+bns1]<br>
[h: dmg2 = eval(wpndmg1)]
[h, if(att2 > 0),CODE:{
<b>Attack 2:</b> [t: roll2 + att2]<br>
<b>Damage:</b> [t: dmg2+bns1]<br>
}]
I did check the second attack value it is above 0.

I figured this out to. Just needed to replace the h with a r before the if statement.

Thanks for any suggestions.
Ralstad

User avatar
Jagged
Great Wyrm
Posts: 1306
Joined: Mon Sep 15, 2008 9:27 am
Location: Bristol, UK

Re: Help with weapon attack macro

Post by Jagged »

Your last if is in an H, which stands for "Hidden". Change it to R

Code: Select all

[r, if(att2 > 0),CODE:{
<b>Attack 2:</b> [t: roll2 + att2]<br>
<b>Damage:</b> [t: dmg2+bns1]<br>
}]

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Help with weapon attack macro

Post by ralstad »

ok now have a problem with

Code: Select all

[r: roll1 = 1d20]
[r: assert(roll1 > 0, "FUMBLE",0)]
<b>Attack:</b> [t: roll1+2]<br>
The code does not give the FUMBLE!!!!! roll1 is a 1

Code: Select all

[r: roll1 = 1d20]
[r: assert(roll1 == 0, "FUMBLE",0)]
<b>Attack:</b> [t: roll1+2]<br>
This way only give a FUMBLE!!!!!!! every time.

What am i doing wrong?

ralstad

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

Re: Help with weapon attack macro

Post by Full Bleed »

ralstad wrote:
Mon Jul 09, 2018 8:50 pm
ok now have a problem with

Code: Select all

[r: roll1 = 1d20]
[r: assert(roll1 > 0, "FUMBLE",0)]
<b>Attack:</b> [t: roll1+2]<br>
The code does not give the FUMBLE!!!!! roll1 is a 1
You're using Wiki: assert() incorrectly.

In your code, roll1 will always have a value between 1 and 20.

So roll1 is always greater than 0.

Assert only halts execution and prints the message ("FUMBLE") if the condition is FALSE or 0.

This is closer to what you want:

Code: Select all

[h: roll1 = 1d20]
[h: broadcast (roll1)]
[h: assert(roll1 > 1, "FUMBLE", 0)]
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Help with weapon attack macro

Post by ralstad »

Thanks FullBleed,

OK, the following code figures 2 attacks and outputs the results into the chat window, I am going to expand it out to 4 attacks but I am wondering how to stop a code if a 1 is rolled on an attack roll and still get the output up till then.

Code: Select all

[h: att1 = getProperty("Wpn 1 Att 1")]
[h: wpndmg1 = getProperty("Wpn 1 Dmg")]
[h: bns1 = getProperty("Wpn 1 Dmg Bns")]
[h: roll = 1d20]
[h: dmg1 = eval(wpndmg1)]
[h: att2 = getProperty("Wpn 1 Att 2")]
[h: roll2 = 1d20]
[h: dmg2 = eval(wpndmg1)]
[switch(roll), code:
case 20: {
<b>Attack:</b> [t: roll+att1]<br>
<b>Damage:</b> [t: dmg1+dmg1+bns1]<br>
  };
case 1: {
<b>FUMBLE!!!!!</b><br>
<----------------I would like to place something here that will end the code from here out but leave the output above----------------->
  };
default: {
<b>Attack:</b> [t: roll+att1]<br>
<b>Damage:</b> [t: dmg1+bns1]<br>
}]
[h: roll = 1d20]
[r, if(att2 > 0),CODE:{[switch(roll), code:
case 20: {
<b>Attack:</b> [t: roll+att2]<br>
<b>Damage:</b> [t: dmg2+dmg2+bns1]<br>
  };
case 1: {
<b>FUMBLE!!!!!</b><br>
<----------------I would like to place something here that will end the code from here out but leave the output above----------------->
  };
default: {
<b>Attack:</b> [t: roll+att1]<br>
<b>Damage:</b> [t: dmg2+bns1]<br>
}]}]
ralstad

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

Re: Help with weapon attack macro

Post by Full Bleed »

First, you're using properties with spaces in them. Don't do that.

From the Introduction_to_Properties article:
NOTE: Property names cannot have spaces in them - so if you have a property called "Hit Points", you would need to enter it as HitPoints.
As for:
ralstad wrote:
Tue Jul 10, 2018 12:23 am
I would like to place something here that will end the code from here out but leave the output above
No function will do that. The entire macro runs.

You have to conditionalize all of your output, break the code up to smaller functions that can be terminated without stopping the calling macro (see Wiki: defineFunction()), or you might want to consider building output in various subsections of your macro and then only broadcasting 1 valid string at the end.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Help with weapon attack macro

Post by ralstad »

Hello,

Can I put an

Code: Select all

[r: if(fum == 0), -------code for attack--------]
around this

Code: Select all

[r, if(att2 > 0),CODE:{[switch(roll), code:
case 20: {
<b>Attack:</b> [t: roll+att2]<br>
<b>Damage:</b> [t: dmg2+dmg2+bns1]<br>
  };
case 1: {
<b>FUMBLE!!!!!</b><br>
[h: fum=1]
  };
default: {
<b>Attack:</b> [t: roll+att2]<br>
<b>Damage:</b> [t: dmg2+bns1]<br>
}]}]
With this before the code

Code: Select all

[h: fum=0]
So I would end with this code to stop

Code: Select all

[r: if(fum == 0),[r, if(att2 > 0),CODE:{[switch(roll), code:
case 20: {
<b>Attack:</b> [t: roll+att2]<br>
<b>Damage:</b> [t: dmg2+dmg2+bns1]<br>
  };
case 1: {
<b>FUMBLE!!!!!</b><br>
[h: fum=1]
  };
default: {
<b>Attack:</b> [t: roll+att2]<br>
<b>Damage:</b> [t: dmg2+bns1]<br>
}]}]]
So if the previous roll is a 1 the next part checks for fum=0 which it would fum=1 so it wouldn't run the next rolls because that variable has changed.

ralstad

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

Re: Help with weapon attack macro

Post by Full Bleed »

ralstad wrote:
Wed Jul 11, 2018 8:06 pm
Can I put an

Code: Select all

[r: if(fum == 0), -------code for attack--------]
around this
That's 3 code levels... which isn't something you should do. There is a way around it, but I suggest you learn to make your macros with 2 code levels and reserve using the workaround for rare occasions when you have no other choice. Fewer code levels is faster and uses less memory.

In this case you can add more than one condition to the Wiki: if() statement.

You can see the available operators listed here: if_(roll_option)

For example:

Code: Select all

[if(att2 > 0 && fum == 0),CODE:
	{
		[switch(roll), CODE:
			case 20:
				{
					<b>Attack:</b> [t: roll+att2]<br>
					<b>Damage:</b> [t: dmg2+dmg2+bns1]<br>
				};
			case 1:
				{
					<b>FUMBLE!!!!!</b><br>
					[h: fum=1]
				};
			default:
				{
					<b>Attack:</b> [t: roll+att2]<br>
					<b>Damage:</b> [t: dmg2+bns1]<br>
				}
		]
	};
	{
	}
]
So if the previous roll is a 1 the next part checks for fum=0 which it would fum=1 so it wouldn't run the next rolls because that variable has changed.
You lost me here. But hopefully understanding that you can make your if statements more conditional will help you do what you want.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Help with weapon attack macro

Post by ralstad »

Thank you full bleed that helped out wonderfully, I forgot about the double if.

Is there a way to remove the '' '' when the following code runs.

Code: Select all

[h: att1 = getProperty("Wpn 1 Att 1")]
[h: wpndmg1 = getProperty("Wpn 1 Dmg")]
[h: bns1 = getProperty("Wpn 1 Dmg Bns")]
[h: roll = 1d20]
[h: dmg1 = eval(wpndmg1)]
[h: att2 = getProperty("Wpn 1 Att 2")]
[h: dmg2 = eval(wpndmg1)]
[h: att3 = getProperty("Wpn 1 Att 3")]
[h: dmg3 = eval(wpndmg1)]
[h: att4 = getProperty("Wpn 1 Att 4")]
[h: dmg4 = eval(wpndmg1)]
[h: fum=0]
[switch(roll), code:
case 20: { -------------- can I use a variable instead of 20-------------------- say if I create a variable earlier being threat from a weapon, say >=18
<b>Attack:</b> [t: roll+att1]<br>
<b>Damage:</b> [t: dmg1+dmg1+bns1]<br>
  };
case 1: { -------------- can I use a variable instead of 1-------------------- say if I create a variable earlier being error from a weapon, say <=3
<b>FUMBLE!!!!!</b><br>
[h: fum=1]
  };
default: {
<b>Attack:</b> [t: roll+att1]<br>
<b>Damage:</b> [t: dmg1+bns1]<br>
}]
[h: roll = 1d20]
[r, if(att2 > 0 && fum == 0),CODE:{[switch(roll), code:
case 20: {
<b>Attack:</b> [t: roll+att2]<br>
<b>Damage:</b> [t: dmg2+dmg2+bns1]<br>
  };
case 1: {
<b>FUMBLE!!!!!</b><br>
[h: fum=1]
  };
default: {
<b>Attack:</b> [t: roll+att2]<br>
<b>Damage:</b> [t: dmg2+bns1]<br>
}]}]
[h: roll = 1d20]
[r, if(att3 > 0 && fum == 0),CODE:{[switch(roll), code:
case 20: {
<b>Attack:</b> [t: roll+att3]<br>
<b>Damage:</b> [t: dmg3+dmg3+bns1]<br>
  };
case 1: {
<b>FUMBLE!!!!!</b><br>
[h: fum=1]
  };
default: {
<b>Attack:</b> [t: roll+att3]<br>
<b>Damage:</b> [t: dmg3+bns1]<br>
}]}]
[h: roll = 1d20]
[r, if(att4 > 0 && fum == 0),CODE:{[switch(roll), code:
case 20: {
<b>Attack:</b> [t: roll+att4]<br>
<b>Damage:</b> [t: dmg4+dmg4+bns1]<br>
  };
case 1: {
<b>FUMBLE!!!!!</b><br>
  };
default: {
<b>Attack:</b> [t: roll+att4]<br>
<b>Damage:</b> [t: dmg4+bns1]<br>
}]}]
The result of the following code is

Attack: 15
Damage: 14
FUMBLE!!!!!
'' '' ------------------ I would like to remove these.----------------------

Also, can I use a variable in the case. Like I have listed above

Thanks for the help

ralstad

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Help with weapon attack macro

Post by ralstad »

Ok, thank you everyone that has helped on this macro I believe I have figured everything out that I needed to.
Here is the following code I ended up with what do you guys think?

Code: Select all

[h: att1 = getProperty("Wpn 1 Att 1")]
[h: wpndmg1 = getProperty("Wpn 1 Dmg")]
[h: bns1 = getProperty("Wpn 1 Dmg Bns")]
[h: roll = 1d20]
[h: dmg1 = eval(wpndmg1)]
[h: att2 = getProperty("Wpn 1 Att 2")]
[h: dmg2 = eval(wpndmg1)]
[h: att3 = getProperty("Wpn 1 Att 3")]
[h: dmg3 = eval(wpndmg1)]
[h: att4 = getProperty("Wpn 1 Att 4")]
[h: dmg4 = eval(wpndmg1)]
[h: fum=0]
[h: err = getProperty("Wpn 1 Error")]
[h: thrt = getProperty("Wpn 1 Threat")]
[r, if(roll >= thrt),CODE:
	{
		<b>Attack:</b><b>CRIT!!!!!</b> [t: roll+att1]<br>
		<b>Damage:</b> [t: dmg1+dmg1+bns1]<br>
	};
	{
	};
]
[r, if(roll <= err),CODE:
	{
		<b>FUMBLE!!!!!</b><br>
		[h: fum=1]
	};
	{
	};
]
[r, if(roll > err && roll < thrt),CODE:
	{
		<b>Attack:</b> [t: roll+att1]<br>
		<b>Damage:</b> [t: dmg1+bns1]<br>
	};
	{
	};
]
[h: roll = 1d20]
[h: check=0]
[r, if(roll >= thrt),CODE:
	{
		[h: check=2]
	};
	{
	};
]
[r, if(roll <= err),CODE:
	{
		[h: check=1]
	};
	{
	};
]
[r, if(att2 > 0 && fum == 0),CODE:{
	[switch(roll), code:
		case 2: {
			<b>Attack:</b><b>CRIT!!!!!</b> [t: roll+att2]<br>
			<b>Damage:</b> [t: dmg2+dmg2+bns1]<br>
		};
		case 1: {
			<b>FUMBLE!!!!!</b><br>
			[h: fum=1]
		};
		default: {
			<b>Attack:</b> [t: roll+att2]<br>
			<b>Damage:</b> [t: dmg2+bns1]<br>
		}]
	};
	{
	};
]
[h: roll = 1d20]
[h: check=0]
[r, if(roll >= thrt),CODE:
	{
		[h: check=2]
	};
	{
	};
]
[r, if(roll <= err),CODE:
	{
		[h: check=1]
	};
	{
	};
]
[r, if(att3 > 0 && fum == 0),CODE:{
	[switch(check), code:
		case 2: {
			<b>Attack:</b><b>CRIT!!!!!</b> [t: roll+att3]<br>
			<b>Damage:</b> [t: dmg3+dmg3+bns1]<br>
  		};
		case 1: {
			<b>FUMBLE!!!!!</b><br>
			[h: fum=1]
 		 };
		default: {
			<b>Attack:</b> [t: roll+att3]<br>
			<b>Damage:</b> [t: dmg3+bns1]<br>
		}]
	};
	{
	};
]
[h: roll = 1d20]
[h: check=0]
[r, if(roll >= thrt),CODE:
	{
		[h: check=2]
	};
	{
	};
]
[r, if(roll <= err),CODE:
	{
		[h: check=1]
	};
	{
	};
]
[r, if(att4 > 0 && fum == 0),CODE:{
	[switch(check), code:
		case 2: {
			<b>Attack:</b><b>CRIT!!!!!</b> [t: roll+att4]<br>
			<b>Damage:</b> [t: dmg4+dmg4+bns1]<br>
  		};
		case 1: {
			<b>FUMBLE!!!!!</b><br>
  		};
		default: {
			<b>Attack:</b> [t: roll+att4]<br>
			<b>Damage:</b> [t: dmg4+bns1]<br>
		}]
	};
	{
	};
]
Any input would be greatly appreciated

ralstad

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Help with weapon attack macro

Post by ralstad »

ok making a small addition to the macro and getting a little headache from it.
Here it is.

Code: Select all

[h: if(att1 == ""),CODE:
	{
	[h: assert(att1 == "", "No bonus entered!", 0)]
	[h: abort(0)]
	}
]
It is popping this error.

Error in body of roll.       
Statement options (if any): h       
Statement Body : if(att1 == ""),CODE: { [h: assert(att1 = "", "No bonus entered!", 0)] [h: abort(0)] }; { };

ralstad

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

Re: Help with weapon attack macro

Post by Full Bleed »

ralstad wrote:
Thu Jul 12, 2018 12:38 am
Ok, thank you everyone that has helped on this macro I believe I have figured everything out that I needed to.
Here is the following code I ended up with what do you guys think?

Code: Select all

[h: att1 = getProperty("Wpn 1 Att 1")]
[h: wpndmg1 = getProperty("Wpn 1 Dmg")]
[h: bns1 = getProperty("Wpn 1 Dmg Bns")]
Any input would be greatly appreciated
You're still using properties with spaces in them.

You're going to have a problem with that.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

Post Reply

Return to “Requests for HELLLLP!”