[HELP] Token Movement
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.
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.
[HELP] Token Movement
Hi
Can I limit the movement of the characters to 4 squares at a time?
How I do it?
Thx.
Can I limit the movement of the characters to 4 squares at a time?
How I do it?
Thx.
Re: [HELP] Token Movement
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.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
- Bone White
- Great Wyrm
- Posts: 1124
- Joined: Tue Aug 23, 2011 11:41 am
- Location: Cornwall, UK
Re: [HELP] Token Movement
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]
[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]
Re: [HELP] Token Movement
Where I put this code?
- Bone White
- Great Wyrm
- Posts: 1124
- Joined: Tue Aug 23, 2011 11:41 am
- Location: Cornwall, UK
Re: [HELP] Token Movement
In a macro named onTokenMove on a Lib:token
Re: [HELP] Token Movement
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:Bone White wrote:A slightly modified snippet of code from my framework (which CIF was rather impressed by iirc).
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())]
};{}]
Code: Select all
[h, token(getSelected()): canNotMove = bitwiseor(getState("Dead"),getState("Unconcious (Wound)"),getState("Unconcious (Stun)"))]
- this combo:
Code: Select all
[tokens.denyMove=1][abort(0)]
- this line:
Code: Select all
[if (substring(getName(getSelected()),0,4) == "Lib:", 1, 0)]
edit: updated my bag of tricks to support this feature.
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
- Bone White
- Great Wyrm
- Posts: 1124
- Joined: Tue Aug 23, 2011 11:41 am
- Location: Cornwall, UK
Re: [HELP] Token Movement
Me after reading this postwolph42 wrote:I like this! I think I will add the move limiter as an option to the bag of tricks...Bone White wrote:A slightly modified snippet of code from my framework (which CIF was rather impressed by iirc).
It was the simplest way to do what I wanted.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)"))]
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 combo:does not work as the abort prevents the denyMove from ever being executedCode: Select all
[tokens.denyMove=1][abort(0)]
Thanks for this, will bulletproof against it now.wolph42 wrote:- this line:will generate an error when the length(name) is < 4, e.g. "Elf", "Ork", "Man", etc..Code: Select all
[if (substring(getName(getSelected()),0,4) == "Lib:", 1, 0)]
Re: [HELP] Token Movement
ROFLMAO !!Bone White wrote:Me after reading this postwolph42 wrote:I like this! I think I will add the move limiter as an option to the bag of tricks...Bone White wrote:A slightly modified snippet of code from my framework (which CIF was rather impressed by iirc).
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
- jfrazierjr
- Deity
- Posts: 5176
- Joined: Tue Sep 11, 2007 7:31 pm
Re: [HELP] Token Movement
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)Bone White wrote: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 combo:does not work as the abort prevents the denyMove from ever being executedCode: Select all
[tokens.denyMove=1][abort(0)]
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..
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..
Re: [HELP] Token Movement
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.
So just abort on top in case of multiple move will not revert the move.
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
- jfrazierjr
- Deity
- Posts: 5176
- Joined: Tue Sep 11, 2007 7:31 pm
Re: [HELP] Token Movement
Oh.. duh... ummm... the master programmer just forgot that part...lolwolph42 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.
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..
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..
Re: [HELP] Token Movement
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
That way i can set per token movement rules (as a attribute " movement" )
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")]
Re: [HELP] Token Movement
Hi,
You can also opt to install the bag of tricks. I've implemented that code in there.
You can also opt to install the bag of tricks. I've implemented that code in there.
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS