[HELP] Token Movement

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
Eriun
Kobold
Posts: 5
Joined: Fri May 25, 2012 7:57 pm

[HELP] Token Movement

Post by Eriun »

Hi

Can I limit the movement of the characters to 4 squares at a time?

How I do it?


Thx.

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

Re: [HELP] Token Movement

Post by aliasmask »

Well, the answer is no and yes. MT doesn't have a way to limit movement that way, but it's possible to write some code to do that. BUT... it's not easy to do. I've been meaning to do this in one form or another but I have been putting it off.

User avatar
Bone White
Great Wyrm
Posts: 1124
Joined: Tue Aug 23, 2011 11:41 am
Location: Cornwall, UK

Re: [HELP] Token Movement

Post by Bone White »

A slightly modified snippet of code from my framework (which CIF was rather impressed by iirc).

[code=php][h: usedMove = getMoveCount()]
[h: abort(usedMove)]
[h: isLibToken =  if (substring(getName(getSelected()),0,4) == "Lib:", 1, 0)]
[h: abort(! isLibToken)]

[h, if (tokens.moveCount !=1), code: {
    [h: tokens.denyMove=1]
    [h: abort(0)]};{}]

[h: initiativeList = getInitiativeList()]
[h: tokens = json.get(initiativeList,"tokens")]

[h, if(json.isEmpty(tokens)), code :{ [h: abort(0)]};{}]

[h: selected = getSelected()]

[h, token(selected): canNotMove = bitwiseor(getState("Dead"),getState("Unconcious (Wound)"),getState("Unconcious (Stun)"))]
[h, if(canNotMove), code: 
    {
    [h: tokens.denyMove = 1]
    [h: broadcast("You are incapacitated!",getPlayerName())]
    };{
    }
]

[h, if(usedMove > 4), code: {
    [h: tokens.denyMove = 1]
    [h: broadcast("You cannot sprint this far!",getPlayerName())]
    };{
    }
] [/code]

Eriun
Kobold
Posts: 5
Joined: Fri May 25, 2012 7:57 pm

Re: [HELP] Token Movement

Post by Eriun »

Where I put this code?

User avatar
Bone White
Great Wyrm
Posts: 1124
Joined: Tue Aug 23, 2011 11:41 am
Location: Cornwall, UK

Re: [HELP] Token Movement

Post by Bone White »

In a macro named onTokenMove on a Lib:token

Eriun
Kobold
Posts: 5
Joined: Fri May 25, 2012 7:57 pm

Re: [HELP] Token Movement

Post by Eriun »

Thx so much.

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

Re: [HELP] Token Movement

Post by wolph42 »

Bone White wrote:A slightly modified snippet of code from my framework (which CIF was rather impressed by iirc).
I like this! I think I will add the move limiter as an option to the bag of tricks. Note though that this code is executed EVERY move so its vital that you try to get it as speedy as possible. Now its a rather small piece of code so I don't think you'll notice any difference but its good practice anyway. Here a couple of suggestions to get it a bit more snappier:

EDIT: below code is updated There are some bugs bonewhites code and there were some in mine, I've debugged, commented and streamlined the code

Code: Select all

<!-- set maximum allowed movement -->
[h: maxMove = 4]
<!-- get move number of moved token -->
[h: usedMove = getMoveCount()]

<!-- abort when total move is 0 -->
[h: abort(usedMove)]
<!-- abort when token is a lib (only check the first token if multiple are selected) -->
[h: abort(!startsWith(lower(getName(listGet(getSelected(),0))), "lib:"))]
<!-- abort when GM -->
[h: abort(isGM())]
<!-- abort when initiative panel is empty -->
[h: abort(!json.isEmpty(json.get(getInitiativeList(),"tokens")))]


<!-- revert move when multiple tokens are moved -->
[h, if (tokens.moveCount !=1), CODE: {
    [tokens.denyMove = 1]
    [broadcast("Please only move 1 token at a time",getPlayerName())]
};{}]

<!-- revert move when token cannot move -->
[h, token(getSelected()), if(getState("Dead") || getState("Incapacitated")), CODE: {
    [tokens.denyMove = 1]
    [broadcast("You are incapacitated!",getPlayerName())]
};{}]

<!-- revert move when moved over the move limit -->
[h, if(usedMove > maxMove), CODE: {
    [h: tokens.denyMove = 1]
    [broadcast("You moved " + usedMove + ". The max allowed moved is: "+maxMove+"!",getPlayerName())]
};{}]  
By the way I like this line, interesting method I certainly need to keep in mind:

Code: Select all

[h, token(getSelected()): canNotMove = bitwiseor(getState("Dead"),getState("Unconcious (Wound)"),getState("Unconcious (Stun)"))] 
edit: ah yes the bugs in BW code:
- this combo:

Code: Select all

[tokens.denyMove=1][abort(0)]
does not work as the abort prevents the denyMove from ever being executed
- this line:

Code: Select all

[if (substring(getName(getSelected()),0,4) == "Lib:", 1, 0)]
will generate an error when the length(name) is < 4, e.g. "Elf", "Ork", "Man", etc..

edit: updated my bag of tricks to support this feature.

User avatar
Bone White
Great Wyrm
Posts: 1124
Joined: Tue Aug 23, 2011 11:41 am
Location: Cornwall, UK

Re: [HELP] Token Movement

Post by Bone White »

wolph42 wrote:
Bone White wrote:A slightly modified snippet of code from my framework (which CIF was rather impressed by iirc).
I like this! I think I will add the move limiter as an option to the bag of tricks...
Me after reading this post
wolph42 wrote:By the way I like this line, interesting method I certainly need to keep in mind:

Code: Select all

[h, token(getSelected()): canNotMove = bitwiseor(getState("Dead"),getState("Unconcious (Wound)"),getState("Unconcious (Stun)"))]
It was the simplest way to do what I wanted.
wolph42 wrote:- this combo:

Code: Select all

[tokens.denyMove=1][abort(0)]
does not work as the abort prevents the denyMove from ever being executed
This if block will never trigger as I later discovered that onMultipleTokenMove is a different macro, and will not run when there is more than one token anyway...
wolph42 wrote:- this line:

Code: Select all

[if (substring(getName(getSelected()),0,4) == "Lib:", 1, 0)]
will generate an error when the length(name) is < 4, e.g. "Elf", "Ork", "Man", etc..
Thanks for this, will bulletproof against it now.

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

Re: [HELP] Token Movement

Post by wolph42 »

Bone White wrote:
wolph42 wrote:
Bone White wrote:A slightly modified snippet of code from my framework (which CIF was rather impressed by iirc).
I like this! I think I will add the move limiter as an option to the bag of tricks...
Me after reading this post
ROFLMAO !!

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Re: [HELP] Token Movement

Post by jfrazierjr »

Bone White wrote:
wolph42 wrote:- this combo:

Code: Select all

[tokens.denyMove=1][abort(0)]
does not work as the abort prevents the denyMove from ever being executed
This if block will never trigger as I later discovered that onMultipleTokenMove is a different macro, and will not run when there is more than one token anyway...
Errr... wait... not sure if I am reading this wrong(I did not read the actual code to know what it does), but just to make sure you know/understand, BOTH "events" fire when there are multiple tokens moved. First onTokenMove is done for each token moved and then after that has completed(for all moving tokens that satisfy criteria X, which I think isPC = true and isVisible= true IIRC), onMultipleTokensMove fires with all the selectedTokens passed as an input argument . It is up to the macro author to know and possibly abort if needed(which It looks like you are doing, but I would suggest putting that at the VERY top.. no use doing more work than you need to)
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

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

Re: [HELP] Token Movement

Post by wolph42 »

Yes I know. However the point of this macro was to revert the move if multiple tokens are moved. Which in its original version did not work because of the abort.

So just abort on top in case of multiple move will not revert the move.

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Re: [HELP] Token Movement

Post by jfrazierjr »

wolph42 wrote:Yes I know. However the point of this macro was to revert the move if multiple tokens are moved. Which in its original version did not work because of the abort.

So just abort on top in case of multiple move will not revert the move.
Oh.. duh... ummm... the master programmer just forgot that part...lol
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

agentken
Kobold
Posts: 1
Joined: Mon Feb 01, 2016 4:12 pm

Re: [HELP] Token Movement

Post by agentken »

Hello all,

New to MapTools, was looking for a way to limit movement. Your Macro seems to have done it

Great macro! Thanks :)

Modified the first (actually second line)
from
[h: maxMove = 4]

to

Code: Select all

<!-- set maximum allowed movement -->
[h: maxMove = getProperty("Movement")]
That way i can set per token movement rules :) (as a attribute " movement" )


Post Reply

Return to “MapTool”