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

Seeking additional code for Faerun Calender - Looking to add Time

This Script is made by Kristy and is slightly modified by me (Removed Down Days) I would like to include Time (military time format) and have a button called "Advance the Time" which can also trigger a new day if it rolls over after midnight.&nbsp; ===================================================================================== Faerun Calender w/o Down Days // Calendar and down day counter for Faerun // Created by Kirsty (<a href="https://app.roll20.net/users/1165285/kirsty" rel="nofollow">https://app.roll20.net/users/1165285/kirsty</a>) // API Commands: // !cal - for the GM displays the menu in the chat window, for a player displays date, weather, moon and down days // Red Colour: #7E2D40 var Calendar = Calendar || (function() { 'use strict'; var version = '0.2.4', setDefaults = function() { state.Calendar = { now: { ordinal: 1, year: 1486, down: 0, divider: 1, weather: "It is a cool but sunny day" }, }; }, handleInput = function(msg) { var args = msg.content.split(","); if (msg.type !== "api") { return; } if(playerIsGM(msg.playerid)){ switch(args[0]) { case '!cal': calmenu(); break; case '!setday': getordinal(msg); weather(); calmenu(); break; case '!setmonth': getordinal(msg); weather(); calmenu(); break; case '!setyear': state.Calendar.now.year=args[1]; calmenu(); break; case '!setordinal': state.Calendar.now.ordinal=args[1]; calmenu(); break; case '!addday': addday(args[1]); weather(); calmenu(); break; case '!weather': weather(); calmenu(); break; case '!playercal': showcal(msg); break; } }else if(args[0]=='!cal'){ showcal(msg); } }, calmenu = function() { var divstyle = 'style="width: 189px; border: 1px solid black; background-color: #ffffff; padding: 5px;"' var astyle1 = 'style="text-align:center; border: 1px solid black; margin: 1px; background-color: #7E2D40; border-radius: 4px; box-shadow: 1px 1px 1px #707070; width: 100px;'; var astyle2 = 'style="text-align:center; border: 1px solid black; margin: 1px; background-color: #7E2D40; border-radius: 4px; box-shadow: 1px 1px 1px #707070; width: 150px;'; var tablestyle = 'style="text-align:center;"'; var arrowstyle = 'style="border: none; border-top: 3px solid transparent; border-bottom: 3px solid transparent; border-left: 195px solid rgb(126, 45, 64); margin-bottom: 2px; margin-top: 2px;"'; var headstyle = 'style="color: rgb(126, 45, 64); font-size: 18px; text-align: left; font-variant: small-caps; font-family: Times, serif;"'; var substyle = 'style="font-size: 11px; line-height: 13px; margin-top: -3px; font-style: italic;"'; var down = state.Calendar.now.down; down = getdown(down); var nowdate = getdate(state.Calendar.now.ordinal).split(','); var month = nowdate[0]; var day = nowdate[1]; var moon = getmoon(); sendChat('Calendar', '/w gm &lt;div ' + divstyle + '&gt;' + //-- '&lt;div ' + headstyle + '&gt;Calendar&lt;/div&gt;' + //-- '&lt;div ' + substyle + '&gt;Menu&lt;/div&gt;' + //-- '&lt;div ' + arrowstyle + '&gt;&lt;/div&gt;' + //-- '&lt;table&gt;' + //-- '&lt;tr&gt;&lt;td&gt;Day: &lt;/td&gt;&lt;td&gt;&lt;a ' + astyle1 + '" href="!setday,?{Day?|1},' + month +'"&gt;' + day + '&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;' + //-- '&lt;tr&gt;&lt;td&gt;Month: &lt;/td&gt;&lt;td&gt;&lt;a ' + astyle1 + '" href="!setmonth,' + day + ',?{Month|Hammer (Jan)|Midwinter|Alturiak (Feb)|Ches (Mar)|Tarsakh (Apr)|Greengrass (Spring)|Mirtul (May)|Kythorn (Jun)|Flamerule (Jul)|Midsummer|Eleasias (Aug)|Eleint (Sep)|Highharvestide (Thanksgiving)|Marpenoth (Oct)|Uktar (Nov)|Feast of the Moon (Winter)|Nightal (Dec)}"&gt;' + month + '&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;' + //-- '&lt;tr&gt;&lt;td&gt;Year: &lt;/td&gt;&lt;td&gt;&lt;a ' + astyle1 + '" href="!setyear,?{Year?|1486}"&gt;' + state.Calendar.now.year + '&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;' + //-- '&lt;tr&gt;&lt;td&gt;Ordinal: &lt;/td&gt;&lt;td&gt;&lt;a ' + astyle1 + '" href="!setordinal,?{Ordinal?|1}"&gt;' + state.Calendar.now.ordinal + '&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;' + //-- '&lt;/table&gt;' + //-- '&lt;br&gt;Weather: ' + state.Calendar.now.weather + //-- '&lt;br&gt;&lt;br&gt;Moon: ' + moon + //-- '&lt;br&gt;&lt;br&gt;&lt;div style="text-align:center;"&gt;&lt;a ' + astyle2 + '" href="!addday,?{Days to add?|1}"&gt;Advance the Date&lt;/a&gt;&lt;/div&gt;' + //-- '&lt;div style="text-align:center;"&gt;&lt;a ' + astyle2 + '" href="!weather"&gt;Roll Weather&lt;/a&gt;&lt;/div&gt;' + //-- '&lt;div style="text-align:center;"&gt;&lt;a ' + astyle2 + '" href="!playercal"&gt;Show to Players&lt;/a&gt;&lt;/div&gt;' + //-- '&lt;/div&gt;' ); }, showcal = function(msg) { var nowdate = getdate(state.Calendar.now.ordinal).split(','); var month = nowdate[0]; var day = nowdate[1]; var down = state.Calendar.now.down; down = getdown(down); var suffix = getsuffix(day); var divstyle = 'style="width: 189px; border: 1px solid black; background-color: #ffffff; padding: 5px;"' var tablestyle = 'style="text-align:center;"'; var arrowstyle = 'style="border: none; border-top: 3px solid transparent; border-bottom: 3px solid transparent; border-left: 195px solid rgb(126, 45, 64); margin-bottom: 2px; margin-top: 2px;"'; var headstyle = 'style="color: rgb(126, 45, 64); font-size: 18px; text-align: left; font-variant: small-caps; font-family: Times, serif;"'; var substyle = 'style="font-size: 11px; line-height: 13px; margin-top: -3px; font-style: italic;"'; var moon = getmoon(); var downstr; getdown(); sendChat(msg.who, '&lt;div ' + divstyle + '&gt;' + //-- '&lt;div ' + headstyle + '&gt;Calendar&lt;/div&gt;' + //-- '&lt;div ' + substyle + '&gt;Player View&lt;/div&gt;' + //-- '&lt;div ' + arrowstyle + '&gt;&lt;/div&gt;' + //-- day + suffix + ' ' + month + ', ' + state.Calendar.now.year + //-- '&lt;br&gt;&lt;br&gt;Today\'s weather:&lt;br&gt;' + state.Calendar.now.weather + //-- '&lt;br&gt;&lt;br&gt;Moon: ' + moon ); }, getdate = function(options){ var day = Number(options); var date; var month; if(day&gt;0 && day&lt;=30){ month="Hammer (Jan)"; date=day; }else if(day==31){ month="Midwinter"; date='festival'; }else if(day&gt;31 && day&lt;=61){ month="Alturiak (Feb)"; date=day-31; }else if(day&gt;61 && day&lt;=91){ month="Ches (Mar)"; date=day-61; }else if(day&gt;91 && day&lt;=121){ month="Tarsakh (Apr)"; date=day-91; }else if(day==122){ month="Greengrass (Spring)"; date='festival'; }else if(day&gt;122 && day&lt;=152){ month="Mirtul (May)"; date=day-122; }else if(day&gt;152 && day&lt;=182){ month="Kythorn (Jun)"; date=day-152; }else if(day&gt;182 && day&lt;=212){ month="Flamerule (Jul)"; date=day-182; }else if(day==213){ month="Midsummer"; date='festival'; }else if(day&gt;213 && day&lt;=243){ month="Eleasias (Aug)" date=day-213; }else if(day&gt;243 && day&lt;=273){ month="Eleint (Sep)"; date=day-243; }else if(day==274){ month="Highharvestide (Thanksgiving)"; date='festival'; }else if(day&gt;274 && day&lt;=304){ month="Marpenoth (Oct)"; date=day-274; }else if(day&gt;304 && day&lt;=334){ month="Uktar (Nov)"; date=day-304; }else if(day==335){ month="Feast of the Moon (Winter)"; date='festival'; }else if(day&gt;335 && day&lt;=365){ month="Nightal (Dec)"; date=day-335; }else{ month="Hammer"; date='1'; } var array=month+','+String(date); return array; }, getordinal = function(options){ var args = options.content.split(","); var date = args[1]; var month = args[2]; var ordinal = state.Calendar.now.ordinal; if(date == 'festival'){ date = 1; }else{ date = Number(args[1]); } switch(month) { case 'Hammer (Jan)': ordinal = date; break; case 'Midwinter': ordinal = 31; break; case 'Alturiak (Feb)': ordinal = 31+date; break; case 'Ches (Mar)': ordinal = 61+date; break; case 'Tarsakh (Apr)': ordinal = 91+date; break; case 'Greengrass (Spring)': ordinal = 122; break; case 'Mirtul (May)': ordinal = 122+date; break; case 'Kythorn (Jun)': ordinal = 152+date; break; case 'Flamerule (Jul)': ordinal = 182+date; break; case 'Midsummer': ordinal = 213; break; case 'Eleasias (Aug)': ordinal = 213+date; break; case 'Eleint (Sep)': ordinal = 243+date; break; case 'Highharvestide (Thanksgiving)': ordinal = 274; break; case 'Marpenoth (Oct)': ordinal = 274+date; break; case 'Uktar (Nov)': ordinal = 304+date; break; case 'Feast of the Moon (Winter)': ordinal = 334+date; break; case 'Nightal (Dec)': ordinal = 335+date; break; } state.Calendar.now.ordinal = ordinal; }, getsuffix = function(day) { var date = Number(day) var suffix if (date == 1 || date == 21 ){ suffix = 'st'; }else if (date == 2 || date == 22){ suffix = 'nd'; }else if (date == 3 || date == 23){ suffix = 'rd'; }else{ suffix = 'th'; } return suffix; }, getdown = function(days) { var down = Number(days); var div = state.Calendar.now.div; if(div!=0){ down = down/div; } return down; }, addday = function(add) { var ordinal = Number(add); var div = state.Calendar.now.div; if(div!=0){ state.Calendar.now.down = Number(state.Calendar.now.down)+ordinal; } ordinal = ordinal + Number(state.Calendar.now.ordinal); if(ordinal&gt;365){ ordinal=ordinal-365; state.Calendar.now.year = Number(state.Calendar.now.year)+1; } state.Calendar.now.ordinal = ordinal; }, weather = function() { var roll; var temperature; var wind; var precipitation; var season; var ordinal = state.Calendar.now.ordinal; if(ordinal &gt; 349 || ordinal &lt;= 75){ season = 'Winter' }else if(ordinal &gt; 75 && ordinal &lt;= 166){ season = 'Spring' }else if(ordinal &gt; 166 && ordinal &lt;=257 ){ season = 'Summer' }else if(ordinal &gt; 257 && ordinal &lt;=349 ){ season = 'Fall' } roll = Math.floor(Math.random()*(20-1+1)+1); if(roll&gt;=15 && roll&lt;=17){ switch(season) { case 'Winter': temperature = 'It is a bitterly cold winter day. '; break; case 'Spring': temperature = 'It is a cold spring day. '; break; case 'Summer': temperature = 'It is a cool summer day. '; break; case 'Fall': temperature = 'It is a cold fall day. '; break; } }else if(roll&gt;=18 && roll&lt;=20){ switch(season) { case 'Winter': temperature = 'It is a warm winter day. '; break; case 'Spring': temperature = 'It is a hot spring day. '; break; case 'Summer': temperature = 'It is a blisteringly hot summer day. '; break; case 'Fall': temperature = 'It is a hot fall day. '; break; } }else{ switch(season) { case 'Winter': temperature = 'It is a cold winter day. '; break; case 'Spring': temperature = 'It is a mild spring day. '; break; case 'Summer': temperature = 'It is a hot summer day. '; break; case 'Fall': temperature = 'It is a mild fall day. '; break; } } roll = Math.floor(Math.random()*(20-1+1)+1); if(roll&gt;=15 && roll&lt;=17){ wind='There is a light breeze and '; }else if(roll&gt;=18 && roll&lt;=20){ wind='There is a howling wind and '; }else{ wind='The air is still and '; } roll = Math.floor(Math.random()*(20-1+1)+1); if(roll&gt;=15 && roll&lt;=17){ precipitation="Light rain or snow."; if(season=='Winter'){ precipitation = 'snow falls softly on the ground.'; }else{ precipitation = 'a light rain falls from the sky.'; } }else if(roll&gt;=18 && roll&lt;=20){ if(season=='Winter'){ precipitation = 'snow falls thick and fast from the sky.'; }else{ precipitation = 'a torrential rain begins to fall.'; } }else{ roll = Math.floor(Math.random()*(2-1+1)+1); if(roll=1){ precipitation = 'the sky is overcast.'; }else{ precipitation = 'the sky is clear.'; } } var forecast=temperature+wind+precipitation; state.Calendar.now.weather = forecast; }, getmoon = function() { var ordinal = state.Calendar.now.ordinal; var moonNo; var moon; moonNo = Math.ceil(ordinal/3)-Math.floor(Math.ceil(ordinal/3)/8)*8; switch(moonNo) { case 1: moon = 'First Quarter'; break; case 2: moon = 'Waxing Cresent'; break; case 3: moon = 'New'; break; case 4: moon = 'Waning Cresent'; break; case 5: moon = 'Third Quarter'; break; case 6: moon = 'Waning Gibbous'; break; case 7: moon = 'Full'; break; case 0: moon = 'Waxing Gibbous'; break; } return moon; }, checkInstall = function() { // Check if the Calendar property exists, creating it if it doesn't if( ! state.Calendar ) { setDefaults(); } }, registerEventHandlers = function() { on('chat:message', handleInput); }; return { CheckInstall: checkInstall, RegisterEventHandlers: registerEventHandlers }; }()); on("ready",function(){ 'use strict'; Calendar.CheckInstall(); Calendar.RegisterEventHandlers(); });
1513828550
Kirsty
Pro
Sheet Author
Hey Nover. I'm visiting family over the holidays so I'm not on Roll20 very frequently right now. If no one else jumps in with some code, I'll be happy to have a look at it for you. I'm a slow coder at the best of times so please bear with me!
1513865264
Kirsty
Pro
Sheet Author
I just had a look and it seems like you're using an old version of the calendar. Any reason you're not using the most up to date version? The newest version has the option to turn down days on and off and does have a time function already. It would be much easier to adjust the newest version to give you a 24 hour clock rather than bring it into the older version. That way I can give the option to everyone who uses the calendar. Please have a look at it and let me know! The latest version can be found:&nbsp; On github
ah, thought the multi-world was different like greyhawk and I am based off the faerun campaign. Gonna check it out. Thanks.
1513899487
Kirsty
Pro
Sheet Author
I've updated the script to include an "advance the time" button. Please note that in order to use that button, you have to set the time type to "24 hour" and set the initial time. The error checking isn't great, it's on my list of things to improve. This version of the script also includes moon images, which was an old request I've been working on for a while. Latest version.
Kirsty said: I've updated the script to include an "advance the time" button. Please note that in order to use that button, you have to set the time type to "24 hour" and set the initial time. The error checking isn't great, it's on my list of things to improve. This version of the script also includes moon images, which was an old request I've been working on for a while. Latest version. At this point, from what I have seen, I love your Calendar API. I just wonder if there is a way to handle custom calendars, i.e. 8 months with 48 days per month.
1513940706

Edited 1513940732
Kirsty
Pro
Sheet Author
Theodore S: Right now, putting a custom calendar in the api is not possible. The weather tables and moon cycles make it too complicated. That being said, if you pm me with details, I'm happy to send you a personalized version for your world.