How can I change the order of tokens with the same init val?

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

Post Reply
ZenCorrosion
Kobold
Posts: 15
Joined: Thu Mar 05, 2015 4:31 pm

How can I change the order of tokens with the same init val?

Post by ZenCorrosion »

I'm working on a custom framework and I want the PC tokens to always go before the NPCs, even when they have the same initiative value. It looks like this is kind of possible in the sense that if two tokens (A & B) have the same initiative value, the first one added to initiative will go first.

However, during combat a PC's initiative value can change and after sorting, gets put after the NPCs with the same value.

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

Re: How can I change the order of tokens with the same init

Post by aliasmask »

The way we do initiative is to add the dex mod as a decimal value so if their init is 12 with a dex of 2 then their init is 12.02. If you want to let PCs go first on ties, then maybe you can add .005 to pc tokens.

ZenCorrosion
Kobold
Posts: 15
Joined: Thu Mar 05, 2015 4:31 pm

Re: How can I change the order of tokens with the same init

Post by ZenCorrosion »

Hmm, that's kind of funny, but I guess it would work. Thanks!

User avatar
Irrlicht
Dragon
Posts: 426
Joined: Mon Feb 09, 2009 10:53 am

Re: How can I change the order of tokens with the same init

Post by Irrlicht »

For extreme initiative sorting, I do this:

[h: random_roll = 1d10000]
[h: setInitiative(eval(getInitiative()) + (token_init_bonus * 0.00001) + (token_Dex * 0.000000001) + (random_roll * 0.00000000000001))]

(So, in case of ties, the highest initiative bonus goes first; if there's still a tie, the highest Dex bonus; and in the extreme case of a further tie, the result of the random roll.)

Then sort initiative, and after it's sorted I take the values again to trim them with floor(), so that the Initiative panel only shows the normal results with no decimals but the order is kept.
"There are many ways my Son, to find where the souls of Demons remain...
But it takes only one second of despair and of doubt until, at last, your Soul they will gain..."

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

Re: How can I change the order of tokens with the same init

Post by Full Bleed »

Irrlicht wrote:Then sort initiative, and after it's sorted I take the values again to trim them with floor(), so that the Initiative panel only shows the normal results with no decimals but the order is kept.
Nifty idea to trim after sorting... didn't think I could do that. I use the method Alias mentions above... but it does look weird with the decimal.

You should share that snippet of code. I think a trimInitiative() UDF would be pretty useful.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

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

Re: How can I change the order of tokens with the same init

Post by aliasmask »

I like the decimal. Everyone gets to see the the dex/init modifier.

User avatar
Irrlicht
Dragon
Posts: 426
Joined: Mon Feb 09, 2009 10:53 am

Re: How can I change the order of tokens with the same init

Post by Irrlicht »

Full Bleed wrote:
Irrlicht wrote:Then sort initiative, and after it's sorted I take the values again to trim them with floor(), so that the Initiative panel only shows the normal results with no decimals but the order is kept.
Nifty idea to trim after sorting... didn't think I could do that. I use the method Alias mentions above... but it does look weird with the decimal.

You should share that snippet of code. I think a trimInitiative() UDF would be pretty useful.
My initiative macro, after doing all it does, calls for this other macro (I guess you guys, who are much better at coding than me, can come up with shortest/simpler variants, but here's mine... besides, I wrote it maybe three years ago or more, and it remained untouched since):

Code: Select all


[h: initiative_List = getInitiativeList()]

[h: token_List = json.get(initiative_List, "tokens")]

[h: initiative_List = ""]
[h: id_List = ""]
[h, foreach(token, token_List),code:
{
   [h: token_init = json.get(token, "initiative")]
   [h: initiative_List = listAppend(initiative_List, token_init)]

   [h: id = json.get(token, "tokenid")]
   [h: id_List = listAppend(id_List, id)]
}]

[h: index = 0]
[h, foreach(value, initiative_List), code:
{
   [h: how_Many = listContains(initiative_List, value)]
   [h, if(how_Many > 1), code:
   {
      [h: id = listGet(id_List, index)]
      [h: switchtoken(id)]
      [h: token_init_bonus = getProperty("initiative", id)]
      [h: token_Dex = getProperty("dex", id)]
      [h: random_roll = 1d10000]
      [h: setInitiative(eval(getInitiative()) + (token_init_bonus * 0.00001) + (token_Dex * 0.000000001) + (random_roll * 0.00000000000001))]
   }]

   [h: index = index + 1]
}]

[h: sortInitiative()]

[h: index = 0]
[h, foreach(value, initiative_List), code:
{
   [h: how_Many = listContains(initiative_List, value)]
   [h, if(how_Many > 1), code:
   {
      [h: id = listGet(id_List, index)]
      [h: switchtoken(id)]
      [h: setInitiative(value)]
   }]

   [h: index = index + 1]
}]

Oh, and I just noticed that I don't use floor(), but simply set the original value with no decimal after the one with decimals has been set and ordered... but well, the result is the same.
"There are many ways my Son, to find where the souls of Demons remain...
But it takes only one second of despair and of doubt until, at last, your Soul they will gain..."

ZenCorrosion
Kobold
Posts: 15
Joined: Thu Mar 05, 2015 4:31 pm

Re: How can I change the order of tokens with the same init

Post by ZenCorrosion »

Cool idea on trimming the init value to get rid of the decimal. Thanks for sharing!

Post Reply

Return to “Macros”