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

Do These Scripts Exist?

1517422538

Edited 1517423949
Every time I have a harebrained idea for a roll20 game, I always find a script that makes it possible.  I've finally run into two ideas, that after much searching, I cannot find scripts for.  I figured I would defer to you for help, oh gracious API community.  I would really appreciate any help with getting these two ideas implemented in my games. First Idea: Does anyone know of a script that can automatically switch a map from day to night (triggers dynamic lighting at a specified time and then turns it off twelve hours later).  This is for the "home town" map of a friend's West Marches campaign. Second Idea: Is there a script that allows players to make new attribute macros, or even global macros with a button-press?  Even simple ones?  I want to use this for a "Contacts App" in a Shadowrun game.  Players can click "Add Contact", be queried for the contact name, then the script adds the name as text in a new macro.  Then when a character wants to text message a contact, I will have a macro set up called "New Message".  Player clicks the button and is queried to recall a contact from their book by "searching" (typing # then the contact name).  Then they are queried to type their message (it actually just whispers the message to me, the GM, so I can "text" them back).   Thanks so much in advance for any help! -Charlie
1517432210
The Aaron
Pro
API Scripter
Those are definitely possible to do with the API, though I'm not aware of any that do that current.  First : Torch has a command for toggling the DL on and off (and the Global Illumination), but not a timer function to do it automatically.  (would that be every 12 game hours or RL hours?  What timezone? etc) Second : This is really just a question of the interface.  Doing the functionality is the easy part.
1517433398
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Related, I use Token-mod to cause an invisible token to display a huuuuuge black aura, which dims the entire map. But also, not on a timer. (I also have it set to use a pale blue for moonlight, or blue green for underwater..)
The Aaron said: Those are definitely possible to do with the API, though I'm not aware of any that do that current.  First : Torch has a command for toggling the DL on and off (and the Global Illumination), but not a timer function to do it automatically.  (would that be every 12 game hours or RL hours?  What timezone? etc) Second : This is really just a question of the interface.  Doing the functionality is the easy part. First: Yes it would switch at 7pm (est) every night then stay turned on til 7am (est) in RL time. Second: I guess I have to start learning HTML.  I've got the Roll20 macros down, but I would really like this contact book API.  Time to dig in keithcurtis said: Related, I use Token-mod to cause an invisible token to display a huuuuuge black aura, which dims the entire map. But also, not on a timer. (I also have it set to use a pale blue for moonlight, or blue green for underwater..) Great idea!  Will look into it!
1517455542
The Aaron
Pro
API Scripter
Second: I’m just talking about the interface as far as commands and arguments. Formatting is really secondary in this case. 
I'm honestly not sure where to start :/
1517467789

Edited 1517467873
My Java knowledge is very little.
For the first Script you might be able to accomplish this by combining the Torch Script The Aaron mentioned and the Cron script by manveti (can be found in the API-Script repository). I have not tested this but if I find the time I can test and supply an example.
1517488460
Jakob
Sheet Author
API Scripter
Charlie Chopshop said: My Java knowledge is very little. Obligatory "Javascript is not Java". On the more helpful side:  starting tips .
Jakob said: Charlie Chopshop said: My Java knowledge is very little. Obligatory "Javascript is not Java". On the more helpful side:  starting tips . Jus further proof of my lack of knowledge :)   Florian B. said: For the first Script you might be able to accomplish this by combining the Torch Script The Aaron mentioned and the Cron script by manveti (can be found in the API-Script repository). I have not tested this but if I find the time I can test and supply an example. Any help would be greatly appreciated.
1517562916

