updating HP bars

Discussion concerning lmarkus' campaign framework for D&D3.x and Pathfinder.

Moderators: dorpond, trevor, Azhrei, giliath, Gamerdude, jay, Mr.Ice, lmarkus001

Forum rules
Discussion regarding lmarkus001's framework only. Other posts deleted without notice! :)
Post Reply
magnus_gallowglass
Kobold
Posts: 11
Joined: Thu Aug 04, 2011 9:50 pm

updating HP bars

Post by magnus_gallowglass »

I created a macro to gather in all tokens with a state of "regen" and heal them all 5 points of non lethal damage to cover NPC regen such as trolls.

Code: Select all

[h: ids=getWithState("regen")]
[h, foreach(id,ids, <br>), code:
{
[h: HPNonLethalDMG = getProperty("HPNonLethalDMG", id)]
[h, if(HPNonLethalDMG-5 > 0): setProperty("HPNonLethalDMG", HPNonLethalDMG-5, id); setProperty("HPNonLethalDMG",max(HPNonLethalDMG-5,0), id) ]
}]
[g: "All tokens on this map with the token state of "regen" just gained 5 hps"]
This works just fine except I realized I didn't make it update the appropriate HP bar for the tokens. This made me realize that I should also make it update states as needed. So I did some digging and found a macro that calls to a lib token which does update the bar/states, the "FullHP" macro which calls "subUpdateHPStatesBars@Lib:libDnD35Pathfinder"

So I *cough* borrowed the code from that macro for mine in the hopes that it would do the trick. With some trial and error the best I can get is an error "Error executing "switchToken": the token name or id "" is unknown."

Here is the modified macro:

Code: Select all

[h: ids=getWithState("regen")]
[h, foreach(id,ids, <br>), code:
{
[h: HPNonLethalDMG = getProperty("HPNonLethalDMG", id)]
[h, if(HPNonLethalDMG-5 > 0): setProperty("HPNonLethalDMG", HPNonLethalDMG-5, id); setProperty("HPNonLethalDMG",max(HPNonLethalDMG-5,0), id) ]
[h:selectTokens(id,0)]
[H: tToken = currentToken() ]
[H, MACRO( "subUpdateHPStatesBars@Lib:libDnD35Pathfinder" ): "Token=" + tToken]
}]
[g: "All tokens on this map with the token state of "regen" just gained 5 hps"]
I've also tried:

Code: Select all

[h: ids=getWithState("regen")]
[h, foreach(id,ids, <br>), code:
{
[h: HPNonLethalDMG = getProperty("HPNonLethalDMG", id)]
[h, if(HPNonLethalDMG-5 > 0): setProperty("HPNonLethalDMG", HPNonLethalDMG-5, id); setProperty("HPNonLethalDMG",max(HPNonLethalDMG-5,0), id) ]
[H: selectTokens(id,0)]
[h,if(HPNonLethalDMG-5>0),code:
	{
	[setBar("HPNonLethalDMG",HPNonLethalDMG-5/HPNonLethalDMG)]
	};
	{
	[setBar("HPNonLethalDMG",0)]
	}]
}]
[g: "All tokens on this map with the token state of "regen" just gained 5 hps"]
This code doesn't give me any errors but also doesn't update the non lethal HP bar :( In all iterations the token's actual HPs are updated, just not the bar.

If someone could give me some guidance into how to either make my macro update the bar directly or get my macro to interface with the lib token properly I would greatly appreciate it.

Thanks
FYI:
I have zero ranks in craft(programming) so whatever crackpot macro I'm posting was made using take 10 and a lot of reading the wiki and forum posts with a dash of borrowing code from other people's macros.

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

Re: updating HP bars

Post by aliasmask »

This is a great idea, but I would do it slightly different. I would make fast healing and regeneration an active mod. Ideally, you would have a start turn button where fast healing would be checked and applied, among other possible effects. Instead of just updating the bar, you should update the hit points which updates the bar. You should look at HP Change, both the Campaign macro and the Lib:libDnD35Pathfinder macro. You can update HP healing without a prompt by calling the macro and setting doinput to 0.

But you can update globally. You would loop through those tokens updating the value by their fast healing or regeneration amounts.

Code: Select all

[H: tokens = getTokens("json",json.set("{}","setStates",json.append("","FastHealing","Regeneration"),"unsetStates",json.append("","Dead")))]
[H: output = ""]
[H, foreach(id,tokens), code: {
   [H: switchToken(id)]
   [H, if(getState("FastHealing")), code: {
      [H: "<!-- get Fast Healing Value -->"]
      [H: value = json.get(json.get(json.get(json.get(json.get(json.get( PrivateJSON, "CustomModSetValues"),"Fast Healing"),"mods"),"globalMod"),"v") ]
      [MACRO("HPChange@Lib:libDnD35Pathfinder"): strformat("Page=Main; doinput=0; HPAmount=%{value}; HPtype=0; Token=%{id}") ]
      [H: output = json.append(output,strformat("<b>%s</b> heals %{value} points",getName(id)))]
   };{
      [H: "<!-- get Regeneration Value -->"]
      [H: value = json.get(json.get(json.get(json.get(json.get(json.get( PrivateJSON, "CustomModSetValues"),"Regeneration"),"mods"),"globalMod"),"v") ]
      [MACRO("HPChange@Lib:libDnD35Pathfinder"): strformat("Page=Main; doinput=0; HPAmount=%{value}; HPtype=3; Token=%{id}") ]
      [H: output = json.append(output,strformat("<b>%s</b> regenerates %{value} points",getName(id)))]
   }]
}]
[R,G: json.toList(output,"<br>")] 
When setting your "FastHealing" and "Regeneration" active mods, just put a variable name in the globalMod text field. I put "Fast_Healing_Value" and "Regeneration_Value" respectively. Don't forget to set your state or this won't work.

You could possible add this to the top of the HP Dying macro, which I would also change to include PCs.

I made the Fast Healing and Regeneration mutually exclusive, but I don't know if there are creatures with both. If there are, then just put in separate if's. I think I'll do that and then post a mod to HP Dying and apply this to my framework.

magnus_gallowglass
Kobold
Posts: 11
Joined: Thu Aug 04, 2011 9:50 pm

Re: updating HP bars

Post by magnus_gallowglass »

Thanks for the reply, much appreciated.
FYI:
I have zero ranks in craft(programming) so whatever crackpot macro I'm posting was made using take 10 and a lot of reading the wiki and forum posts with a dash of borrowing code from other people's macros.

Post Reply

Return to “D&D 3.5/Pathfinder 1e Campaign Macros”