Skip to content

Instantly share code, notes, and snippets.

@BaldarSilveraxe
Last active December 30, 2015 05:09
Show Gist options
  • Save BaldarSilveraxe/7780941 to your computer and use it in GitHub Desktop.
Save BaldarSilveraxe/7780941 to your computer and use it in GitHub Desktop.
Roll20 Calendar and weather scpits
//API:Events:ChatMessage:processAPIswitch:Chronos:add**********************************************
roll20API.processAPIaddChronos = function() {
//Add Chronos sheet if needed
if(findObjs({ _type: "character", name: "GM_Chronos" }).length == 0){
createObj("character", {
name: "GM_Chronos",
bio: "Text Here"
});
GM_ChronosObject = findObjs({ _type: "character", name: "GM_Chronos" })
GM_Chronosid = GM_ChronosObject[0].id
for (var index in roll20API.attribs) {
createObj("attribute", {
name: roll20API.attribs[index].name,
current: roll20API.attribs[index].current,
max: roll20API.attribs[index].max,
characterid: GM_Chronosid
});
};
for (var ability in roll20API.abilities) {
createObj("ability", {
name: roll20API.abilities[ability].name,
description: "",
action: roll20API.abilities[ability].action,
characterid: GM_Chronosid
});
};
}else{
GM_ChronosObject = findObjs({ _type: "character", name: "GM_Chronos" })
GM_Chronosid = GM_ChronosObject[0].id
};
//API values
roll20API.commandChronos = roll20API.Long;
roll20API.valueGiven = roll20API.message;
roll20API.textGiven = roll20API.message;
//get Chronos current
roll20API.startMinute = findObjs({ _type: "attribute", name: "Minute", _characterid: GM_Chronosid})[0].get("current");
roll20API.startHour = findObjs({ _type: "attribute", name: "Hour", _characterid: GM_Chronosid})[0].get("current");
roll20API.startDay = findObjs({ _type: "attribute", name: "Day", _characterid: GM_Chronosid})[0].get("current");
roll20API.startMonth = findObjs({ _type: "attribute", name: "Month", _characterid: GM_Chronosid})[0].get("current");
roll20API.startYear = findObjs({ _type: "attribute", name: "Year", _characterid: GM_Chronosid})[0].get("current");
//get Chronos values
roll20API.currentMinute = parseInt(findObjs({ _type: "attribute", name: "Minute", _characterid: GM_Chronosid})[0].get("current"));
roll20API.currentHour = parseInt(findObjs({ _type: "attribute", name: "Hour", _characterid: GM_Chronosid})[0].get("current"));
roll20API.currentDay = parseInt(findObjs({ _type: "attribute", name: "Day", _characterid: GM_Chronosid})[0].get("current"));
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;
};
};
roll20API.currentYear = parseInt(findObjs({ _type: "attribute", name: "Year", _characterid: GM_Chronosid})[0].get("current"));
//carry values for incriments of time
roll20API.valueGiven = roll20API.message
roll20API.tempCarryHours = 0;
roll20API.tempCarryDays = 0;
roll20API.daysLeftOver = 0;
//Add minutes
if(roll20API.commandChronos == "numMinuteChronos" || roll20API.commandChronos == "addMinuteChronos"){
if(roll20API.commandChronos == "addMinuteChronos"){roll20API.valueGiven = 1};
roll20API.processAPIminuteChronos();
if(roll20API.tempCarryHours !== 0){
roll20API.valueGiven = roll20API.tempCarryHours
roll20API.processAPIhourChronos();
};
};
//add hours
if(roll20API.commandChronos == "numHourChronos" || roll20API.commandChronos == "addHourChronos"){
if(roll20API.commandChronos == "addHourChronos"){roll20API.valueGiven = 1};
roll20API.processAPIhourChronos();
if(roll20API.tempCarryDays !== 0){
roll20API.commandChronos = "numDayChronos";
roll20API.valueGiven = roll20API.tempCarryDays;
};
};
//add days
if(roll20API.commandChronos == "numDayChronos" || roll20API.commandChronos == "addDayChronos"){
if(roll20API.commandChronos == "addDayChronos"){roll20API.valueGiven = 1};
roll20API.processAPIdayChronos();
while(roll20API.daysLeftOver >= 1){
roll20API.valueGiven = roll20API.daysLeftOver;
roll20API.processAPIdayChronos();
};
};
var forceUpdate = false;
//regionsChronos
if(roll20API.commandChronos == "regionsChronos"){
findObjs({ _type: "attribute", name: "Region", _characterid: GM_Chronosid})[0].set({current: roll20API.textGiven});
forceUpdate = true;
};
//terrainChronos
if(roll20API.commandChronos == "terrainChronos"){
findObjs({ _type: "attribute", name: "Terrain", _characterid: GM_Chronosid})[0].set({current: roll20API.textGiven});
forceUpdate = true;
};
//validate values
roll20API.processAPImonthCheckChronos();
//get Chronos final
roll20API.endtMinute = findObjs({ _type: "attribute", name: "Minute", _characterid: GM_Chronosid})[0].get("current");
roll20API.endtHour = findObjs({ _type: "attribute", name: "Hour", _characterid: GM_Chronosid})[0].get("current");
roll20API.endDay = findObjs({ _type: "attribute", name: "Day", _characterid: GM_Chronosid})[0].get("current");
roll20API.endMonth = findObjs({ _type: "attribute", name: "Month", _characterid: GM_Chronosid})[0].get("current");
roll20API.endYear = findObjs({ _type: "attribute", name: "Year", _characterid: GM_Chronosid})[0].get("current");
for (var loopcalendarYear in roll20API.calendarYear) {
if(roll20API.calendarYear[loopcalendarYear].month == roll20API.endMonth){
roll20API.numberDaysinMonth = roll20API.calendarYear[loopcalendarYear].days;
roll20API.seasonMonth = roll20API.calendarYear[loopcalendarYear].season;
roll20API.nameMonth = roll20API.calendarYear[loopcalendarYear].name;
};
};
var daynumberofweek = parseInt(roll20API.endDay) - ((Math.ceil(parseInt(roll20API.endDay)/7)-1)*7)
var daynumberofweekstr = daynumberofweek.toString();
for (var loopweekDays in roll20API.weekDays) {
if(roll20API.weekDays[loopweekDays].weekdayValue == daynumberofweekstr){
roll20API.weekDayName = roll20API.weekDays[loopweekDays].name;
};
};
//Check for weather reset and type of weather reset
findObjs({ _type: "attribute", name: "CodeA4", _characterid: GM_Chronosid})[0].set({current: "-"});
var dayCount = Math.abs(parseInt(roll20API.startDay) - parseInt(roll20API.endDay));
var resetWeatherType = "None";
if(roll20API.startYear !== roll20API.endYear || roll20API.startMonth !== roll20API.endMonth || forceUpdate == true){
resetWeatherType = "Reset";
dayCount = 1;
roll20API.processAPIweatherChronos(resetWeatherType, dayCount);
};
if(resetWeatherType == "None" && roll20API.startDay !== roll20API.endDay){
resetWeatherType = "Day";
roll20API.processAPIweatherChronos(resetWeatherType, dayCount);
};
if(resetWeatherType == "None" && findObjs({ _type: "character", name: "GM_Chronos" }).length == 0){
resetWeatherType = "Day";
dayCount = 1;
roll20API.processAPIweatherChronos(resetWeatherType, dayCount);
};
//check for rain
var GETChancePrecip = findObjs({ _type: "attribute", name: "ChancePrecip", _characterid: GM_Chronosid})[0].get("current");
if(GETChancePrecip == "Y"){
roll20API.processAPIrainChronos();
}else{
findObjs({ _type: "attribute", name: "CodeA3", _characterid: GM_Chronosid})[0].set({current: "-"});
};
//check for special Weather
var GETNoteA2 = findObjs({ _type: "attribute", name: "NoteA2", _characterid: GM_Chronosid})[0].get("current");
if(GETNoteA2 !== "-"){
roll20API.processAPIspecialChronos();
};
//create and or update report
roll20API.processAPIreportChronos();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment