RPTools.net

Discussion and Support

Skip to content

It is currently Sun Feb 18, 2018 7:08 pm 






Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

Previous topic | Next topic 

  Print view

Author Message
 Offline
Kobold
 
Joined: Wed Jul 31, 2013 8:57 am
Posts: 18
 Post subject: Moving a Token to a random coordinate
PostPosted: Sun Jan 21, 2018 8:40 pm 
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.


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 8009
Location: Bay Area
 Post subject: Re: Moving a Token to a random coordinate
PostPosted: Sun Jan 21, 2018 9:00 pm 
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:

Code:
[H: moveToken(getTokenX(0)+1d3-2,getTokenY(0)+1d3-2)]


This will move token to current position from -1 to +1 in the X and Y direction with a chance of no movements.

_________________
Downloads:


Top
 Profile  
 
 Offline
Kobold
 
Joined: Wed Jul 31, 2013 8:57 am
Posts: 18
 Post subject: Re: Moving a Token to a random coordinate
PostPosted: Sun Jan 21, 2018 10:06 pm 
I guess I should have mentioned what my aim is :oops:

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 :D

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.


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 8009
Location: Bay Area
 Post subject: Re: Moving a Token to a random coordinate
PostPosted: Sun Jan 21, 2018 11:00 pm 
You may want to check out the animated dice thread: 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: viewtopic.php?p=193914#p193914

I'll share once I take a look at it.

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9478
Location: Netherlands
 Post subject: Re: Moving a Token to a random coordinate
PostPosted: Mon Jan 22, 2018 9:15 am 
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:
e.gd6:
[
HmoveToken(roll(1,6),00'dice')]
3d4:
[
HmoveToken(roll(3,4),00'dice')]
etc

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
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


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri May 12, 2006 7:56 pm
Posts: 6381
Location: Middle of Nowhere, NM
 Post subject: Re: Moving a Token to a random coordinate
PostPosted: Tue Jan 23, 2018 6:39 pm 
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:
Attachment:
DiceDrop1.jpg
DiceDrop1.jpg [ 144.6 KiB | Viewed 211 times ]


  • 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.


Top
 Profile  
 
User avatar  Offline
Dragon
 
Joined: Mon Oct 26, 2009 4:51 am
Posts: 308
 Post subject: Re: Moving a Token to a random coordinate
PostPosted: Tue Jan 23, 2018 7:34 pm 
I think faced with that I'd just measure up the surface areas and convert it to percentages. :wink:


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9478
Location: Netherlands
 Post subject: Re: Moving a Token to a random coordinate
PostPosted: Wed Jan 24, 2018 4:41 am 
Phergus wrote:
I believe the OP is not just after dice roller but a drop chart or die drop table.


roughly the same difference, instead of a line (1 dim) you have a surface (2 dim). So this:
Code:
[H: moveToken(roll(1,6),0, 0, 'dice')] 

becomes this
Code:
[moveToken(getTokenX(0,"roll_sheet") + roll(1,getTokenWidth("roll_sheet")), getTokenY(0,"roll_sheet") + roll(1,getTokenHeight("roll_sheet")), 1, "dice")] 

biggest diff is the fact that gettokenwidth can only return pixels not cells, so yo have to flag this in movetoken. The result will thus also not be bound by cells, but by pixel size.
Something that can be fixed with:
Code:
[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"
)]  


note that I've added getTokenX/Y so you don't necessarily have to place the sheet at the origin!

edit: forgot to make it random!

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
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


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 8009
Location: Bay Area
 Post subject: Re: Moving a Token to a random coordinate
PostPosted: Wed Jan 24, 2018 4:59 am 
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:


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri May 12, 2006 7:56 pm
Posts: 6381
Location: Middle of Nowhere, NM
 Post subject: Re: Moving a Token to a random coordinate
PostPosted: Wed Jan 24, 2018 8:27 am 
I imagine it is a mechanic that is much more interesting at the game table with actual dice.


Top
 Profile  
 
 Offline
Kobold
 
Joined: Wed Jul 31, 2013 8:57 am
Posts: 18
 Post subject: Re: Moving a Token to a random coordinate
PostPosted: Wed Jan 24, 2018 8:56 pm 
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.


Top
 Profile  
 
 Offline
Kobold
 
Joined: Wed Jul 31, 2013 8:57 am
Posts: 18
 Post subject: Re: Moving a Token to a random coordinate
PostPosted: Thu Jan 25, 2018 8:12 am 
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)


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9478
Location: Netherlands
 Post subject: Re: Moving a Token to a random coordinate
PostPosted: Thu Jan 25, 2018 9:09 am 
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.

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
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


Top
 Profile  
 
 Offline
Kobold
 
Joined: Wed Jul 31, 2013 8:57 am
Posts: 18
 Post subject: Re: Moving a Token to a random coordinate
PostPosted: Thu Jan 25, 2018 8:12 pm 
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.


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9478
Location: Netherlands
 Post subject: Re: Moving a Token to a random coordinate
PostPosted: Fri Jan 26, 2018 2:02 am 
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:

Code:
<!-- 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")-roll(1,getTokenWidth("roll_sheet")/gs+1), 
    
getTokenY(0,"roll_sheet")-roll(1,getTokenHeight("roll_sheet")/gs+1), 
    
0
    
"dice_1"
)] 
 

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: No registered users and 2 guests





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman