How can count how many tokens have the same GM name on a map ?

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
User avatar
Tymophil
Kobold
Posts: 15
Joined: Mon May 25, 2020 2:33 am

How can count how many tokens have the same GM name on a map ?

Post by Tymophil »

Hi all maptoolers,

The titles says it all...
I need to count how many "goblins" (the token label) are on the map and compare it to the number of PCs. How can I do that ?

Thanks.

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

Re: How can count how many tokens have the same GM name on a map ?

Post by aliasmask »

It's going to involve Wiki: getTokens(), but the details depends on the naming convention and some other things. For example, is it a big map with a lot of different creatures or is just 1 encounter map. Will/Can the creature label have other things like multiple types? What's the reason for getting this number? What about other token states like "dead" or visible to players?

User avatar
Tymophil
Kobold
Posts: 15
Joined: Mon May 25, 2020 2:33 am

Re: How can count how many tokens have the same GM name on a map ?

Post by Tymophil »

aliasmask wrote:
Sun Nov 17, 2024 6:04 pm
It's going to involve Wiki: getTokens(), but the details depends on the naming convention and some other things. For example, is it a big map with a lot of different creatures or is just 1 encounter map. Will/Can the creature label have other things like multiple types? What's the reason for getting this number? What about other token states like "dead" or visible to players?
Okay, so I need to add a little bit of context...

I am a Maptool newbie, trying to produce a framework for 13th Age. In this D&D-like game the Goblin Warriors do more damage when the Goblins (of any kind) outnumber the PCs.
According to the 13th Age rules, the Goblins have a type: Humanoid. So I gave to all my Goblins tokens the label "Goblin".
On a given map, I need to know if the Goblins (excluding the dead ones) outnumber the PCs, to increase the damage of the Goblin Warriors attacks.

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

Re: How can count how many tokens have the same GM name on a map ?

Post by aliasmask »

You could count the goblins in the initiative to generate a bonus for the warriors. This calculation would only happen on the Goblin Warrior token when calculating damage. The pseudo-code would be something like this.

<!-- check goblin warrior bonus damage -->
Am I a goblin warrior
Do I have advantage
getInit List
if PCcount - GoblinCount > 0, then give bonus

User avatar
Tymophil
Kobold
Posts: 15
Joined: Mon May 25, 2020 2:33 am

Re: How can count how many tokens have the same GM name on a map ?

Post by Tymophil »

aliasmask wrote:
Mon Nov 18, 2024 5:50 am
You could count the goblins in the initiative to generate a bonus for the warriors. This calculation would only happen on the Goblin Warrior token when calculating damage. The pseudo-code would be something like this.

<!-- check goblin warrior bonus damage -->
Am I a goblin warrior
Do I have advantage
getInit List
if PCcount - GoblinCount > 0, then give bonus
The "goblin" information is the label of the token. How can I get the "GoblinCount" part of your macro?

I found how to get the PCcount, but I cannot do the same with the label.

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

Re: How can count how many tokens have the same GM name on a map ?

Post by aliasmask »

Code: Select all

[H: tokenIds = json.path.read(getInitiativeList(),"\$..tokenId","ALWAYS_RETURN_LIST,SUPPRESS_EXCEPTIONS")]
[H: goblins = 0]
[H, foreach(tokenId,tokenIds), code: {
   [H: switchToken(tokenId)]
   [H, if(getTokenLabel() == "goblin"): goblins = goblins +1]
}]
More error checking and other things can be done, but this is the basic part.

Post Reply

Return to “MapTool”