Difference between revisions of "User:Rasikko"

4,144 bytes added ,  10:54, 24 March 2021
m
imported>Scrivener07
(Created page with "== Time Functions == These are some helper functions you can use to work with time in the game. I offer three ways of starting them off, as the functions will require any of t...")
 
imported>Scrivener07
 
(12 intermediate revisions by the same user not shown)
Line 9: Line 9:
<br>
<br>
The last method is through GetFormFromFile and pulls the global instead of making it a property.
The last method is through GetFormFromFile and pulls the global instead of making it a property.
<source lang="papyrus">Float daysPassed = (Game.GetFormFromFile(0x00000039, "Fallout4.ESM") as GlobalVariable).GetValue()
<source lang="papyrus">Float daysPassed = (Game.GetFormFromFile(0x00000039, "Fallout4.ESM") as GlobalVariable).GetValue()</source>
<br>
Using any of them, you pass into the arguments where needed for the following function:
<source lang="papyrus">
Float Function GetGameTime(Float afDaysPassed) Global
    ; Returns the number of hours passed for the current day.
   
    Float gameTime = (afDaysPassed - afDaysPassed as int) * 24.0
    if gameTime > 12.00
return gameTime - 12.00
    endif
 
    return gameTime
EndFunction
</source>
<br>
This function requires the return value from GetGameTime() above.
<source lang="papyrus">
Float Function GetCurrentInGameTime(Float afGameTime) Global
    ; Returns the actual in game time. h.mm0000
 
    return afGameTime as int + ((((afGameTime - afGameTime as int) * 60.0) as int) / 100.0)
EndFunction
</source>
<br>
<source lang="papyrus">
String Function GetCurrentDayOfWeek(Float afDaysPassed) Global
    ; Returns the day of week.
    Int dayOfWeek = afDaysPassed as int % 7
    String[] daysOfWeek = new String[7]
    daysOfWeek[0] = "Sunday"
    daysOfWeek[1] = "Monday"
    daysOfWeek[2] = "Tuesday"
    daysOfWeek[3] = "Wednesday"
    daysOfWeek[4] = "Thursday"
    daysOfWeek[5] = "Friday"
    daysOfWeek[6] = "Saturday"
 
    return daysOfWeek[dayOfWeek]
EndFunction
</source>
<br>
Converting functions..(short description)
<source lang="papyrus">
Float Function GameDaysPassedToGameSecondsPassed(Float afDaysPassed)
    ; Converts the GameDaysPassed return value to seconds passed.
    return afDaysPassed * 3600.0
EndFunction
</source>
<br>
Functions for returning units of time since 10.28.2287. 30.416667 is used because Fallout 4 does not have leap years and thus always has common years(365 days).
<source lang="papyrus">
Float Function GetMonthsPassed(Float afDaysPassed) Global
    ; Returns the number of month passed since game start.
    return afDaysPassed / 30.416667
EndFunction
 
Float Function GetWeeksPassed(Float afDaysPassed) Global
    ; Returns the number of weeks passed since game start.
    return afDaysPassed / 7.0
EndFunction
 
Float Function GetTotalHoursPassed(Float afDaysPassed) Global
    ; Returns the total number of hours passed since game start.
    return afDaysPassed * 24.0
EndFunction
 
Float Function GetTotalMinutesPassed(Float afDaysPassed) Global
    ; Returns the total number of minutes passed since game start.
    return afDaysPassed * 24.0 * 60.0
EndFunction
 
Float Function GetTotalSecondsPassed(Float afDaysPassed) Global
    ; Returns the total number of seconds passed since game start.
    return afDaysPassed * 24.0 * 60.0 * 60.0
EndFunction
</source>
--[[User:Rasikko|Rasikko]] ([[User talk:Rasikko|talk]]) 2018-08-31T15:50:59 (EDT)
 
<source lang="papyrus">
Float Function GetHoursPassedForWeek(Float afDaysPassed) Global
    ; Returns the number of hours passed for the current week.
    return ((afDaysPassed / 7.0) - (afDaysPassed / 7.0) as int) * 168.0
EndFunction
</source>
--[[User:Rasikko|Rasikko]] ([[User talk:Rasikko|talk]]) 2018-09-07T16:15:58 (EDT)
 
<source lang="papyrus">
String Function GetAnyDayOfWeek(Int day, Int month, Int year) Global
    ; returns the day of week that any day falls on for any month of any year.
 
    Int[] KeyValues = new Int[12]
    KeyValues[0] = 6
    KeyValues[1] = 2
    KeyValues[2] = 2
    KeyValues[3] = 5
    KeyValues[4] = 0
    KeyValues[5] = 3
    KeyValues[6] = 5
    KeyValues[7] = 4
    KeyValues[8] = 4
    KeyValues[9] = 5
    KeyValues[10] = 2
    KeyValues[11] = 4
   
    Int dayOfWeek = (29 + day + KeyValues[month] + year) % 7
 
    if dayOfWeek == 0
      return "Sunday"
    elseif dayOfWeek == 1
      return "Monday"
    elseif dayOfWeek == 2
      return "Tuesday"
    elseif dayOfWeek == 3
      return "Wednesday"
    elseif dayOfWeek == 4
      return "Thursday"
    elseif dayOfWeek == 5
      return "Friday"
    elseif dayOfWeek == 6
      return "Saturday"
    endif
 
    return ""
EndFunction
</source>
The key values represent the days of the week that the first day of every month starts on for the year 2287. The formulas involved uses those values to find the days of the week for any day. --[[User:Rasikko|Rasikko]] ([[User talk:Rasikko|talk]]) 2018-09-09T00:34:08 (EDT)
Anonymous user