Help Making Macro (MapTools 1.3b89)

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

McSpazz
Cave Troll
Posts: 32
Joined: Fri Sep 09, 2016 7:37 pm

Re: Help Making Macro (MapTools 1.3b89)

Post by McSpazz »

In the for loop, would it start out as this, right?

foreach(resistName, checkBoxes){

...

}

Once within, however, I'm unsure how I'd refer to the check boxes verses the resist name. Or would it just be as simple as comparing the resistName and CheckBoxes directly?

Also, as there's no such thing as "all" type damage (simply a resistance to all), is there any way I could keep All in resistNames but not display an "all" checkbox?

EDIT: Nevermind on that last question. I figured it'd be easier to just remove all from the resist names list and add two lines after the foreach loop that handles resist all.

McSpazz
Cave Troll
Posts: 32
Joined: Fri Sep 09, 2016 7:37 pm

Re: Help Making Macro (MapTools 1.3b89)

Post by McSpazz »

This is what I have so far...not sure if it works or not, still needs testing. I post this for public consumption!

EDIT: Forgot a close bracket. I'm now getting errors at the very start of the for each loop. I have a few statements trying to output the contents of values but no luck yet.
Spoiler

Code: Select all

[H: resistNames = "Acid,Poison,Cold,Fire,Force,Thunder,Lightning,Necrotic,Radiant,Psychic"]
EDIT 2: HA! I found the problem! I was using the json.get function when I didn't need to. As far as I can tell, this is fully functional now!
[H: checkboxes = listFormat(resistNames,"%list","check%item|0|%item Resistance|CHECK","##")]
[H: abort(input(
   "hpChange|0|Incoming Damage",
   checkboxes
))]
<!--
This macro takes the incoming damage and damage type as input and outputs damage based on resistance modifications.
Resistance is considered to be all numbers greater than zero and vulnerabilities are all numbers less than zero.
If the damage is typed and you have no vulnerabilities or resistances, you take full damage.
If the damage is untyped (nothing checked), resist/vulnerable will still be considered
If a targeted damage type has no resistance or vulnerability, all resistances are negated.
All vulnerabilities override all resistances (including resist all)
Resistance and vulnerability will default to the lowest value which is not zero.
-->
[h:resisted = 0]
[h:vulnerable = 0]
[h:resistBit = 0]
[H, foreach(resistName,resistNames),code:{
	[r:resistName]
	[h: checker = eval("check"+resistName)]
	[r: checker]
	[H: baseValue = eval("baseResist"+resistName)]
	[H: modValue = eval("modResist"+resistName)]
	[H: compValue = if(modValue != 0,modValue,baseValue)]
	[if(checker == 1),code:{
		[h: resistBit = if(compValue < 0 || resistBit == 1,1,0)]
		[h: resisted = if(resistBit == 0,if(resisted == 0,compValue,min(resisted,compValue)),if(resisted > 0,0,min(resisted,compValue)))]
	};{}]
}]
<!--
Check for resist all override.
If resisted is greater than or equal to zero:
	If resist all is greater than or equal to zero, add to resistance.
	If resist all is less than zero, override resisted with below zero value
If resisted is less than zero
	If resist all is less than zero, add to vulnerability
	If resist all is greater than or equal to zero, change nothing
-->
[H: compValue = if(modResistAll != 0,modResistAll,baseResistAll)]
[H: resisted = if(resisted >= 0,if(compValue >= 0,resisted + compValue,compValue),if(compValue < 0,resisted - compValue,resisted))]
<!--
Calculate HP change.
Subtract final resistance modification from the change in HP
Ensure you cannot GAIN health by taking damage (ie: someone trying to input a negative value)
Calculate damage to temp HP to be taken out of final damage to HP
Remove calculated damage from both HP and temp HP and adjust token's health bar.
-->
[h:resisted = min(hpChange,resisted)]
[h:hpChange = hpChange - resisted]
[h:hpChange = if(hpChange < 0,0,hpChange)]
[h:dmgToTemp = min(hpChange,TempHP)]
[h:HP = HP - (hpChange - dmgToTemp)]
[h:TempHP = TempHP - dmgToTemp]
[h:bar.Health = HP / MaxHP]
<!--
Set necessary states. Bloodied at 1/2 HP (halo), incapacitated at 0 or lower, dead at negative 1/2 HP.
Output damage and resisted 
-->
[if(HP <= -(maxHP/2)),code:{
	[h:state.Incapacitated = 0]
	[h:token.halo = "none"]
	[h:state.Dead = 1]
};{
	[h:token.halo = if(HP <= MaxHP/2,"red","None")]
	[h: state.Incapacitated = if(HP <= 0,1,0)]
}]
[r:token.name] loses [r:hpChange - dmgToTemp] hit points, [r:dmgToTemp] temp HP, and resisted [r:resisted]

McSpazz
Cave Troll
Posts: 32
Joined: Fri Sep 09, 2016 7:37 pm

Re: Help Making Macro (MapTools 1.3b89)

Post by McSpazz »

Two more questions.

1: Is there any way I could streamline the properties a bit? It's not super important if everything works, but down the line I wouldn't mind it if I didn't have to use a bajillion properties to set a token's base and temporary resistances.

2: My party doesn't need the whole print-out in the chat window of all of our resistances. What do I remove from the resistance macro to just do the macro and not print anything out? It's a bit more complicated than the damage macro and I'm not sure what's doing that print out.

Thanks again for all of your help!!! After I suss out the second two questions, I plan on adding the finished macros to the original post so people doing searches don't have to spend ages looking.

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Help Making Macro (MapTools 1.3b89)

Post by aliasmask »

I'm going to be super busy with my own coding this week and starting a new campaign. Perhaps someone else can field your questions.

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

Re: Help Making Macro (MapTools 1.3b89)

Post by wolph42 »

so its up to me then...

one thing on your final code: ALWAYS make sure that you NEVER have one ' in the code. Always use them in 'pairs' or don't use them at all. They're especially finicky in comments (they can really screw up you're code!!)

As for your questions. You do not need to define the properties! If you want to create (and read) undefined properties use g/setProperty(). This way you can create 'hidden' properties on tokens.

If you really want to remove them, your options are:
json.objects or
strPropList.
The former has the advantage that you don't really need to think about the content, the latter is easy to use and superfast!

You're 2nd question is a bit hard to understand, so here my interpretation:
When you use the resistance macro you don't want anything showing up in the chat!

Couple of ways:
1. you can Wiki: defineFunction() the function and then set output to '0' (no output).
2. when you call the macro you use [h:...]
3. [h:hide] everything inside the macro INCLUDING [h:'<!-- any comment -->']
4. bluntly put a [h:abort(0)] at the end of the code, this will trash all output to chat
The exception to all of the above is: Wiki: broadcast()

Post Reply

Return to “Macros”