PDA

View Full Version : Get distance between Token and Target in LUA



Old Man
June 13th, 2017, 10:10
Hi All,

at the moment I'm working on an addition to CoreRuleset that help me running the high complex German DSA Game. Based on Comfort I like to add automatic sets of modifier based on the distance between then Token and the Target.

For Example:

the Thief like to trow an Dagger on an 10 square distance Target. He get's an - 10 Modifier
the Ranger at the same time has a 15 square distance Target get's a +5 Modifier.

There are multiple Modifiers that will added the the stack but at first I need the distance information.

Thank You for your support

BR

Old Man

Trenloe
June 13th, 2017, 16:21
You'll need three things: The position (x, y) of the attacking and target tokens, and the grid size of the image - if you might use square or hex grids, then you might need to get the grid type and factor that in.

For the tow tokens, use getPosition: https://www.fantasygrounds.com/refdoc/tokeninstance.xcp#getPosition

On the map image control, use getGridSize: https://www.fantasygrounds.com/refdoc/imagecontrol.xcp#getGridSize and maybe getGridType: https://www.fantasygrounds.com/refdoc/imagecontrol.xcp#getGridType

Then, you'll need to do some calculations to work out the distance between then two tokens based off their positions and size of grid.

If you have the SvageWorlds ruleset, this is done in scripts\manager_token.lua - function getTokenDistance(ctrlImage, tokenTargeter, tokenTarget) This is the only ruleset I'm aware of that makes range calculations and applies the results to attacks.

Old Man
June 14th, 2017, 08:04
Thank You for the Support! This helps!

BR

Old Man