Edited 1517563302
First off, I played around with it but could not accomplish the final goal. But I think I can point to the problems. The plan was the following: Use the Cron Script to execute commands periodically Said periodically executed command should switch between daytime and nighttime Executing Commands periodically First we want to make sure we can get commands executed on time. Head over to github and grab the source for the following API scripts: CommandShell ( <a href="https://raw.githubusercontent.com/Roll20/roll20-api-scripts/master/CommandShell/shell.js" rel="nofollow">https://raw.githubusercontent.com/Roll20/roll20-api-scripts/master/CommandShell/shell.js</a> ) Cron ( <a href="https://raw.githubusercontent.com/Roll20/roll20-api-scripts/master/cron/cron.js" rel="nofollow">https://raw.githubusercontent.com/Roll20/roll20-api-scripts/master/cron/cron.js</a> ) Go to your API scripts for the campaign and add the sources you got as a new API Script each. Call them "cron.js" and "shell.js". Test if the API scripts are correctly placed by starting your campaign and entering the !cron command. It should display the commands usage information in the Chat. Now to execute a command every day 7pm (EST) you would do something like: !cron -t 24:00:00 -i 24:00:00 Look at me, I'm dancing crazy What that command does, is on midnight GMT (which happens to be 7pm EST; specified by the -t parameter) execute the command "Look at me, I'm dancing crazy" and repeat every 24 hours (specified by -i parameter). Making it Nighttime and Daytime Now head over to your API Scripts and add the Torch Script which can be installed with the Oneclick-Install. Make it so! After the sandbox has restarted go over to you campaign and try "!torch --help" so you can see if everything has been setup correctly. You can now use all the commands given in the helptext. We are most interested in !daytime and !nighttime. Theoretically we would now combine the cron command from above with the torch commands, which might look something like this: !cron -t 24:00:00 -i 24:00:00 !nighttime !cron -t 12:00:00 -i 24:00:00 !daytime Maybe I got day and night mixed up, I suck at timezones and even more at the 12-hour clock format. But wait, you said there was a problem.&nbsp; Unfortunately yes, the part about combining cron and torch was unfortunately made up. It should be possible from what I read but I think something on the side of the Torch Script is preventing it from working correctly. Fortunately The Aaron is already on this thread. Although it is not working in the specific case I can tell that the cron script works with executing API commands. I can also see that when calling "!torch --help" via cron I get no output, but the API console shows a periodic error that corresponds with the torch script not finding a player where the content of the helpfile should be whispered. So my belief is that should be working but either the torch script is partially filtering out messages that originate from another API script, or the !nighttime and !daytime functions require some information to be implicitly passed to the script (like having a token selected). I think Aaron could give us more information on this as he is obviously the most knowledgeable regarding the torch script he built. I think, but haven't tested this that there could be a further problem as the API scripts won't run when nobody is logged into the campaign, so if say nobody is there when it becomes night it just doesn't become night. This the roll20 equivalent of " If a tree falls in a forest and no one is around to hear it, does it make a sound? ". Sorry terrible pun. So you might need to make sure there's always somebody logged in or to update the cron script to retry intervals it missed afther the API was shut down the last time so that when a player logs on after the change in daylight it is retried the moment he goes online. I hope that helped
As I understand the touch API it only works where the page as Dm separate from the player ribbon or something like that. The error could be from a lack of this but as you said the great and powerful will be along at some point&nbsp;
Florian B. said: First off, I played around with it but could not accomplish the final goal. But I think I can point to the problems. The plan was the following: Use the Cron Script to execute commands periodically Said periodically executed command should switch between daytime and nighttime Wow!&nbsp; That was incredibly insightful and helpful.&nbsp; I really appreciate all of you putting in the effort to help me accomplish this goal.&nbsp; It seems that we are really close.&nbsp; I'm sitting on the edge of my seat waiting to see what Master Aaron has to say about. As far as staying logged in to trigger the day and night switch, I do have an extra raspberry pi.&nbsp; I could definitely just have it turned on with a maintenance account parked in the Roll20 game.
1517604370

Edited 1517605597
The Aaron
Pro
API Scripter
HA!&nbsp; Lordmage, I think you're precisely right. It might be possible to get cron to call Torch, but that's probably going the long way round.&nbsp; Best would be to write a script explicitly for this.&nbsp;&nbsp; How do you want to indicate the page(s) that should be changed.&nbsp; I'd suggest having a token on the GM layer with a particular name, something like&nbsp;&nbsp; "DayNightChanges". Then you can write a script that does something like (completely untested back of the envelope code): on('ready',()=&gt;{ &nbsp; // find all the pages with tokens on the GM layer named DayNightChanges &nbsp; let pages = _.chain(findObjs({type:'graphic',subtype:'token',layer:'gmlayer',name: 'DayNightChanges'})) &nbsp; &nbsp; &nbsp;.map((t)=&gt;getObj('page',t.get('pageid'))) &nbsp; &nbsp; &nbsp;.reject(_.isUndefined) &nbsp; &nbsp; &nbsp;.value(); &nbsp; const SetSun = (m)=&gt;_.each(pages,(p)=&gt;p.set('lightglobalillum',m)); &nbsp; // function to turn on the sun &nbsp; const TurnSunOn=()=&gt;{ &nbsp; &nbsp; // for each page, turn it on &nbsp; &nbsp; SetSun(true); &nbsp; &nbsp; // schedule turning it off in 12 hours &nbsp; &nbsp; _.delay(TurnSunOff,(12*60*60*1000)); &nbsp; }; &nbsp; // function to turn off the sun &nbsp; const TurnSunOff=()=&gt;{ &nbsp; &nbsp; // for each page, turn it on &nbsp; &nbsp; SetSun(false); &nbsp; &nbsp; // schedule turning it off in 12 hours &nbsp; &nbsp; _.delay(TurnSunOff,(12*60*60*1000)); &nbsp; }; &nbsp; // set up an event to change the time the first time (starting the chain) &nbsp; let now = new Date(); &nbsp; // build the next time that the change needs to happen. &nbsp; let when = new Date(now); &nbsp; when.setUTCMinutes(0); // zero out minutes and seconds &nbsp; when.setUTCSeconds(0); &nbsp; if(now.getUTCHours()&lt;12) { // 12 UTC is noon UTC, which is 7am EST, so night time &nbsp; &nbsp; // make sure the sun is in the right mode &nbsp; &nbsp; SetSun(false); &nbsp; &nbsp; // schdule event for next transition &nbsp; &nbsp; when.setUTCHours(12);&nbsp; &nbsp; &nbsp; _.delay(TurnSunOn, when-now); &nbsp; } else { // must be 12 or greater, so day time &nbsp; &nbsp; // make sure the sun is in the right mode &nbsp; &nbsp; SetSun(true); &nbsp; &nbsp; // schdule event for next transition &nbsp; &nbsp; when.setUTCHours(24);&nbsp; &nbsp; &nbsp; _.delay(TurnSunOff, when-now); &nbsp; } }); Basically, this should figure out when the next event is based on the current time, then delay a change until that time.&nbsp; Really, this should monitor those tokens and update the list of pages when they change (added, removed, renamed, etc), but that's a lot more wiring and you can just restart the API when you add new ones.
1517604417
The Aaron
Pro
API Scripter
As far as staying logged in to trigger the day and night switch, I do have an extra raspberry pi.&nbsp; I could definitely just have it turned on with a maintenance account parked in the Roll20 game. That shouldn't be necessary. =D
keithcurtis said: Related, I use Token-mod to cause an invisible token to display a huuuuuge black aura, which dims the entire map. But also, not on a timer. (I also have it set to use a pale blue for moonlight, or blue green for underwater..) that idea is so great it almost makes me cry :D seriously, so simple!
1517881311
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
gui8312 said: keithcurtis said: Related, I use Token-mod to cause an invisible token to display a huuuuuge black aura, which dims the entire map. But also, not on a timer. (I also have it set to use a pale blue for moonlight, or blue green for underwater..) that idea is so great it almost makes me cry :D seriously, so simple! It's just a&nbsp; Stupid Roll20 Trick .