Skip to content

Instantly share code, notes, and snippets.

@BaldarSilveraxe
Created December 4, 2013 20:40
Show Gist options
  • Save BaldarSilveraxe/7795128 to your computer and use it in GitHub Desktop.
Save BaldarSilveraxe/7795128 to your computer and use it in GitHub Desktop.
Roll20 Calendar and weather report
//API:Events:ChatMessage:processAPIswitch:Chronos:report**********************************************
roll20API.processAPIreportChronos = function() {
//Check for GM_Chronos report
var GM_Chronoslength = findObjs({ _type: "handout", name: "GM_Chronos_Report" }).length
var GM_ChronosExist = false;
if(GM_Chronoslength !== 0){
GM_ChronosExist = true;
}else{
GM_ChronosExist = false;
};
//Add if needed
if(GM_ChronosExist == false){
createObj("handout", {
name: "GM_Chronos_Report",
notes: "Report will be updated shortly"
});
};
//get the values need for the report
var GETcurrentRegion = findObjs({ _type: "attribute", name: "Region", _characterid: GM_Chronosid})[0].get("current");
var GETcurrentTerrain = findObjs({ _type: "attribute", name: "Terrain", _characterid: GM_Chronosid})[0].get("current");
var GETcurrentMinute = findObjs({ _type: "attribute", name: "Minute", _characterid: GM_Chronosid})[0].get("current");
var GETcurrentHour = findObjs({ _type: "attribute", name: "Hour", _characterid: GM_Chronosid})[0].get("current");
var GETcurrentDay = findObjs({ _type: "attribute", name: "Day", _characterid: GM_Chronosid})[0].get("current");
var GETcurrentMonth = findObjs({ _type: "attribute", name: "Month", _characterid: GM_Chronosid})[0].get("current");
var GETcurrentYear = findObjs({ _type: "attribute", name: "Year", _characterid: GM_Chronosid})[0].get("current");
var GETcurrentSeason = findObjs({ _type: "attribute", name: "Season", _characterid: GM_Chronosid})[0].get("current");
var GETcurrentTempHigh = findObjs({ _type: "attribute", name: "TempHigh", _characterid: GM_Chronosid})[0].get("current");
var GETcurrentTempLow = findObjs({ _type: "attribute", name: "TempLow", _characterid: GM_Chronosid})[0].get("current");
var GETcurrentWindDir = findObjs({ _type: "attribute", name: "WindDir", _characterid: GM_Chronosid})[0].get("current");
var GETcurrentWindSpd = findObjs({ _type: "attribute", name: "WindSpd", _characterid: GM_Chronosid})[0].get("current");
var GETcurrentCodeA3 = findObjs({ _type: "attribute", name: "CodeA3", _characterid: GM_Chronosid})[0].get("current");
var GETcurrentCodeA4 = findObjs({ _type: "attribute", name: "CodeA4", _characterid: GM_Chronosid})[0].get("current");
//look up moon and tide
var ckey = null;
var gkey = null;
var moonValue = "Blue Moon";
var tideValue = "Red Tide";
var lowtideValue = "15";
var hightideValue = "18";
for (var loopmoonTide in roll20API.moonTide) {
var ckey = roll20API.moonTide[loopmoonTide].month;
ckey = ckey + roll20API.moonTide[loopmoonTide].day;
var gkey = GETcurrentMonth;
gkey = gkey + GETcurrentDay;
if(ckey == gkey){
moonValue = roll20API.moonTide[loopmoonTide].moon;
tideValue = roll20API.moonTide[loopmoonTide].tide;
lowtideValue = roll20API.moonTide[loopmoonTide].lowtide;
hightideValue = roll20API.moonTide[loopmoonTide].hightide;
};
};
//look up month fantasy name
var ckey = null;
var gkey = null;
var nameMonthValue = "Frostmoot";
var displaymonthValue = "11";
for (var loopcalendarYear in roll20API.calendarYear) {
var ckey = roll20API.calendarYear[loopcalendarYear].month;
var gkey = GETcurrentMonth;
if(ckey == gkey){
nameMonthValue = roll20API.calendarYear[loopcalendarYear].name;
displaymonthValue = roll20API.calendarYear[loopcalendarYear].displaymonth;
};
};
//look up weekDay fantasy name
var ckey = null;
var gkey = null;
var nameDayValue = "Moonday";
for (var loopweekDay in roll20API.weekDays) {
var ckey = roll20API.weekDays[loopweekDay].month;
var gkey = GETcurrentMonth;
if(ckey == gkey){
nameDayValue = roll20API.weekDays[loopweekDayr].name;
};
};
//suffix array
var suffixArray = new Array();
var suffixArray = new Array("NA",
"st","nd","rd","th","th","th","th","th","th","th",
"th","th","th","th","th","th","th","th","th","th",
"st","nd","rd","th","th","th","th","th","th","th",
"st","nd","rd","th","th","th","th","th","th","th")
GETcurrentCodeA3 = "D" //REMOVE
//Rainfall
var PerspirationValue = "No precipitation. "
if(GETcurrentCodeA3 == "-"){
PerspirationValue = "No precipitation.";
};
if(GETcurrentCodeA3 == "T"){
PerspirationValue = "Trace";
if(parseInt(GETcurrentTempLow) >= 36){
PerspirationValue = PerspirationValue + " (less than 1/8\" rain).";
};
if(parseInt(GETcurrentTempHigh) <= 30){
PerspirationValue = PerspirationValue + " (less than 1/2\" snow). ";
};
if(parseInt(GETcurrentTempLow) <= 35 && parseInt(GETcurrentTempHigh) >= 30){
PerspirationValue = PerspirationValue + " (less than 1/8\" sleet and/or 1/2\" snow).";
};
};
if(GETcurrentCodeA3 == "L"){
PerspirationValue = "Light";
if(parseInt(GETcurrentTempLow) >= 36){
PerspirationValue = PerspirationValue + " (less than 1/2\" rain).";
};
if(parseInt(GETcurrentTempHigh) <= 30){
PerspirationValue = PerspirationValue + " (less than 1\" snow). ";
};
if(parseInt(GETcurrentTempLow) <= 35 && parseInt(GETcurrentTempHigh) >= 30){
PerspirationValue = PerspirationValue + " (less than 1/2\" sleet and/or 1\" snow).";
};
};
if(GETcurrentCodeA3 == "M"){
PerspirationValue = "Moderate";
if(parseInt(GETcurrentTempLow) >= 36){
PerspirationValue = PerspirationValue + " (less than 3/4\" rain).";
};
if(parseInt(GETcurrentTempHigh) <= 30){
PerspirationValue = PerspirationValue + " (less than 2\" snow). ";
};
if(parseInt(GETcurrentTempLow) <= 35 && parseInt(GETcurrentTempHigh) >= 30){
PerspirationValue = PerspirationValue + " (less than 3/4\" sleet and/or 2\" snow).";
};
};
if(GETcurrentCodeA3 == "H"){
PerspirationValue = "Heavy";
if(parseInt(GETcurrentTempLow) >= 36){
PerspirationValue = PerspirationValue + " (less than 1 1/2\" rain).";
};
if(parseInt(GETcurrentTempHigh) <= 30){
PerspirationValue = PerspirationValue + " (less than 4\" snow). ";
};
if(parseInt(GETcurrentTempLow) <= 35 && parseInt(GETcurrentTempHigh) >= 30){
PerspirationValue = PerspirationValue + " (less than 1 1/2\" sleet and/or 4\" snow).";
};
};
if(GETcurrentCodeA3 == "D"){
PerspirationValue = "Downpour";
if(parseInt(GETcurrentTempLow) >= 36){
PerspirationValue = PerspirationValue + " (more than 1 1/2\" rain).";
};
if(parseInt(GETcurrentTempHigh) <= 30){
PerspirationValue = PerspirationValue + " (more than 4\" snow). ";
};
if(parseInt(GETcurrentTempLow) <= 35 && parseInt(GETcurrentTempHigh) >= 30){
PerspirationValue = PerspirationValue + " (more than 1 1/2\" sleet and/or 4\" snow).";
};
};
//specail weather
var SCPreportText = "";
var SLCcode = "";
var SLCname = "";
var SLCdescrip = "";
if(GETcurrentCodeA4 !== "-"){
SCPreportText = "<hr><b style='color:#FF0000;'>Special Weather Warning</b><br><br>";
for (var loopSpecialLetterCodes in roll20API.SpecialLetterCodes) {
SLCcode = roll20API.SpecialLetterCodes[loopSpecialLetterCodes].code;
SLCname = roll20API.SpecialLetterCodes[loopSpecialLetterCodes].name;
SLCdescrip = roll20API.SpecialLetterCodes[loopSpecialLetterCodes].descrip;
if(SLCcode == GETcurrentCodeA4){
SCPreportText = SCPreportText + "<b>" + SLCname + "</b><br>";
SCPreportText = SCPreportText + SLCdescrip;
};
};
};
//Create text of the report
var reportText = "<h4>Time and Weather Report</h4><hr>";
reportText = reportText + "<b>Region:</b> " + GETcurrentRegion + "<br>";
reportText = reportText + "<b>Terrain:</b> " + GETcurrentTerrain + "<br>";
reportText = reportText + "<b>Season:</b> " + GETcurrentSeason + "<br>";
reportText = reportText + "<b>Moon:</b> " + moonValue + "<br>";
reportText = reportText + "<b>" + tideValue + ":</b> Low = " + lowtideValue + "' High = " + hightideValue + "'<br>";
reportText = reportText + "<b><i>" + nameDayValue + ", " + displaymonthValue + " the " + parseInt(GETcurrentDay) + suffixArray[parseInt(GETcurrentDay)] + "</i></b><br>";
reportText = reportText + "   <i>" + displaymonthValue + "/" + GETcurrentDay + "/" + GETcurrentYear + " (MM/DD/YYYYY)</i><br>";
reportText = reportText + "   <i>" + GETcurrentHour + ":" + GETcurrentMinute + "</i><br>"
reportText = reportText + "<hr><b>High:</b> " + parseInt(GETcurrentTempHigh) + "\u00B0<br>";
reportText = reportText + "<b>Low:</b> " + parseInt(GETcurrentTempLow) + "\u00B0<br>";
reportText = reportText + "<b>Winds From:</b> " + GETcurrentWindDir + "<br>";
reportText = reportText + "<b>Speed Up To:</b> " + parseInt(GETcurrentWindSpd) + "-mph <br>";
reportText = reportText + "<b>Precipitation:</b> " + PerspirationValue + "<br>";
reportText = reportText + SCPreportText
GM_ChronosReportObject = findObjs({ _type: "handout", name: "GM_Chronos_Report" })
GM_ChronosReportObject[0].set("notes", reportText);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment