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.
How can I change the order of tokens with the same init val?
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
-
- Kobold
- Posts: 15
- Joined: Thu Mar 05, 2015 4:31 pm
Re: How can I change the order of tokens with the same init
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.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
-
- Kobold
- Posts: 15
- Joined: Thu Mar 05, 2015 4:31 pm
Re: How can I change the order of tokens with the same init
Hmm, that's kind of funny, but I guess it would work. Thanks!
Re: How can I change the order of tokens with the same init
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.
[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..."
But it takes only one second of despair and of doubt until, at last, your Soul they will gain..."
- 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
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.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.
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."
Re: How can I change the order of tokens with the same init
I like the decimal. Everyone gets to see the the dex/init modifier.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: How can I change the order of tokens with the same init
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):Full Bleed wrote: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.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.
You should share that snippet of code. I think a trimInitiative() UDF would be pretty useful.
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]
}]
"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..."
But it takes only one second of despair and of doubt until, at last, your Soul they will gain..."
-
- Kobold
- Posts: 15
- Joined: Thu Mar 05, 2015 4:31 pm
Re: How can I change the order of tokens with the same init
Cool idea on trimming the init value to get rid of the decimal. Thanks for sharing!