pr6i6e6st
May 4th, 2020, 08:42
edit: almost have it, bust still off. when a day changes, my current date in minutes comes back as less than my startdate in minutes for some reason. so once the calendar has been changed and it hits midnight, it returns the difference to be greater than 1440 minutes then sets the time to start over for another cycle.
--Timer Functions--
function setStartTime(rActor, sFirst)
local sActorType, nodeActor = ActorManager.getTypeAndNode(rActor);
nStartTime = getCurrentDateinMinutes(rActor);
DB.setValue(nodeActor, "" .. sFirst .. ".starttime", "number", nStartTime);
Debug.console("setStartTime called; nStartTime = ", nStartTime);
end
function getStartTime(rActor, sFirst)
local sActorType, nodeActor = ActorManager.getTypeAndNode(rActor);
local nRound = DB.getValue(nodeActor, "game.round", 0);
nStartTime = getCurrentDateinMinutes(nRound)
FetchStartTime = DB.getValue(nodeActor, "" .. sFirst .. ".starttime", 0);
return FetchStartTime;
end
function getCurrentDateinMinutes()
local nMinutes = DB.getValue("calendar.current.minute");
local nHours = DB.getValue("calendar.current.hour");
local nDays = DB.getValue("calendar.current.day");
local nMonths = DB.getValue("calendar.current.month");
local nYears = DB.getValue("calendar.current.year");
Debug.console("getCurrentDateinMinutes called; nMinutes, nHours, nDays, nMonths, nYears =", nMinutes, nHours, nDays, nMonths, nYears);
nHoursinMinutes = convertHourstoMinutes(nHours);
nDaysinMinutes = convertDaystoMinutes(nDays);
nMonthsinMinutes = convertMonthssnowtoMinutes(nMonths);
nYearsinMinutes = convertYearsnowtoMinutes(nYears);
Debug.console("getCurrentDateinMinutes called; nHoursinMinutes, nDaysinMinutes, nMonthsinMinutes, nYearsinMinutes =", nHoursinMinutes, nDaysinMinutes, nMonthsinMinutes, nYearsinMinutes);
nDateinMinutes = nHoursinMinutes + nDaysinMinutes + nMonthsinMinutes + nYearsinMinutes + nMinutes;
Debug.console("getCurrentDateinMinutes called; nDateinMinutes =", nDateinMinutes);
return nDateinMinutes;
end
--Compare times --
function isTimeGreaterThan(rActor, sFirst, nCompareBy)
local sActorType, nodeActor = ActorManager.getTypeAndNode(rActor);
local nRound = DB.getValue(nodeActor, "game.round", 0);
local nStartTime = getStartTime(rActor, sFirst);
local nCurrentTime = getCurrentDateinMinutes();
local nDifference = nCurrentTime - nStartTime;
Debug.console("isTimeGreaterThan called; nDifference, nCurrentTime, nStartTime = ", nDifference, nCurrentTime, nStartTime);
if nDifference > nCompareBy then
return true;
elseif nDifference <= nCompareBy then
return false;
end
end
function getTimeDifference(rActor, sFirst, nCompareBy)
local sActorType, nodeActor = ActorManager.getTypeAndNode(rActor);
local nRound = DB.getValue(nodeActor, "game.round", 0);
local nStartTime = DB.getValue(nodeActor, "" .. sFirst .. ".starttime", 0);
local nCurrentTime = getCurrentDateinMinutes();
nDifference = nCurrentTime - nStartTime;
Debug.console("isTimeGreaterThan called; nDifference, nCurrentTime, nStartTime = ", nDifference, nCurrentTime, nStartTime);
return nDifference;
end
--convert time functions --
function convertHourstoMinutes(nNumber)
local nMinutesTotaled = nNumber * 60;
return nMinutesTotaled;
end
function convertMinutestoHours(nNumber)
local nHoursTotaled = nNumber / 60;
return nHoursTotaled;
end
function convertHourstoDays(nNumber)
local nDaysTotaled = nNumber / 24);
return nDaysTotaled;
end
function convertDaystoHours(nNumber)
local nHoursTotaled = nNumber * 24;
return nHoursTotaled;
end
function convertMinutestoDays(nNumber)
local nHoursTotaled = convertMinutestoHours(nNumber);
local nDaysTotaled = convertHourstoDays(nHoursTotaled);
return nDaysTotaled;
end
function convertDaystoMinutes(nNumber)
local nDaysinHours = convertDaystoHours(nNumber);
local nMinutesTotaled = convertHourstoMinutes(nDaysinHours);
return nMinutesTotaled;
end
function convertMonthtoHours(nNumber)
local nYear = DB.getValue("calendar.current.year", 0);
local nMonth = DB.getValue("calendar.current.month");
nDays = getDaysInMonth(nNumber);
nHoursTotaled = convertDaystoHours(nDays);
Debug.console("convertMonthtoHours called; nMonth, nYear, nDays, nHoursTotaled = ", nMonth, nCount, nDays, nHoursTotaled);
return nHoursTotaled;
end
function convertMonthtoMinutes(nNumber)
local nYear = DB.getValue("calendar.current.year", 0);
local nMonth = DB.getValue("calendar.current.month");
nDays = getDaysInMonth(nMonth);
nMinutesTotaled = convertDaystoMinutes(nDays);
Debug.console("convertMonthtoMinutes called; nMonth, nYear, nDays, nMinutesTotaled = ", nMonth, nYear, nDays, nMinutesTotaled);
return nMinutesTotaled;
end
function convertYeartoHours(nNumber)
local nYearinDays = 365;
bisLeapYear = isLeapYear(nNumber);
if bisLeapYear == true then
nYearinDays = nYearinDays + 1;
end
nYearinHours = nYearinDays * 24;
return nYearinHours;
end
function convertYeartoMinutes(nNumber)
local nYearinHours = convertYeartoHours(nNumber);
nYearinMinutes = nYearinHours * 60;
return nYearinMinutes;
end
function convertYearsnowtoMinutes(nYear)
local nYearCount = 0;
local nYearinDays = 365;
local nLeapYear = 0;
local nDaysTotaled = 0
for i=1,nYear do
if nYearCount < nYear then
nYearinHours = convertYeartoHours(i);
nMinutesTotaled = nMinutesTotaled + convertHourstoMinutes(nYearinHours);
nYearCount = nYearCount + 1;
end
end
return nMinutesTotaled;
end
function convertMonthssnowtoMinutes(nMonth)
local nCount = 0;
local nMinutes = 0;
for i=1,nMonth do
if nCount < nMonth then
nMinutes = convertMonthtoMinutes(nCount) + nMinutes;
nCount = nCount + 1;
end
Debug.console("convertMonthsnowtoMinutes called; nCount, nMonth, nMinutes =", nCount, nMonth, nMinutes);
end
return nMinutes;
end
--extra calculations --
function getDaysInMonth(nMonth)
local nYear = DB.getValue("calendar.current.year", 0);
local nDays = DB.getValue("calendar.data.periods.period" .. nMonth .. ".days", 0);
if nMonth == 2 then
local nYear = DB.getValue("calendar.current.year", 0);
if (nYear % 400) == 0 then
nVar = 1;
elseif (nYear % 100) == 0 then
nVar = 0;
elseif (nYear % 4) == 0 then
nVar = 1;
end
else
nVar = 0;
end
nDays = nDays + nVar;
return nDays;
end
function isLeapYear(nYear)
return nYear%4==0 and (nYear%100~=0 or nYear%400==0)
end
thanks for any advice and suggestions guys! you've helped me get this far, and i feel like i've vastly improved since i began!
--Timer Functions--
function setStartTime(rActor, sFirst)
local sActorType, nodeActor = ActorManager.getTypeAndNode(rActor);
nStartTime = getCurrentDateinMinutes(rActor);
DB.setValue(nodeActor, "" .. sFirst .. ".starttime", "number", nStartTime);
Debug.console("setStartTime called; nStartTime = ", nStartTime);
end
function getStartTime(rActor, sFirst)
local sActorType, nodeActor = ActorManager.getTypeAndNode(rActor);
local nRound = DB.getValue(nodeActor, "game.round", 0);
nStartTime = getCurrentDateinMinutes(nRound)
FetchStartTime = DB.getValue(nodeActor, "" .. sFirst .. ".starttime", 0);
return FetchStartTime;
end
function getCurrentDateinMinutes()
local nMinutes = DB.getValue("calendar.current.minute");
local nHours = DB.getValue("calendar.current.hour");
local nDays = DB.getValue("calendar.current.day");
local nMonths = DB.getValue("calendar.current.month");
local nYears = DB.getValue("calendar.current.year");
Debug.console("getCurrentDateinMinutes called; nMinutes, nHours, nDays, nMonths, nYears =", nMinutes, nHours, nDays, nMonths, nYears);
nHoursinMinutes = convertHourstoMinutes(nHours);
nDaysinMinutes = convertDaystoMinutes(nDays);
nMonthsinMinutes = convertMonthssnowtoMinutes(nMonths);
nYearsinMinutes = convertYearsnowtoMinutes(nYears);
Debug.console("getCurrentDateinMinutes called; nHoursinMinutes, nDaysinMinutes, nMonthsinMinutes, nYearsinMinutes =", nHoursinMinutes, nDaysinMinutes, nMonthsinMinutes, nYearsinMinutes);
nDateinMinutes = nHoursinMinutes + nDaysinMinutes + nMonthsinMinutes + nYearsinMinutes + nMinutes;
Debug.console("getCurrentDateinMinutes called; nDateinMinutes =", nDateinMinutes);
return nDateinMinutes;
end
--Compare times --
function isTimeGreaterThan(rActor, sFirst, nCompareBy)
local sActorType, nodeActor = ActorManager.getTypeAndNode(rActor);
local nRound = DB.getValue(nodeActor, "game.round", 0);
local nStartTime = getStartTime(rActor, sFirst);
local nCurrentTime = getCurrentDateinMinutes();
local nDifference = nCurrentTime - nStartTime;
Debug.console("isTimeGreaterThan called; nDifference, nCurrentTime, nStartTime = ", nDifference, nCurrentTime, nStartTime);
if nDifference > nCompareBy then
return true;
elseif nDifference <= nCompareBy then
return false;
end
end
function getTimeDifference(rActor, sFirst, nCompareBy)
local sActorType, nodeActor = ActorManager.getTypeAndNode(rActor);
local nRound = DB.getValue(nodeActor, "game.round", 0);
local nStartTime = DB.getValue(nodeActor, "" .. sFirst .. ".starttime", 0);
local nCurrentTime = getCurrentDateinMinutes();
nDifference = nCurrentTime - nStartTime;
Debug.console("isTimeGreaterThan called; nDifference, nCurrentTime, nStartTime = ", nDifference, nCurrentTime, nStartTime);
return nDifference;
end
--convert time functions --
function convertHourstoMinutes(nNumber)
local nMinutesTotaled = nNumber * 60;
return nMinutesTotaled;
end
function convertMinutestoHours(nNumber)
local nHoursTotaled = nNumber / 60;
return nHoursTotaled;
end
function convertHourstoDays(nNumber)
local nDaysTotaled = nNumber / 24);
return nDaysTotaled;
end
function convertDaystoHours(nNumber)
local nHoursTotaled = nNumber * 24;
return nHoursTotaled;
end
function convertMinutestoDays(nNumber)
local nHoursTotaled = convertMinutestoHours(nNumber);
local nDaysTotaled = convertHourstoDays(nHoursTotaled);
return nDaysTotaled;
end
function convertDaystoMinutes(nNumber)
local nDaysinHours = convertDaystoHours(nNumber);
local nMinutesTotaled = convertHourstoMinutes(nDaysinHours);
return nMinutesTotaled;
end
function convertMonthtoHours(nNumber)
local nYear = DB.getValue("calendar.current.year", 0);
local nMonth = DB.getValue("calendar.current.month");
nDays = getDaysInMonth(nNumber);
nHoursTotaled = convertDaystoHours(nDays);
Debug.console("convertMonthtoHours called; nMonth, nYear, nDays, nHoursTotaled = ", nMonth, nCount, nDays, nHoursTotaled);
return nHoursTotaled;
end
function convertMonthtoMinutes(nNumber)
local nYear = DB.getValue("calendar.current.year", 0);
local nMonth = DB.getValue("calendar.current.month");
nDays = getDaysInMonth(nMonth);
nMinutesTotaled = convertDaystoMinutes(nDays);
Debug.console("convertMonthtoMinutes called; nMonth, nYear, nDays, nMinutesTotaled = ", nMonth, nYear, nDays, nMinutesTotaled);
return nMinutesTotaled;
end
function convertYeartoHours(nNumber)
local nYearinDays = 365;
bisLeapYear = isLeapYear(nNumber);
if bisLeapYear == true then
nYearinDays = nYearinDays + 1;
end
nYearinHours = nYearinDays * 24;
return nYearinHours;
end
function convertYeartoMinutes(nNumber)
local nYearinHours = convertYeartoHours(nNumber);
nYearinMinutes = nYearinHours * 60;
return nYearinMinutes;
end
function convertYearsnowtoMinutes(nYear)
local nYearCount = 0;
local nYearinDays = 365;
local nLeapYear = 0;
local nDaysTotaled = 0
for i=1,nYear do
if nYearCount < nYear then
nYearinHours = convertYeartoHours(i);
nMinutesTotaled = nMinutesTotaled + convertHourstoMinutes(nYearinHours);
nYearCount = nYearCount + 1;
end
end
return nMinutesTotaled;
end
function convertMonthssnowtoMinutes(nMonth)
local nCount = 0;
local nMinutes = 0;
for i=1,nMonth do
if nCount < nMonth then
nMinutes = convertMonthtoMinutes(nCount) + nMinutes;
nCount = nCount + 1;
end
Debug.console("convertMonthsnowtoMinutes called; nCount, nMonth, nMinutes =", nCount, nMonth, nMinutes);
end
return nMinutes;
end
--extra calculations --
function getDaysInMonth(nMonth)
local nYear = DB.getValue("calendar.current.year", 0);
local nDays = DB.getValue("calendar.data.periods.period" .. nMonth .. ".days", 0);
if nMonth == 2 then
local nYear = DB.getValue("calendar.current.year", 0);
if (nYear % 400) == 0 then
nVar = 1;
elseif (nYear % 100) == 0 then
nVar = 0;
elseif (nYear % 4) == 0 then
nVar = 1;
end
else
nVar = 0;
end
nDays = nDays + nVar;
return nDays;
end
function isLeapYear(nYear)
return nYear%4==0 and (nYear%100~=0 or nYear%400==0)
end
thanks for any advice and suggestions guys! you've helped me get this far, and i feel like i've vastly improved since i began!