Page 1 of 1

Is this possible?

Posted: Mon May 08, 2017 11:36 pm
by xavram
I have a "Done with Turn" macro that when the players are done, advances the initiative and handle a bunch of stuff (state checks, damage from bleeding, advances spell duration, etc, etc). Works just fine, except for one thing. I call switchToken during it but that means the players end up NOT having their token selected. And of course, that irritates them, since we use strict token ownership. So each time it goes from one of their turns to someone else's, that player has to re-select his token.

But, from a DM perspective, its great that it switches to the token with initiative because then I'm all set to perform the action for the next NPC.

So my question is...is there some way to switchToken for the DM...but for the players, keep selection on the token they're already on?

This is probably very wishful thinking but I thought I'd ask.

Re: Is this possible?

Posted: Tue May 09, 2017 2:42 am
by wolph42
first of all switchtoken() is a temporary function that only applies to the macro its run in. It has nothing to do with selection of a token.

now just to be clear: you want a macro that does stuff and when it ends it:
1. selects the token of the user that pressed the button and
2. on the GM client it selects the token that is next in initiative?

is that correct?

that is possible. but not really easy.

Re: Is this possible?

Posted: Tue May 09, 2017 3:40 am
by aliasmask
Which tokens other players select are not effected by another players actions. Each client keeps a record of their own selections. But it's possible to force a selected token with Wiki: selectTokens(), but it has to be run from that client, not the person who ran the macro. This can be done by sending a link to chat to that client that makes the select command. You'll end up with some whitespace or you can someone incorporate it in to your end of turn macro.

pseudo-code:
player A selects end of turn
macro runs updating various things for that players token
link sent to player who controls token next in initiative with autoexecute on
macro runs beginning of turn functions including setting the currently token to be selected

Re: Is this possible?

Posted: Tue May 09, 2017 12:42 pm
by xavram
Maybe I need to look at my "Done with Turn" macro and see if I'm forcing the "selection" issue due to an error on my part. I had thought the "switchToken" was doing it but if that's not the case, then it must be something I'm doing in the code.

Re: Is this possible?

Posted: Tue May 09, 2017 7:39 pm
by xavram
I did have a "selectToken" in there!

Okay, so I took that out and at the end of my "Done with Turn" macro, I added this...

[h, if(isNPC()), code : {
[h: selectText = macroLink("", "SelectInitNpc@Lib:PC_CombatMacros")]
[broadcast(selectText, "gm")]
}]

The "SelectInitNPC" is pretty simple just...

[h : selectTokens(getInitiativeToken())]

...however, nothing happens. I put in a broadcast in "SelectInitNPC", before the selectTokens, but that never displays either. So I must be doing something incorrect and I'd assume its in the macroLink stuff since I have limited experience with that.

Any ideas?

Re: Is this possible?

Posted: Tue May 09, 2017 7:53 pm
by aliasmask
Make sure SelectInitNpc has autorun on. Also, you can't autorun your own macros. You can only autorun for other clients. If the player is the same then use execLink rather than broadcasting it to chat.

Re: Is this possible?

Posted: Tue May 09, 2017 8:01 pm
by xavram
So, tried it like...

[h, if(isNPC()), code : {
[h: selectText = macroLink("", "SelectInitNpc@Lib:PC_CombatMacros")]
[h : execLink(selectText)]
}]

No luck, nothing happens.

And when you say, "Make sure SelectInitNpc has autorun on", I assume you're talking about the "Auto Execute" checkbox. With it checked or unchecked, doesn't work.

Re: Is this possible?

Posted: Tue May 09, 2017 11:20 pm
by aliasmask
Here's what I did:

Code: Select all

@@ @Next

<!-- advance the initiative to the next token and change the selection to that token for the owner of that token -->

[H: nextInitiative()]
[H: id = getInitiativeToken()]
[H: owners = getOwners("json",id)]
[H, if(json.isEmpty(owners)): owner = json.get(getInfo("server"),"gm"); owner = owners]
[H, if(json.isEmpty(owner)): owner = getPlayerName(); owner = json.get(owner,0)]

[H, if(owner == getPlayerName()): selectTokens(id); broadcast("Select Token" + macroLink("","SelectNext@"+getMacroLocation(),"none",json.append("[]",id),id) + "...",owner)]


!!
@@ @SelectNext

[H: id = arg(0)]
[H: selectTokens(id)]

!!
 
It doesn't check all the possible situations like an owner that doesn't exist, but it works for me.

The test campaign allow you to check the owner of the token and it will change the selection when it's their turn. Defaults to the first gm of campaign if no owner selected. Does nothing if owner of token not in game.

Re: Is this possible?

Posted: Wed May 10, 2017 10:38 am
by xavram
I'll play around with this tonight, thanks!

Re: Is this possible?

Posted: Wed May 10, 2017 5:47 pm
by xavram
You the man AM! Minor tweak and its working like a charm!

Thanks!