Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Moving a token one step forward, rather than one step up?

April 29 (5 years ago)
Danny
Pro
Marketplace Creator

Right now I believe that you can only move a token along the grid. The arrow keys will move a token along the grid. I want to move a token one step forward - roughly a grid space, but in the direction it is facing, rather than along the grid. Is this possible already? This would be especially useful in RPGs where facing matters, such as the IKRPG, which is gridless, and has a back-strike element.

April 29 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

There isn't a way via the user interface.  I could write a script that would move a token some number of steps in the direction it is facing.

April 29 (5 years ago)
Danny
Pro
Marketplace Creator

Is there a way to formally request this as a feature, because it seems like a common sense thing that should be included, like as an alt function of the arrow keys. If the API is something you can whip up quick, I'd be interested, but don't go out of your way mate - more curious than anything.

April 29 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

Probably not to hard to do the API, maybe 15min of effort. 

You can add a suggestion in the Suggestions forum for a built in option. 

April 29 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

Here ya go.  This will move in the direction of the Rotation Bar, up on an unrotated token.  This lines up with the "forward" direction for light, so will work with it.  (Quick tip, if your token is facing down, right click->advanced->flip vertical, right click->advanced->flip horizontal to get it the right way).

Command is !mif  (Move In Facing):

!mif

That will move all selected tokens one standard unit (70 pixels) in the facing direction.  You can vary that by supplying an argument which is the number (decimals accepted) of units to move (negative numbers will move backwards):

!mif 3
!mif 1.5
!mif -2

You can also use inline rolls:

!mif [[1d3]]

You can reference attributes, but bear in mind it won't be deterministic which attribute is referenced with multiple tokens selected:

!mif [[@{selected|speed}]]


Code:

on('ready',()=>{

    const processInlinerolls = (msg) => {
        if(_.has(msg,'inlinerolls')){
            return _.chain(msg.inlinerolls)
                .reduce(function(m,v,k){
                    let ti=_.reduce(v.results.rolls,function(m2,v2){
                        if(_.has(v2,'table')){
                            m2.push(_.reduce(v2.results,function(m3,v3){
                                m3.push(v3.tableItem.name);
                                return m3;
                            },[]).join(', '));
                        }
                        return m2;
                    },[]).join(', ');
                    m['$[['+k+']]']= (ti.length && ti) || v.results.total || 0;
                    return m;
                },{})
                .reduce(function(m,v,k){
                    return m.replace(k,v);
                },msg.content)
                .value();
        } else {
            return msg.content;
        }
    };
    
    on('chat:message', (msg) => {
        if('api' === msg.type && /^!mif\b/i.test(msg.content)){
            let args = processInlinerolls(msg).split(/\s+/);

            msg.selected
                .map((o)=>getObj('graphic',o._id))
                .filter((t)=>undefined !== t)
                .forEach(t=>{
                    let angle = ((parseFloat(t.get('rotation'))||0)-90) * (Math.PI/180);
                    let distance = 70*(args[1]||1);
                    let x = t.get('left')+(distance*Math.cos(angle));
                    let y = t.get('top')+(distance*Math.sin(angle));

                    t.set({
                        top: y,
                        left: x
                    });

                });


        }
    });
});

April 30 (5 years ago)
Danny
Pro
Marketplace Creator

Thanks for your time man. This is great.

April 30 (5 years ago)
GiGs
Pro
Sheet Author
API Scripter

I'm planning to do a tabletop wargame in roll20 soon, this might come in very handy for moving units of troops

April 30 (5 years ago)
Danny
Pro
Marketplace Creator
Yep.