Sunday 4 November 2012

A small script to change the calendar date when traveling

GlobalVariable Property GameYear  Auto
GlobalVariable Property GameDay  Auto  
GlobalVariable Property GameHour  Auto  
GlobalVariable Property GameMonth  Auto  
;amount of travel time, with fixed component and random element added, 
;change as you see fit;this will break for really big values, you should add checks 
;if you're traveling longer than a month
int traveldays = 14 + Utility.RandomInt(-3, 3)

int currentday = gameday.GetValue() as int
int currentmonth = gamemonth.GetValue() as int
int currentyear = gameyear.GetValue() as int

;define array with number of days in each month
int[] montharray = new int[12]
montharray[0] = 31
montharray[1] = 28
montharray[2] = 31
montharray[3] = 30
montharray[4] = 31
montharray[5] = 30
montharray[6] = 31
montharray[7] = 31
montharray[8] = 30
montharray[9] = 31
montharray[10] = 30
montharray[11] = 31

;how many days in current month
int currentmonthdays = montharray[currentmonth]

; add travel days to current date
int dayaftertravel = (currentday + traveldays)

;check if we've passed over into the next monthif dayaftertravel > currentmonthdays
dayaftertravel = (dayaftertravel - currentmonthdays)
currentmonth = (currentmonth + 1)
;check if we've passed over into the next year
        if currentmonth > 11
        currentmonth = 0
        gameyear.setvalue(currentyear+1)
        endif
endif

; set the month
gamemonth.setvalue(currentmonth)

; and set the new date
gameday.setvalue(dayaftertravel)

; set the game hour to a random number because why not
gamehour.setvalue(Utility.RandomInt(0, 23))
Debug.Notification("You have been at sea for " + traveldays + " days")

No comments:

Post a Comment