Newbie Macro for initiative

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
malarian
Kobold
Posts: 14
Joined: Sun Jun 12, 2011 11:22 am

Newbie Macro for initiative

Post by malarian »

Dear All
As a wondered for some time now i have launched an old school 2nd edition framework but i am currently working on the initiative panel
- Already experience issues with sorting and find solution here is the code

In the Campagin panel i launch the following macro from a token lib

Code: Select all

[MACRO("StartCombat2@Lib:Combat"):""]
The macro launches the following
1) a little text into the chat

Code: Select all

[H: "<!--Declarations-->" ]
[h:  Titred='<table border="0", width="250px"><tr bgcolor="#1924FF"><td style="padding:0px 5px;" align=center ><span style="color:white">']
[h:  Titred2='<table border="0", width="250px"><tr bgcolor="#0C98FF"><td style="padding:0px 5px;" align=center ><span style="color:white">']
[h:  Titref="</td></tr></table>"]
[h: setLibProperty("Initcount", 1, "Lib:combat")]
[h: Contenu= "Nouveau Combat"]
[h: Contenu2= " Round      "  + "   " +      getLibProperty("Initcount", "lib:combat") + "     "+"     Initiative Nouveau round !" + ]
[r: declaration = Titred + Contenu +Titref]
[r: declaration2 = Titred2 + Contenu2 +Titref]
2) Clearing of the Initiative list

Code: Select all

[h: removeAllFromInitiative()]
[r: declaration3="All Token removed sucessfully"]
3) Define intitiative to round 1
This is achieved via the storage of the current round into a token lib

Code: Select all

[h: round0=getLibProperty("Initcount", "lib:combat")]
[h: setInitiativeRound(round0)]
[r: declaration4="Round set to 1 "]
4) Define the token to be added to inittiative
in this case only add NPC and Non dead (based on statement)

Code: Select all

[h, CODE:{
[h: cond = '{"npc":1, "unsetStates":["Dead"]}']
[h: jsonpions.liste = getTokens("json",cond)]
[h: jsonNPC = jsonpions.liste]
[h: jsonInit = '[]']
}] 
[h: "<!--Definit l initiative: Force + 1d500-->" ]
[h, foreach(id, jsonNPC), CODE:
{
	[h: selectTokens(id,0)]
	[h: genre1 = getProperty('strength',id)]
	[h: genre1 =genre1+1d500]
[h: "<!--Definit le Json pour les PNJ a ajouter dans initiative-->" ]
	[h: jsonInsert = json.set('{}', "id", id, "init", genre1)]
	[h: jsonInit = json.append(jsonInit, jsonInsert)]
}]

[H: "<!--transfert vers token lib-->" ]
[h: setLibProperty("json.init", jsonInit, "Lib:combat")]
[h: json.libb=getLibProperty("json.init", "lib:combat")]

<pre>[r: json.indent(json.libb)]</pre>
Results is the following

[
{
"id": "C0A8010ABF4EFCF0AAA10400C0A8000A",
"init": 335
},
{
"id": "C0A8010ABF4EFCF096A10400C0A8000A",
"init": 433
},
{
"id": "C0A8010ABF4EFCF094A10400C0A8000A",
"init": 451
}
]


After that the intent is where the issues are coming
My project is
1) to be able for every single token listed before to add into a Json annother occurence based on the number of attack for every token
2) to check into token property to retreive informations related to the number of attack and sequence of attack in order to adjust their initiative
3) add these new occurrence to the JSON
4) Use the Json to sort by initiative
5) Add the content to the init panel

let's take an exemple :
Token 1 : Orc with one attack and
Token 2 : Dragon with three attacks
The "json.libb" contains the first occurence for each token
Token 1 : init 10
Token 2 : Init 12

But i would like t o have at the end
Token 1 : init 10 first strike
Token 2 : Init 12 first strike
Token 2 : Init 12+ adj second strike
Token 2 : Init 12+ adj + adj third strike

Is is possible ?

malarian
Kobold
Posts: 14
Joined: Sun Jun 12, 2011 11:22 am

Re: Newbie Macro for initiative

Post by malarian »

I have manage to go a little further but still fail to obtain the expected result

I have tried to create a second json for the additionnal strikes but obtain a failure with selectTokens ==>> HELP !!!

Code: Select all

[h, FOREACH(id, jsonInit), CODE:
{
	[h: selectTokens(id,0)]
	[h: genre1 = getProperty('strength',id)]
	[h: genre1 =genre1+1d5]
[h: "<!--Definit le Json pour les PNJ a ajouter dans initiative-->" ]
	[h: jsonInsert2 = json.set('{}', "id", id, "init", genre1)]
	[h: jsonInit2 = json.append(jsonInit2, jsonInsert2)]
}]

<pre>[r: json.indent(jsonInit2)]</pre>
In fact i dont understand where is my mistake as i can obtain the Id but cannot use them again into my next loop

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

Re: Newbie Macro for initiative

Post by wolph42 »

Code: Select all

[h, FOREACH(id, jsonInit), CODE:{
    <!-- selecttoken is not required for this loop, neither are the h: as you already have one outside -->
   [genre1        = getProperty('strength',id)]
   [genre1        = genre1+1d5]
   [numAttack  = getProperty('numAttack',id)]<!-- or whatever its called -->
    <!-- Definit le Json pour les PNJ a ajouter dans initiative -->
   [count(numAttack): jsonInit2 = json.append(jsonInit2, json.set('{}', "id", id, "init", genre1, "numAttack", roll.count+1))]
}] 

