Last active
December 30, 2015 05:09
-
-
Save BaldarSilveraxe/7780978 to your computer and use it in GitHub Desktop.
Roll 20 Calendar and Weather
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//API:Events:ChatMessage:processAPIswitch:Chronos:minutes********************************************** | |
roll20API.processAPIminuteChronos = function() { | |
var addNumMins = parseInt(roll20API.valueGiven) + roll20API.currentMinute; | |
if(isNaN(addNumMins)){var addNumMins = 0}; | |
roll20API.tempCarryHours = Math.floor(addNumMins/60); | |
var tempCurrentMinutes = Math.round(((addNumMins/60) % 1) * 60); | |
var newCurrentMinutes = tempCurrentMinutes.toString(); | |
if(newCurrentMinutes.length == 1){newCurrentMinutes = "0" + newCurrentMinutes}; | |
findObjs({ _type: "attribute", name: "Minute", _characterid: GM_Chronosid})[0].set({current: newCurrentMinutes}); | |
}; | |
//API:Events:ChatMessage:processAPIswitch:Chronos:hours********************************************** | |
roll20API.processAPIhourChronos = function() { | |
var addNumHours = parseInt(roll20API.valueGiven) + roll20API.currentHour; | |
if(isNaN(addNumHours)){var addNumHours = 0}; | |
roll20API.tempCarryDays = Math.floor(addNumHours/24); | |
var tempCurrentHours = Math.round(((addNumHours/24) % 1) * 24); | |
var newCurrentHours = tempCurrentHours.toString(); | |
if(newCurrentHours.length == 1){newCurrentHours = "0" + newCurrentHours}; | |
findObjs({ _type: "attribute", name: "Hour", _characterid: GM_Chronosid})[0].set({current: newCurrentHours}); | |
}; | |
//API:Events:ChatMessage:processAPIswitch:Chronos:days********************************************** | |
roll20API.processAPIdayChronos = function() { | |
roll20API.currentDay = parseInt(findObjs({ _type: "attribute", name: "Day", _characterid: GM_Chronosid})[0].get("current")); | |
var addNumDays = parseInt(roll20API.valueGiven) + parseInt(roll20API.currentDay); | |
if(isNaN(addNumDays)){var addNumDays = 0}; | |
if(addNumDays <= parseInt(roll20API.daysInCurrentMonth) + 1){ | |
roll20API.daysLeftOver = 0; | |
var newCurrentDays = addNumDays.toString(); | |
if(newCurrentDays.length == 1){newCurrentDays = "0" + newCurrentDays}; | |
findObjs({ _type: "attribute", name: "Day", _characterid: GM_Chronosid})[0].set({current: newCurrentDays}); | |
}; | |
if(addNumDays >= parseInt(roll20API.daysInCurrentMonth) + 1){ | |
roll20API.daysLeftOver = parseInt(addNumDays) - parseInt(roll20API.daysInCurrentMonth) - 1; | |
addNumDays = 1; | |
tempCurrentMonth = roll20API.currentMonth + 1; | |
if(tempCurrentMonth >= 13){ | |
newCurrentYear = parseInt(roll20API.currentYear) + 1; | |
roll20API.currentYear = newCurrentYear; | |
newCurrentYearstr = newCurrentYear.toString() | |
var pad = "00000" | |
var newYearPad = pad.substring(0, pad.length - newCurrentYearstr.length) + newCurrentYearstr | |
roll20API.currentYear = newCurrentYear; | |
findObjs({ _type: "attribute", name: "Year", _characterid: GM_Chronosid})[0].set({current: newYearPad}); | |
tempCurrentMonth = 1; | |
}; | |
var newCurrentDays = addNumDays.toString(); | |
if(newCurrentDays.length == 1){newCurrentDays = "0" + newCurrentDays}; | |
findObjs({ _type: "attribute", name: "Day", _characterid: GM_Chronosid})[0].set({current: newCurrentDays}); | |
var newCurrentMonths = tempCurrentMonth.toString(); | |
if(newCurrentMonths.length == 1){newCurrentMonths = "0" + newCurrentMonths}; | |
findObjs({ _type: "attribute", name: "Month", _characterid: GM_Chronosid})[0].set({current: newCurrentMonths}); | |
roll20API.currentMonth = parseInt(findObjs({ _type: "attribute", name: "Month", _characterid: GM_Chronosid})[0].get("current")); | |
for (var loopcalendarYear in roll20API.calendarYear) { | |
if(roll20API.calendarYear[loopcalendarYear].month == roll20API.currentMonth){ | |
roll20API.daysInCurrentMonth = roll20API.calendarYear[loopcalendarYear].days; | |
}; | |
}; | |
}; | |
}; | |
//API:Events:ChatMessage:processAPIswitch:Chronos:Month Check********************************************** | |
roll20API.processAPImonthCheckChronos = function() { | |
//set default values if out of range | |
var correctDay = 15 | |
//get current values to check | |
var CHECKcurrentMinute = parseInt(findObjs({ _type: "attribute", name: "Minute", _characterid: GM_Chronosid})[0].get("current")); | |
var CHECKcurrentHour = parseInt(findObjs({ _type: "attribute", name: "Hour", _characterid: GM_Chronosid})[0].get("current")); | |
var CHECKcurrentDay = parseInt(findObjs({ _type: "attribute", name: "Day", _characterid: GM_Chronosid})[0].get("current")); | |
var CHECKcurrentMonth = parseInt(findObjs({ _type: "attribute", name: "Month", _characterid: GM_Chronosid})[0].get("current")); | |
var CHECKcurrentYear = parseInt(findObjs({ _type: "attribute", name: "Year", _characterid: GM_Chronosid})[0].get("current")); | |
var CHECKcurrentRegion = findObjs({ _type: "attribute", name: "Region", _characterid: GM_Chronosid})[0].get("current"); | |
var CHECKcurrentTerrain = findObjs({ _type: "attribute", name: "Terrain", _characterid: GM_Chronosid})[0].get("current"); | |
//if not a number set to -1 | |
if(isNaN(CHECKcurrentMinute)){CHECKcurrentMinute = -1}; | |
if(isNaN(CHECKcurrentHour)){CHECKcurrentHour = -1}; | |
if(isNaN(CHECKcurrentMonth)){CHECKcurrentMonth = -1}; | |
if(isNaN(CHECKcurrentYear)){CHECKcurrentYear = -1}; | |
//check minutes between 0-60 set to 00 if not | |
if(CHECKcurrentMinute <= -1 || CHECKcurrentMinute >= 60){ | |
findObjs({ _type: "attribute", name: "Minute", _characterid: GM_Chronosid})[0].set({current: "00"}); | |
}; | |
//check hours between 0-24 set to 12 if not | |
if(CHECKcurrentHour <= -1 || CHECKcurrentHour >= 24){ | |
findObjs({ _type: "attribute", name: "Hour", _characterid: GM_Chronosid})[0].set({current: "12"}); | |
}; | |
//check Month < 1 set to 01 | |
if(CHECKcurrentMonth <= -1){ | |
findObjs({ _type: "attribute", name: "Month", _characterid: GM_Chronosid})[0].set({current: "01"}); | |
}; | |
//check Month > 13 set to 12 | |
if(CHECKcurrentMonth >= 13){ | |
findObjs({ _type: "attribute", name: "Month", _characterid: GM_Chronosid})[0].set({current: "12"}); | |
}; | |
//get month Again | |
CHECKcurrentMonth = parseInt(findObjs({ _type: "attribute", name: "Month", _characterid: GM_Chronosid})[0].get("current")); | |
//get max day for the month | |
for (var loopMonthCheck in roll20API.calendarYear) { | |
if(roll20API.calendarYear[loopMonthCheck].month == CHECKcurrentMonth){ | |
var maxdaysmonth = roll20API.calendarYear[loopMonthCheck].days; | |
}; | |
}; | |
//set day to max if over | |
if(parseInt(CHECKcurrentDay) >= (parseInt(maxdaysmonth)) + 1){ | |
findObjs({ _type: "attribute", name: "Day", _characterid: GM_Chronosid})[0].set({current: maxdaysmonth}); | |
}; | |
//set day to 01 if <=0 | |
if(CHECKcurrentDay <= 0){ | |
findObjs({ _type: "attribute", name: "Day", _characterid: GM_Chronosid})[0].set({current: "01"}); | |
}; | |
//check year for under 0 | |
if(CHECKcurrentYear <= -1){ | |
findObjs({ _type: "attribute", name: "Year", _characterid: GM_Chronosid})[0].set({current: "00000"}); | |
}; | |
//check year for over 99999 | |
if(CHECKcurrentYear >= 100000){ | |
findObjs({ _type: "attribute", name: "Year", _characterid: GM_Chronosid})[0].set({current: "99999"}); | |
}; | |
//if Region = Artic and Terrain = Forest change to Hills (no forest in the artic) | |
if(CHECKcurrentRegion == "Arctic" && CHECKcurrentTerrain == "Forest"){ | |
findObjs({ _type: "attribute", name: "Terrain", _characterid: GM_Chronosid})[0].set({current: "Hills"}); | |
}; | |
}; | |
//API:Events:ChatMessage:processAPIswitch:Chronos:Weather********************************************** | |
roll20API.processAPIweatherChronos = function(resetWeather, countDay) { | |
//get values needed from current | |
var GETcurrentMonth = findObjs({ _type: "attribute", name: "Month", _characterid: GM_Chronosid})[0].get("current"); | |
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 GETcurrentWindSpd = findObjs({ _type: "attribute", name: "WindSpd", _characterid: GM_Chronosid})[0].get("current"); | |
var GETcurrentCodeA1 = findObjs({ _type: "attribute", name: "CodeA1", _characterid: GM_Chronosid})[0].get("current"); | |
var CodeA1Value = parseInt(GETcurrentCodeA1); | |
//get allowable ranges roll20API.TempVarA1 | |
var ckey = null; | |
var gkey = null; | |
var LowValue = null; | |
var AveValue = null; | |
var MaxValue = null; | |
var seasonValue = "Spring"; | |
for (var loopTempVarA1 in roll20API.TempVarA1) { | |
var ckey = roll20API.TempVarA1[loopTempVarA1].regions; | |
ckey = ckey + roll20API.TempVarA1[loopTempVarA1].terrain; | |
ckey = ckey + roll20API.TempVarA1[loopTempVarA1].month; | |
var gkey = GETcurrentRegion | |
gkey = gkey + GETcurrentTerrain | |
gkey = gkey + GETcurrentMonth | |
//"ABC".charCodeAt(0) | |
if(ckey == gkey){ | |
LowValue = parseInt(roll20API.TempVarA1[loopTempVarA1].low); | |
AveValue = parseInt(roll20API.TempVarA1[loopTempVarA1].mean); | |
MaxValue = parseInt(roll20API.TempVarA1[loopTempVarA1].high); | |
seasonValue = roll20API.TempVarA1[loopTempVarA1].season | |
}; | |
}; | |
//default roll20API.TempVarA2 results | |
var netStep = 0; | |
var precipitationStep = "S"; | |
var windDirStep = "Prevailing"; | |
var windSpdStep = "+000"; | |
var noteStep = "-"; | |
var windSpdStepNetChange = parseInt(windSpdStep); | |
//for each day step up/down on roll20API.TempVarA2 | |
for (var loopcountDay=0;loopcountDay<countDay;loopcountDay++){ | |
//roll 2 dice (need both and sum) | |
var diceOne = Math.floor((Math.random()*6)+1); | |
var diceTwo = Math.floor((Math.random()*6)+1); | |
var diceSum = diceOne + diceTwo; | |
for (var loopTempVarA2 in roll20API.TempVarA2) { | |
if(parseInt(roll20API.TempVarA2[loopTempVarA2].dice) == diceSum){ | |
netStep = netStep + parseInt(roll20API.TempVarA2[loopTempVarA2].step); | |
if(isNaN(parseInt(roll20API.TempVarA2[loopTempVarA2].windSpd)) == false){ | |
if(windSpdStepNetChange + parseInt(roll20API.TempVarA2[loopTempVarA2].windSpd) >= 0){ | |
windSpdStepNetChange = windSpdStepNetChange + parseInt(roll20API.TempVarA2[loopTempVarA2].windSpd); | |
}; | |
}; | |
precipitationStep = roll20API.TempVarA2[loopTempVarA2].precipitation; | |
windDirStep = roll20API.TempVarA2[loopTempVarA2].windDir; | |
windSpdStep = roll20API.TempVarA2[loopTempVarA2].windSpd; | |
noteStep = roll20API.TempVarA2[loopTempVarA2].note; | |
}; | |
}; | |
}; | |
//set the CodeA1 Value to what it should be | |
CodeA1Value = CodeA1Value + netStep | |
if(CodeA1Value < LowValue){CodeA1Value = LowValue}; | |
if(CodeA1Value > MaxValue){CodeA1Value = MaxValue}; | |
//added for bug... need to check | |
if(CodeA1Value > 26){CodeA1Value = 26;}; | |
if(CodeA1Value < 1){CodeA1Value = 1;}; | |
CodeA1Chr = CodeA1Value.toString(); | |
var lowTempFound = "-020"; | |
var highTempFound = "-040"; | |
for (var loopTempVarA1code in roll20API.TempVarA1code) { | |
if(roll20API.TempVarA1code[loopTempVarA1code].code == CodeA1Chr){ | |
lowTempFound = roll20API.TempVarA1code[loopTempVarA1code].lowCode; | |
highTempFound = roll20API.TempVarA1code[loopTempVarA1code].highCode; | |
}; | |
}; | |
//pad and level cap wind | |
var padwind = "000"; | |
if(noteStep !== "!"){ | |
if(windSpdStepNetChange >= 46){windSpdStepNetChange = 45}; | |
if(GETcurrentRegion == "Subarctic" && windSpdStepNetChange >= 31){windSpdStepNetChange = 30}; | |
if(GETcurrentRegion == "Tropical" && windSpdStepNetChange >= 21){windSpdStepNetChange = 20}; | |
if(GETcurrentRegion == "Arctic" && windSpdStepNetChange >= 21){windSpdStepNetChange = 20}; | |
} | |
var windstr = windSpdStepNetChange.toString() | |
var windstrPad = "+" + padwind.substring(0, padwind.length - windstr.length) + windstr; | |
//record values | |
findObjs({ _type: "attribute", name: "CodeA1", _characterid: GM_Chronosid})[0].set({current: CodeA1Chr}); | |
findObjs({ _type: "attribute", name: "TempHigh", _characterid: GM_Chronosid})[0].set({current: highTempFound}); | |
findObjs({ _type: "attribute", name: "TempLow", _characterid: GM_Chronosid})[0].set({current: lowTempFound}); | |
if(windDirStep !== "Same"){ | |
findObjs({ _type: "attribute", name: "WindDir", _characterid: GM_Chronosid})[0].set({current: windDirStep}); | |
}; | |
findObjs({ _type: "attribute", name: "WindSpd", _characterid: GM_Chronosid})[0].set({current: windstrPad}); | |
findObjs({ _type: "attribute", name: "ChancePrecip", _characterid: GM_Chronosid})[0].set({current: precipitationStep}); | |
findObjs({ _type: "attribute", name: "Season", _characterid: GM_Chronosid})[0].set({current: seasonValue}); | |
findObjs({ _type: "attribute", name: "NoteA2", _characterid: GM_Chronosid})[0].set({current: noteStep}); | |
}; | |
//API:Events:ChatMessage:processAPIswitch:Chronos:rain********************************************** | |
roll20API.processAPIrainChronos = function() { | |
//get values needed from current | |
var GETcurrentSeason = findObjs({ _type: "attribute", name: "Season", _characterid: GM_Chronosid})[0].get("current"); | |
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"); | |
//get allowable ranges roll20API.TempRainA3 | |
var ckey = null; | |
var gkey = null; | |
var AValue = "-"; | |
var BValue = "-"; | |
var CValue = "-"; | |
for (var loopTempRainA in roll20API.TempVarA1) { | |
var ckey = roll20API.TempVarA1[loopTempRainA].regions; | |
ckey = ckey + roll20API.TempVarA1[loopTempRainA].terrain; | |
ckey = ckey + roll20API.TempVarA1[loopTempRainA].season; | |
var gkey = GETcurrentRegion; | |
gkey = gkey + GETcurrentTerrain; | |
gkey = gkey + GETcurrentSeason; | |
if(ckey == gkey){ | |
AValue = roll20API.TempVarA1[loopTempRainA].rain_a; | |
BValue = roll20API.TempVarA1[loopTempRainA].rain_b; | |
CValue = roll20API.TempVarA1[loopTempRainA].rain_c; | |
}; | |
}; | |
var diceOne = Math.floor((Math.random()*6)+1); | |
var diceTwo = Math.floor((Math.random()*6)+1); | |
var CodeA3Var = AValue; | |
if(diceOne > diceTwo){CodeA3Var = AValue}; | |
if(diceOne = diceTwo){CodeA3Var = BValue}; | |
if(diceOne < diceTwo){CodeA3Var = CValue}; | |
findObjs({ _type: "attribute", name: "CodeA3", _characterid: GM_Chronosid})[0].set({current: CodeA3Var}); | |
}; | |
//API:Events:ChatMessage:processAPIswitch:Chronos:special********************************************** | |
roll20API.processAPIspecialChronos = function() { | |
//get values needed from current | |
var GETcurrentSeason = findObjs({ _type: "attribute", name: "Season", _characterid: GM_Chronosid})[0].get("current"); | |
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"); | |
//get allowable ranges roll20API.TempRainA3 | |
var ckey = null; | |
var gkey = null; | |
var AValue = "-"; | |
var BValue = "-"; | |
var CValue = "-"; | |
var DValue = "-"; | |
for (var loopTempSpcA4 in roll20API.TempVarA1) { | |
var ckey = roll20API.TempVarA1[loopTempSpcA4].regions; | |
ckey = ckey + roll20API.TempVarA1[loopTempSpcA4].terrain; | |
ckey = ckey + roll20API.TempVarA1[loopTempSpcA4].season; | |
var gkey = GETcurrentRegion; | |
gkey = gkey + GETcurrentTerrain; | |
gkey = gkey + GETcurrentSeason; | |
if(ckey == gkey){ | |
AValue = roll20API.TempVarA1[loopTempSpcA4].A; | |
BValue = roll20API.TempVarA1[loopTempSpcA4].B; | |
CValue = roll20API.TempVarA1[loopTempSpcA4].C; | |
DValue = roll20API.TempVarA1[loopTempSpcA4].D; | |
}; | |
}; | |
var diceOne = Math.floor((Math.random()*6)+1); | |
var diceTwo = Math.floor((Math.random()*6)+1); | |
var RollOneSum = diceOne + diceTwo | |
var diceThree = Math.floor((Math.random()*6)+1); | |
var diceFour = Math.floor((Math.random()*6)+1); | |
var RollTwoSum = diceThree + diceFour | |
var CodeA4Var = "-"; | |
if(RollOneSum == 2){ | |
if(RollTwoSum <= 4){CodeA4Var = AValue;}; | |
if(RollTwoSum == 5 || RollTwoSum == 6 || RollTwoSum == 7){CodeA4Var = BValue;}; | |
}; | |
if(RollOneSum == 12){ | |
if(RollTwoSum >= 10){CodeA4Var = CValue;}; | |
if(RollTwoSum == 8 || RollTwoSum == 9 || RollTwoSum == 7){CodeA4Var = DValue;}; | |
}; | |
findObjs({ _type: "attribute", name: "CodeA4", _characterid: GM_Chronosid})[0].set({current: CodeA4Var}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment