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

[Script] Disable Rotation via Chat Window Command

May 20 (12 years ago)
Konrad J.
Pro
API Scripter

Very simple script to disable/enable rotation.  Only the GM can enable or disable.  The rotation still happens since we have no way to interrupt the event, but it gets immediately reversed once the rotation handle is unclicked.  This can be useful so that players can't rotate tokens, but even so the GM can't rotate them by accident.  At the moment we have no way to know who triggered an event other than a chat message event.  If that ability gets added then we could add an option to lock rotation for players only.

Enable rotation (default)

!r on

Disable rotation

!r off


var rotateGlobal = {
    rotationEnable : true
};
function processRotateScript(argv, who) { 
if (who.indexOf("(GM)") > -1) {
var rotateCommand = argv.shift();
switch(rotateCommand) {
case 'on':
rotateGlobal.rotationEnable = true;
break;
case 'off':
rotateGlobal.rotationEnable = false;
break;
}
}
}
// on() events
// process scripts
on("change:graphic:rotation", function(obj, prev) {    
        if (rotateGlobal.rotationEnable ===  false) {
   obj.set("rotation",prev.rotation);
   return;
   }
});
var processScriptTabs = function(argv, who) {
    // this will run the various other scripts depending upon the chat
    // window command.  Just add another Case statement to add a new command.
    var script = argv.shift();
    switch(script) {
        case "!r":
processRotateScript(argv, who);
        break;
default:
    }
};
on("chat:message", function(msg) {
    // returns the chat window command entered, all in lowercase.
var chatCommand = msg.content;
chatCommand = chatCommand.toLowerCase(); //make all characters lowercase
var argv = chatCommand.split(' ');
if (msg.type !== 'api') {
return;
}
return processScriptTabs(argv, msg.who);
});

May 20 (12 years ago)

Couldn't I just add (GM) to my display name to be able to rotate and enable/disable this command?

May 20 (12 years ago)
Riley D.
Roll20 Team

Yes, but on the other hand you would see a player do it and could tell them to knock it off :P.

May 20 (12 years ago)
Alex L.
Pro
Sheet Author

Riley D. said:

Yes, but on the other hand you would see a player do it and could tell them to knock it off :P.

So Riley when are you going to add a isGM boolean to the player object :P


May 20 (12 years ago)
Konrad J.
Pro
API Scripter

HoneyBadger said:

Couldn't I just add (GM) to my display name to be able to rotate and enable/disable this command?

Yup, but that's all I could think of for now. :) And they really can only rotate stuff they are in control of.  Its more to stop accidental rotates than to stop player's from fooling around.  Someone had requested the ability to do that since they would rotate tokens sometimes and didn't mean to.  I could add things like renaming and resizing to the script as well I guess.

You actually wouldn't see a player do it since ! commands aren't echoed to the chat window. ;)

If Riley set the player object._type to gm for a GM and player when a player.  Then we just take the who info, search for the object, then check its _type if gm

Ooops, _type is the the actual type of object of course.  Yes it would be nice to have a isGM boolean!

It could be useful to have a way to know if its the GM or the player that executed a command.  Also be good to know who triggered a change:graphic event.


May 20 (12 years ago)
Alex L.
Pro
Sheet Author

Konrad J. said:

HoneyBadger said:

Couldn't I just add (GM) to my display name to be able to rotate and enable/disable this command?

Yup, but that's all I could think of for now. :) And they really can only rotate stuff they are in control of.  Its more to stop accidental rotates than to stop player's from fooling around.  Someone had requested the ability to do that since they would rotate tokens sometimes and didn't mean to.  I could add things like renaming and resizing to the script as well I guess.

You actually wouldn't see a player do it since ! commands aren't echoed to the chat window. ;)

If Riley set the player object._type to gm for a GM and player when a player.  Then we just take the who info, search for the object, then check its _type if gm

Ooops, _type is the the actual type of object of course.  Yes it would be nice to have a isGM boolean!

It could be useful to have a way to know if its the GM or the player that executed a command.  Also be good to know who triggered a change:graphic event.


I believe Riley said the who triggered what event thing is a nice idea abut hard to put into practice so we may or may not see it one day.

May 20 (12 years ago)
Konrad J.
Pro
API Scripter

Alex L. said:

Konrad J. said:

HoneyBadger said:

Couldn't I just add (GM) to my display name to be able to rotate and enable/disable this command?

Yup, but that's all I could think of for now. :) And they really can only rotate stuff they are in control of.  Its more to stop accidental rotates than to stop player's from fooling around.  Someone had requested the ability to do that since they would rotate tokens sometimes and didn't mean to.  I could add things like renaming and resizing to the script as well I guess.

You actually wouldn't see a player do it since ! commands aren't echoed to the chat window. ;)

If Riley set the player object._type to gm for a GM and player when a player.  Then we just take the who info, search for the object, then check its _type if gm

Ooops, _type is the the actual type of object of course.  Yes it would be nice to have a isGM boolean!

It could be useful to have a way to know if its the GM or the player that executed a command.  Also be good to know who triggered a change:graphic event.


I believe Riley said the who triggered what event thing is a nice idea abut hard to put into practice so we may or may not see it one day.
I remember that.  Hoping the more good reasons for something we show him the more chance we have of something happening. :)

May 20 (12 years ago)
Konrad J.
Pro
API Scripter

HoneyBadger said:

Couldn't I just add (GM) to my display name to be able to rotate and enable/disable this command?

Here you go.  The GM puts his display name at the top of the script.  Now we know who the GM is. :)

var rotateGlobal = {

    rotationEnable : true,

    GMName : "GMs Name" //put the gm's display name here

};

function isGM(who) {

if (rotateGlobal.GMName + " (GM)" === who) {

return true;

}

else {

return false;

}

}

function processRotateScript(argv, who) { 

if (isGM(who) === true) {

var rotateCommand = argv.shift();

switch(rotateCommand) {

case 'on':

rotateGlobal.rotationEnable = true;

break;

case 'off':

rotateGlobal.rotationEnable = false;

break;

}

}

}

// on() events

// process scripts

on("change:graphic:rotation", function(obj, prev) {    

        if (rotateGlobal.rotationEnable ===  false) {

   obj.set("rotation",prev.rotation);

   return;

   }

});

var processScriptTabs = function(argv, who) {

    // this will run the various other scripts depending upon the chat

    // window command.  Just add another Case statement to add a new command.

    var script = argv.shift();

    switch(script) {

        case "!r":

processRotateScript(argv, who);

        break;

default:

    }

};

on("chat:message", function(msg) {

    // returns the chat window command entered, all in lowercase.

var chatCommand = msg.content;

chatCommand = chatCommand.toLowerCase(); //make all characters lowercase

var argv = chatCommand.split(' ');

if (msg.type !== 'api') {

return;

}

return processScriptTabs(argv, msg.who);

});


May 20 (12 years ago)
Alex L.
Pro
Sheet Author

FYI i started work on a API totorial guide thing on the wiki its not very good atm but it should have some useful stuff.

https://wiki.roll20.net/API:A_Guide_to_the_API

May 20 (12 years ago)
Konrad J.
Pro
API Scripter

Alex L. said:

FYI i started work on a API totorial guide thing on the wiki its not very good atm but it should have some useful stuff.

https://wiki.roll20.net/API:A_Guide_to_the_API

Awesome.  I wanted to do that also, but haven't had a chance.  I'll have a look.