Difference between revisions of "User:Rasikko"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Rasikko
imported>Rasikko
Line 249: Line 249:
* When time permits, add another example concerning the Events OnActivate, OnTriggerEnter and OnTriggerLeave.
* When time permits, add another example concerning the Events OnActivate, OnTriggerEnter and OnTriggerLeave.
* Test out function for acquiring the xp for the next level and add it to the condition function page of the same name as an alternative to it.
* Test out function for acquiring the xp for the next level and add it to the condition function page of the same name as an alternative to it.
* Fix syntax/logic issue concerning the Cast to string section in [[Cast Reference]], because it's completely wrong.

Revision as of 13:52, 31 March 2018

Array Funtions

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
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

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 function has GetCurrentGameTime live up to its name. Will return the in-game time, instead of days passed. At least 1 day has to have passed.

Float Function GetCurrentGameTimeExtended() Global
    ; Returns the time displayed in the game.
    ; Format is hh.mmssss
	
    Float currentGameTime = Utility.GetCurrentGameTime()
    Float fractionOfDay = currentGameTime - currentGameTime as int
    Float hour = (fractionOfDay * 24) as int
    Float minutes = ((fractionOfDay * 24) - hour) * 60
    Float seconds = (minutes - minutes as int) * 60
	
    if currentGameTime >= 1.0
	; before adding the hours, we need to turn the minutes into a decimal.
	minutes = (minutes as int) / 100.0
	
	; do the same to the seconds 
	seconds = seconds / 10000.0

	return hour + minutes + seconds
    endif
	
    return -1.0
	
EndFunction


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


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

Game.GetRealHoursPassed() * 60


To get the number of seconds that have passed since game start. Note at least 1 day has to have passed:

Float Function GetGameSecondsPassed()
    ; returns the number of game seconds since game start.
    Float gameTime = Utility.GetCurrentGameTime()
	
    if gameTime >= 1.0
	return gameTime / 24.0 * 60 * 60
    endif
	
    return -1.0
EndFunction


For milliseconds:

Float Function GetGameMillisecondsPassed()
    ; Returns milliseconds passed since game start.

    Float gameTime = Utility.GetCurrentGameTime()

    if gameTime >= 1.0
	return gameTime / 24.0 * 60.0 * 60.0 * 1000.0
    endif

    return -1.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.

Calendar Functions

Various functions for dealing with the months, weeks, or days. Months in Skyrim are index based. Meaning Morning Star is Month 0, and Evening Star is Month 11. Days of the week are also index based, where Sundas is 0, and Loredas is 6. One day passes on Morndas, 18th, Last Seed,4E201. The game starts at 8:00AM, Sundas, 17th Last Seed 4E 201, which is exactly 16 hours til the next day.
Skyrim's calendar resets(first day of the year starts on middas again) every 6 years.
The following function is the same as using GameMonth.GetValue(), but without using a property or GetValue - GlobalVariable. The idea behind all the following functions is to serve as an alternative to properties.

Int Function GetCurrentGameMonth() Global
	Int daysPassed = Utility.GetCurrentGameTime() as int
	
	; the number of days left in the year when the game starts
	Int daysRemainingGameStart =  136
	
	; the number of days that have passed(which are not counted)
	; when the game starts.
	Int daysPassedGameStart = 228
	
	Float monthlyAverage = 30.416667

	if (daysPassed < daysRemainingGameStart)
		return ((daysPassedGameStart + daysPassed) / monthlyAverage) as int
	else
		return ((daysPassed - daysRemainingGameStart) / monthlyAverage) as int
	endif
EndFunction


Getting the current week of the year.

Int Function GetCurrentGameWeek()
    Int totalDays = Utility.GetCurrentGameTime() as int
    Int daysRemainingGameStart = 136
    Int daysPassedGameStart = 228

    if (totalDays < daysRemainingGameStart)
	    return (totalDays + daysPassedGameStart) / 7
    else
	    return (totalDays - daysRemainingGameStart) / 7
    endif
EndFunction


This one should be self explanatory.

Int Function GetGameMonthTotalDays(int aiGameMonth = 0) Global
	; returns the number of days for this month.
	Int[] months = new Int[12]
	months[0] = 31
	months[1] = 28
	months[2] = 31
	months[3] = 30
	months[4] = 31
	months[5] = 30
	months[6] = 31
	months[7] = 31
	months[8] = 30
	months[9] = 31
	months[10]= 30
	months[11]= 31
	
	return months[aiGameMonth]
EndFunction

Lunar Functions

Returns the time Masser rises. If the current time is beyond this, will return how many hours til the next moonrise. If more than 1 day has not passed, will return the time Masser will rise instead.

Float Function GetMasserRiseTime() Global
    Float gameTime = Utility.GetCurrentGameTime()
    Float riseTime = 20.00 ; 8PM
    Float hoursPerDay = 24.00	
    Float currentHour = (gameTime - gameTime as int) * hoursPerDay
	
    if (gameTime >= 1.0)
	 if currentHour > riseTime
       
	    riseTime = currentHour - (riseTime - 12.00)
		
	    return riseTime
	 else
	    return riseTime
	 endif
    endif
    
    return riseTime
EndFuntion


Same above, but for Masser's setting time.

Float Function GetMasserSetTime() Global
    ; Returns the time that Masser sets. If the current time is passed the moonset time,
    ; will return the number of hours til the next moonset.
	
    Float daysPassed = Utility.GetCurrentGameTime()
    Float hoursPerDay = 24.00
    Float setTime = 4.00 ; 4AM
    Float currentHour = (daysPassed - daysPassed as int) * hoursPerDay
	
    if daysPassed >= 1.0
	if currentHour > setTime
	  
	   setTime = currentHour - setTime
			
	   return setTime
	else
	   return setTime
        endif
    endif
	
    return setTime
	
EndFunction

Self Reminders

  • When time permits, add another example concerning the Events OnActivate, OnTriggerEnter and OnTriggerLeave.
  • Test out function for acquiring the xp for the next level and add it to the condition function page of the same name as an alternative to it.
  • Fix syntax/logic issue concerning the Cast to string section in Cast Reference, because it's completely wrong.