Moving a Token to a random coordinate
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
Moving a Token to a random coordinate
How would one make a macro so that a token would move to a random coordinate within the visible window, or perhaps some set dimensions.
Re: Moving a Token to a random coordinate
Depends on the nature of the move. If it's based on current position, then you'll need the current x,y. If you need it to be a visible square from your token then you'll need to use isVisible or canSeeToken depending on application. In either case, you'll need to use moveToken. The problem with random movement with no limitations is that you can move in to or through walls.
A basic scenario, move to random adjacent square:
This will move token to current position from -1 to +1 in the X and Y direction with a chance of no movements.
A basic scenario, move to random adjacent square:
Code: Select all
[H: moveToken(getTokenX(0)+1d3-2,getTokenY(0)+1d3-2)]
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Moving a Token to a random coordinate
I guess I should have mentioned what my aim is
I'm trying to simulate a drop chart in maptool, you know the one, where you have a sheet of paper with different boxes, and you throw some dice on there, and where the die lands and the number it shows on its face gives you some information. So I need a way to "throw" the dice in a confined area of the virtual table. Preferably on the .jpg die drop chart I pasted onto the virtual table. I'll look into moveToken more
I'm thinking outline my drop chart .jpg in vision blocking, put my "die" token within there, and somehow use the isVisible, to define the range of places the die can be moved to.
I'm trying to simulate a drop chart in maptool, you know the one, where you have a sheet of paper with different boxes, and you throw some dice on there, and where the die lands and the number it shows on its face gives you some information. So I need a way to "throw" the dice in a confined area of the virtual table. Preferably on the .jpg die drop chart I pasted onto the virtual table. I'll look into moveToken more
I'm thinking outline my drop chart .jpg in vision blocking, put my "die" token within there, and somehow use the isVisible, to define the range of places the die can be moved to.
Re: Moving a Token to a random coordinate
You may want to check out the animated dice thread: http://forums.rptools.net/viewtopic.php?f=8&t=18001
I also recall coveredInFish doing something.
edit: I just remember I made a map based off his drop-in here: http://forums.rptools.net/viewtopic.php ... 14#p193914
I'll share once I take a look at it.
I also recall coveredInFish doing something.
edit: I just remember I made a map based off his drop-in here: http://forums.rptools.net/viewtopic.php ... 14#p193914
I'll share once I take a look at it.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Moving a Token to a random coordinate
well if you really want a visual dice roller strip (as it sounds like). The easiest is to create a strip of single line squares starting on x=0, y=0 (continuing with x=1, x=2, etc). Put the token on x=0 initially. And then you can use (lets call the token 'dice'):
Code: Select all
e.g. d6:
[H: moveToken(roll(1,6),0, 0, 'dice')]
3d4:
[H: moveToken(roll(3,4),0, 0, 'dice')]
etc
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
Re: Moving a Token to a random coordinate
I believe the OP is not just after dice roller but a drop chart or die drop table. Normally a piece of paper is divided into zones and then you drop a group of dice onto it. Each dice that drops into a zone has its value used to determine some attribute related to that zone. May use all the same type of die or different kinds.
Here is a basic die drop table:
[/url]
Here is a basic die drop table:
[/url]
- So place something like that as the background of a map.
- Determine the dimensions of it from the top left corner as 'w' and 'h'.
- In macro generate two rolls [xloc = 1dw] where w is the width
- and [yloc = 1dh] where h is the height.
- Determine die face with another roll to get image from table of die facs.
- Plop token with correct image at that location.
- Rinse, repeat.
- metatheurgist
- Dragon
- Posts: 364
- Joined: Mon Oct 26, 2009 5:51 am
Re: Moving a Token to a random coordinate
I think faced with that I'd just measure up the surface areas and convert it to percentages.
Re: Moving a Token to a random coordinate
roughly the same difference, instead of a line (1 dim) you have a surface (2 dim). So this:Phergus wrote:I believe the OP is not just after dice roller but a drop chart or die drop table.
Code: Select all
[H: moveToken(roll(1,6),0, 0, 'dice')]
Code: Select all
[moveToken(getTokenX(0,"roll_sheet") + roll(1,getTokenWidth("roll_sheet")), getTokenY(0,"roll_sheet") + roll(1,getTokenHeight("roll_sheet")), 1, "dice")]
Something that can be fixed with:
Code: Select all
[h:gs = json.get(json.get(getInfo("map"),"grid"),"size")]
[moveToken(
getTokenX(1,"roll_sheet") + roll(1,getTokenWidth("roll_sheet")/gs),
getTokenY(1,"roll_sheet") + roll(1,getTokenHeight("roll_sheet")/gs),
1,
"dice"
)]
edit: forgot to make it random!
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
Re: Moving a Token to a random coordinate
Unless you're going for special effect I say random chart is way to go. I don't think coding time for the special effect makes it worth it. But that's just me.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Moving a Token to a random coordinate
I imagine it is a mechanic that is much more interesting at the game table with actual dice.
Re: Moving a Token to a random coordinate
Yes it's exactly that, but I intend to use it to determine where something the players are looking for is. See "Vornheim" supplement for more details.
EG Players Ask: Where's the apothecary?
<drop die onto map of city..it lands in foreign distance>
GM Answers: It's here, in the foreign district.
Players Ask: What's the layout of this shop, I want to rob it.
<drop a d4 and draw lines from it = to the number it rolls, inside a rectangular shape>
GM Answers: It looks like this.
EG Players Ask: Where's the apothecary?
<drop die onto map of city..it lands in foreign distance>
GM Answers: It's here, in the foreign district.
Players Ask: What's the layout of this shop, I want to rob it.
<drop a d4 and draw lines from it = to the number it rolls, inside a rectangular shape>
GM Answers: It looks like this.
Re: Moving a Token to a random coordinate
I think the pseudo-code would be something like...
1. Make 2 "corner" tokens and 1 "dice" token
2. Manually move the "corner" tokens to upper right and lower left corner of your drop chart
3. Get Corner tokens x and y and set to upperRightX, upperRightY,lowerLeftX,LowerLeftY
4. Width = upperRightX-lowerLeftX
5. Length = upperRightY-lowerLeftY
6. randomly generate a new x coordinate between 0 and Width, set to randomX
7. randomly generate a new y coordinate between 0 and Height, set to randomY
8. newX=lowerLeftX+randomX
9. newY=lowerLeftY+randomY
10. move "dice" token to (newX,newY)
1. Make 2 "corner" tokens and 1 "dice" token
2. Manually move the "corner" tokens to upper right and lower left corner of your drop chart
3. Get Corner tokens x and y and set to upperRightX, upperRightY,lowerLeftX,LowerLeftY
4. Width = upperRightX-lowerLeftX
5. Length = upperRightY-lowerLeftY
6. randomly generate a new x coordinate between 0 and Width, set to randomX
7. randomly generate a new y coordinate between 0 and Height, set to randomY
8. newX=lowerLeftX+randomX
9. newY=lowerLeftY+randomY
10. move "dice" token to (newX,newY)
Re: Moving a Token to a random coordinate
that's the extensive description of the method I posted earlier; in which its clear that steps 1-5 are redundant and 7-10 can be done in one line of code...
note that "dice" and "roll_sheet" are respectively the token and the background map.
note that "dice" and "roll_sheet" are respectively the token and the background map.
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
Re: Moving a Token to a random coordinate
Nice! What's the /gs do? When I leave that in, the dice only stays in the upper left corner of the drop_area. When I remove it, the dice will occasionally pop outside of the drop area.
Re: Moving a Token to a random coordinate
gs has the gridsize (typically 50 pixels per cell) as getWidth/height can only return the size of a token in pixels. So you have to divide it by gs to get the number of cells. Its quite possible that I overlooked something or used a 1 where it should be a 0. You can check the fuctions in the wiki
You can pull that line of code apart by putting everything in a variable and check those in mt to see where it goes wrong. e.g. [r:x= getTokenX(0)] [r:h=getTokenHeight()] etc.
edit: as I find it kind of an interesting topic, I tested it myself, here's the code:
You can pull that line of code apart by putting everything in a variable and check those in mt to see where it goes wrong. e.g. [r:x= getTokenX(0)] [r:h=getTokenHeight()] etc.
edit: as I find it kind of an interesting topic, I tested it myself, here's the code:
Code: Select all
<!-- gridless -->
[h:moveToken(
getTokenX(1,"roll_sheet") + roll(1,getTokenWidth("roll_sheet")),
getTokenY(1,"roll_sheet") + roll(1,getTokenHeight("roll_sheet")),
1,
"dice"
)]
<!-- grid -->
<!-- best to have roll_sheet NOT snapped to grid and sized such that its a few pixels within the borders of the outer gridlines -->
[h:gs = json.get(json.get(getInfo("map"),"grid"),"size")]<br>
[h:moveToken(
getTokenX(0,"roll_sheet")-1 + roll(1,getTokenWidth("roll_sheet")/gs+1),
getTokenY(0,"roll_sheet")-1 + roll(1,getTokenHeight("roll_sheet")/gs+1),
0,
"dice_1"
)]
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