User:Rasikko

Revision as of 14:00, 3 February 2018 by imported>Rasikko (→‎Time Functions)

Remove from Array

Int[] Function RemoveFromArray(Int[] array, int startIndex, int numOfElementsToRemove = 1) Global
	; Removes a number of elements from an array from the starting index.
	; Change the return, parameter, and variable type to suit the array type you are using.
	
	int arrayLength = array.length
	
	if (startIndex == 0 && numOfElementstoRemove == 0)
		array[startIndex] = 0
		return array
	elseif numOfElementsToRemove >= arrayLength
		; To prevent an error. Returns the array unchanged.
		return array
	else
		while (startIndex < numOfElementsToRemove + 1)
			array[startIndex] = 0
			startIndex += 1
		endwhile
	endif
	
	return array
EndFunction

Reverse an Array

Form[] Function ReverseArray(Form[] array) Global
	; Reverses the order from the smallest index to the largest and returns the array.
	; Change the return, parameter, and variable type to suit the array type you are reversing.
 
	Int index = array.length
	Int i = 0
	Form temp
 
	while (i < (index / 2))
		temp = array[i]
		array[i] = array[(index - 1) - i]
		array[(index - 1) - i] = temp
		i += 1
	endwhile
 
	return array
EndFunction

Unit Converions

The Unit page lists the Skyrim Unit to metric/imperial conversions, centimeters to inches is obvious, though it doesn't list the calculations when going to feet, so here it is: FT = Unit * 0.046875 --Rasikko (talk) 2018-01-10T12:18:45 (EST)

Time Functions

NOTE: The calculations for functions dealing with weeks or months, or years appear to be inaccurate. Currently in the process of reviewing calculations and making corrections. Various functions for calculating time in skyrim. Most use GetCurrentGameTime - Utility as it returns the total game days passed. Making it easier for conversions.
This simple function converts days passed into hours passed.

Float Function GetGameHoursPassed()
	; Converts the game days passed to game time hours.
	return Utility.GetCurrentGameTime() * 24
EndFunction


This function takes the game days passed and converts them into minutes passed.

Float Function GetGameMinutesPassed()
    ; Converts the game days passed to game minutes passed.
    return Utility.GetCurrentGameTime() * 24 * 60
EndFunction


This function does a few mathematical steps before arriving to the result:
1. The days passed is turned into a whole number and divided by 7 with the remainder being the day of the week.
2. The days passed is turned into a fraction of a day and then converted into the hours passed since that day started.
3. Result from Step 2 is added to the result of Step 1.

Float Function GetGameHoursPassedForWeek()
    ; returns the total hours passed for the current week.
	
    ; Get the current time(it's actually how many game days have passed).
    Float CurrentGameTime = Utility.GetCurrentGameTime()
	
    ; Get hours passed since sundas.
    return (((CurrentGameTime as Int) % 7) + ((CurrentGameTime - CurrentGameTime as int) * 24)) as Float
EndFunction


To get the total real minutes passed since the game started, you do the following:

Game.GetRealHoursPassed() * 60


To get the total game minutes passed since the game started, you do the following:

(Game.GetRealHoursPassed() * 60) / (Game.GetFormFromFile(0x0000003A, "Skyrim.ESM") as GlobalVariable).GetValue() ; Timescale global


To get the total game hours passed since a game month has started:

Float Function GetGameHoursPassedForMonth()
    ; Returns the number of hours passed for the current month.
    Float CurrentGameTime = Utility.GetCurrentGameTime()
    return (((Game.GetFormFromFile(0x0000037, "Skyrim.ESM") as GlobalVariable).GetValue() * 24) + ((CurrentGameTime - CurrentGameTime as int) * 24)) as Float
EndFunction

Note: The function may be faster to use the GameDay global as a property and simply call GetValue on it than using GetFormFromFile - Game and reduce number of casting. I used GetFormFromFile simply because it keeps my code(s) as small as possible on this page.
To get the current hour and the minutes for that day(the fraction of minutes is converted to actual minutes).

Float Function GetGameTimeOfDay()
    ; returns the game time for the current day.
    Float CurrentGameTime = Utility.GetCurrentGameTime() 
    Float GameTimeOfDay = (CurrentGameTime - CurrentGameTime as int) * 24
 
    return GameTimeOfDay as int + (((GameTimeOfDay - GameTimeOfDay as int) * 60) / 100)
EndFunction

Having a little more fun with time. This function returns how many days have passed for the current year. This works by first checking if the year is greater than 4E 201. Then subtracts the current number of days passed from the number of total days passed for 4E 201, which is 134. Taking in account for starting year:

Int Function GetDaysPassedForYear()
    ; returns the number of days passed for the current year.
    Int CurrentGameTime = Utility.GetCurrentGameTime() as int
	
    if (Game.GetFormFromFile(0x00000035, "Skyrim.ESM") as GlobalVariable).GetValue() as int > 201
        return (CurrentGameTime - 134) / 30 * 30 as int
    else
        return CurrentGameTime
    endif
EndFunction

Can use this to return the number of seconds passed. If your character has played for 264 game days, this will return 2,376,000.

Float Function GetGameSecondsPassed()
    ; returns the total number of seconds passed (in game time).
   
    return Utility.GetCurrentGameTime() / 24.0 * 60.0 * 3600.0
EndFunction

This function will return how many real minutes have passed from the total game minutes. Calculations are done using seconds as they are easier.

Float Function GetRealMinutesPassed()
 ; returns the number of real minutes that have passed.
 
 ; using variables to show how conversions are done.
 Float DaysToHours = 24.0
 Float HoursToMinutes = 60.0
 Float MinutesToSeconds = 60.0
  
 Float CurrentGameTime = Utility.GetCurrentGameTime() * DaysToHours * HoursToMinutes * MinutesToSeconds \
     / (Game.GetFormFromFile(0x0000003A, "Skyrim.ESM") as GlobalVariable).GetValue()

  ; converting seconds to minutes for return value.
  return CurrentGameTime / 60.0
  
EndFunction

Short note about game time: Game time is paused when in a menu. While this is a well known fact, it can be easily forgotten when working with it along side real time, as real time obviously keeps running.

Skyrim has no leap years, and thus has common years, where the first day and last day of the year are on the same day of the week.