malarian
Kobold
Posts: 14
Joined: Sun Jun 12, 2011 11:22 am

Re: Newbie Macro for initiative

Post by malarian »

Hi wolph42
Thks a lot for your input it is of a lot of help

I still have an issue with the fact that i cannot extract the id ( preharps nested object json insid the array ?)
i obtain invalid expression in a similar way as if it was not possible for the loop to extract the "ID" values from the Json created

here is what is obtained from the resolution of the macro

Code: Select all

« json.get(record,"id") = json.get({"id":"C0A8010ABF4EFCF0AAA10400C0A8000A","init":335}, "id") = C0A8010ABF4EFCF0AAA10400C0A8000A » 
« genre1 = getProperty('strength',id) = Expression: genre1 = getProperty('strength',id) invalide. » 
« genre1 = genre1+1d5 = genre1 = (0 + 1) = 1 » « numAttack = getProperty('#ATTc',id) = Expression: numAttack = getProperty('#ATTc',id) invalide. »   , 
« json.get(record,"id") =
Any idea ?

I have tested the token via

Code: Select all

[r: test=getSelected()]
[r: genre1        = getProperty('Strength',test)]
but result is ok :
C0A8010ABF4EFCF0AAA10400C0A8000A and value for strenght is also ok at 9


Kurghoth
Kobold
Posts: 15
Joined: Fri Aug 22, 2014 4:36 am
Location: Ancona, Italy
Contact:

Re: Newbie Macro for initiative

Post by Kurghoth »

Hi all... this is my first post in here...

I am totally new to maptool and there is one thing I am not able to figure out...

I am using 1.3.b89 version... I tried to create a lib token to store macro following the wiki instuction... but I don't understand what I have to do to store macro in a Lib Token... I saw there was a "macro tab" on the token settings in older version of Map Tool... a tab that is not on the new version... so... how I am supposed to proceed?

:shock:

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

Re: Newbie Macro for initiative

Post by wolph42 »

Kurghoth wrote:Hi all... this is my first post in here...

I am totally new to maptool and there is one thing I am not able to figure out...

I am using 1.3.b89 version... I tried to create a lib token to store macro following the wiki instuction... but I don't understand what I have to do to store macro in a Lib Token... I saw there was a "macro tab" on the token settings in older version of Map Tool... a tab that is not on the new version... so... how I am supposed to proceed?

:shock:
1. create a lib:token (e.g. lib:myMacros)
2. make sure the 'selection' panel is open
3. right mouse click on the 'selection panel'
4. click 'new macro'
5. right mouse click on the new macro and then 'edit macro'
dont forget to save.

Kurghoth
Kobold
Posts: 15
Joined: Fri Aug 22, 2014 4:36 am
Location: Ancona, Italy
Contact:

Re: Newbie Macro for initiative

Post by Kurghoth »

I finally got it... ty so much... I have two choice now... Study by myself or ask you any question that come into my mind...

I will choose the first one don't worry...

:D

malarian
Kobold
Posts: 14
Joined: Sun Jun 12, 2011 11:22 am

Re: Newbie Macro for initiative

Post by malarian »

Dear wolph42 and other silencers

Sometime you are proud to be able to achieve what you are doing
This is the case for me with the init so please find herafter the rest of the code

Code: Select all

[h: json.libb=getLibProperty("json.init", "lib:combat")]

[h: "<!--Definit les init de chacun des token listes dans Json libb et ajoute une nouvelle serie d'init-->" ]
[h: jsonInit1 = '[]']
[h: jsonInit2 = '[]']
I have discovered that in order to avoid issue during the FOREACH loop it was necessarry to declare the two jsons

Code: Select all

[h, FOREACH(item, json.libb), CODE:{
	[current = json.get(item, "id")]
	[current2 = json.get(item, "init")]
	[genre1        = getProperty('Strength',current)]
	[numAttack  = getProperty('ATTc',current)]
	[numAttack  = numAttack-1]
	[count(numAttack), code: {
		[genre3 = genre1*(roll.count+1)]
		[genre4 = genre3+current2]
		[jsonInit2 = json.append(jsonInit2, json.set('{}', "id", current, "init", genre4, "numAttack", roll.count+1, "adjustinit",genre3))]
		}]
}]
count is used to add one copy of each token based on the number of attack ( ATTc) they have
Inside this loop i retreive precious information for the initiative ( Strenght value and also the initial init as defined in the begining of the code included in above messages)

Code: Select all

[h: "<!--Ajoute des duplicate des token avec une nouvelle inititative-->" ]
[h: jsonInitfinal = json.merge(jsonInit2,json.libb)]
json.merge is used in order to create multiple occurence of the same token inside one Json Array containing initiative adjusted for each attack ( each attack is delayed of the streght value)

Code: Select all

[h: "<!--Sorting of the Json by initiative value ascending-->" ]
[h: jsonInitfinal = json.sort(jsonInitfinal, "ascending", "init")]

Code: Select all

[h: "<!--Add all the occurence into the init panel   -->" ]
[h, FOREACH(item1, jsonInitfinal), CODE:{
[current1 = json.get(item1, "id")]
[value1 = json.get(item1, "init")]
[switchtoken(current1)]
[addToInitiative(1,value1)]
}]
Here i have search a lot for being able to set initiative only to some of the occurence this is achieved by [addToInitiative(1,value1)] where the 1 is for allowing duplicates and the values of each token, to be added. I encountred the fact that is is mendatory to set initiative straight away as if you use setinitiative() insttead it doesnt work as expected

Hope it will helps

Post Reply

Return to “Macros”