Skip to content

Commit 3faa147

Browse files
Merge pull request #3224 from MishimaHaruna/localtime
Localtime/daylight savings enhancements and fixes
2 parents 82265ef + 87be781 commit 3faa147

34 files changed

+335
-246
lines changed

db/constants.conf

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3877,16 +3877,6 @@ constants_db: {
38773877
MOUNT_DRAGON_BLUE: 7
38783878
MOUNT_DRAGON_RED: 8
38793879

3880-
comment__: "Gettime Types"
3881-
GETTIME_SECOND: 1
3882-
GETTIME_MINUTE: 2
3883-
GETTIME_HOUR: 3
3884-
GETTIME_WEEKDAY: 4
3885-
GETTIME_DAYOFMONTH: 5
3886-
GETTIME_MONTH: 6
3887-
GETTIME_YEAR: 7
3888-
GETTIME_DAYOFYEAR: 8
3889-
38903880
comment__: "gettimer"
38913881
TIMER_COUNT: 0
38923882
TIMER_TICK_NEXT: 1

doc/constants_pre-re.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3816,17 +3816,6 @@
38163816
- `MOUNT_DRAGON_BLUE`: 7
38173817
- `MOUNT_DRAGON_RED`: 8
38183818

3819-
### Gettime Types
3820-
3821-
- `GETTIME_SECOND`: 1
3822-
- `GETTIME_MINUTE`: 2
3823-
- `GETTIME_HOUR`: 3
3824-
- `GETTIME_WEEKDAY`: 4
3825-
- `GETTIME_DAYOFMONTH`: 5
3826-
- `GETTIME_MONTH`: 6
3827-
- `GETTIME_YEAR`: 7
3828-
- `GETTIME_DAYOFYEAR`: 8
3829-
38303819
### gettimer
38313820

38323821
- `TIMER_COUNT`: 0
@@ -5358,6 +5347,23 @@
53585347
- `QINFO_QUEST`: 7
53595348
- `QINFO_MERCENARY_CLASS`: 8
53605349

5350+
### Gettime Types
5351+
5352+
- `GETTIME_SECOND`: 1
5353+
- `GETTIME_MINUTE`: 2
5354+
- `GETTIME_HOUR`: 3
5355+
- `GETTIME_WEEKDAY`: 4
5356+
- `GETTIME_DAYOFMONTH`: 5
5357+
- `GETTIME_MONTH`: 6
5358+
- `GETTIME_YEAR`: 7
5359+
- `GETTIME_DAYOFYEAR`: 8
5360+
5361+
### Gettimetick Types
5362+
5363+
- `GETTIMETICK_SYSTEM_MS`: 0
5364+
- `GETTIMETICK_HOUROFDAY_S`: 1
5365+
- `GETTIMETICK_UNIXTIME`: 2
5366+
53615367
### function types
53625368

53635369
- `FUNCTION_IS_COMMAND`: 1

doc/constants_re.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3816,17 +3816,6 @@
38163816
- `MOUNT_DRAGON_BLUE`: 7
38173817
- `MOUNT_DRAGON_RED`: 8
38183818

3819-
### Gettime Types
3820-
3821-
- `GETTIME_SECOND`: 1
3822-
- `GETTIME_MINUTE`: 2
3823-
- `GETTIME_HOUR`: 3
3824-
- `GETTIME_WEEKDAY`: 4
3825-
- `GETTIME_DAYOFMONTH`: 5
3826-
- `GETTIME_MONTH`: 6
3827-
- `GETTIME_YEAR`: 7
3828-
- `GETTIME_DAYOFYEAR`: 8
3829-
38303819
### gettimer
38313820

38323821
- `TIMER_COUNT`: 0
@@ -5358,6 +5347,23 @@
53585347
- `QINFO_QUEST`: 7
53595348
- `QINFO_MERCENARY_CLASS`: 8
53605349

5350+
### Gettime Types
5351+
5352+
- `GETTIME_SECOND`: 1
5353+
- `GETTIME_MINUTE`: 2
5354+
- `GETTIME_HOUR`: 3
5355+
- `GETTIME_WEEKDAY`: 4
5356+
- `GETTIME_DAYOFMONTH`: 5
5357+
- `GETTIME_MONTH`: 6
5358+
- `GETTIME_YEAR`: 7
5359+
- `GETTIME_DAYOFYEAR`: 8
5360+
5361+
### Gettimetick Types
5362+
5363+
- `GETTIMETICK_SYSTEM_MS`: 0
5364+
- `GETTIMETICK_HOUROFDAY_S`: 1
5365+
- `GETTIMETICK_UNIXTIME`: 2
5366+
53615367
### function types
53625368

53635369
- `FUNCTION_IS_COMMAND`: 1

doc/sample/npc_test_time.txt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
//============================================================
1010

1111
prontera,157,181,6 script Time Sample 8W_SOLDIER,{
12-
mes "[Time Sample]";
13-
mes " System Tick : " + gettimetick(0);
14-
mes " Time Tick : " + gettimetick(1);
15-
mes " GETTIME_SECOND : " + gettime(GETTIME_SECOND) + " (Sec)";
16-
mes " GETTIME_MINUTE : " + gettime(GETTIME_MINUTE) + " (Min)";
17-
mes " GETTIME_HOUR : " + gettime(GETTIME_HOUR) + " (Hour)";
18-
mes " GETTIME_WEEKDAY : " + gettime(GETTIME_WEEKDAY) + " (WeekDay)";
19-
mes "GETTIME_DAYOFMONTH : " + gettime(GETTIME_DAYOFMONTH) + " (MonthDay)";
20-
mes " GETTIME_MONTH : " + gettime(GETTIME_MONTH) + " (Month)";
21-
mes " GETTIME_YEAR : " + gettime(GETTIME_YEAR) + " (Year)";
22-
mes " GETTIME_DAYOFYEAR : " + gettime(GETTIME_DAYOFYEAR) + " (Day of Year)";
23-
mes " gettimestr : " + gettimestr("%Y-%m/%d %H:%M:%S",19);
24-
close;
12+
mes("[Time Sample]");
13+
mesf(" System Tick : %d", gettimetick(GETTIMETICK_SYSTEM_MS));
14+
mesf(" Time Tick : %d", gettimetick(GETTIMETICK_HOUROFDAY_S));
15+
mesf(" GETTIME_SECOND : %d (Sec)", gettime(GETTIME_SECOND));
16+
mesf(" GETTIME_MINUTE : %d (Min)", gettime(GETTIME_MINUTE));
17+
mesf(" GETTIME_HOUR : %d (Hour)", gettime(GETTIME_HOUR));
18+
mesf(" GETTIME_WEEKDAY : %d (WeekDay)", gettime(GETTIME_WEEKDAY));
19+
mesf("GETTIME_DAYOFMONTH : %d (MonthDay)", gettime(GETTIME_DAYOFMONTH));
20+
mesf(" GETTIME_MONTH : %d (Month)", gettime(GETTIME_MONTH));
21+
mesf(" GETTIME_YEAR : %d (Year)", gettime(GETTIME_YEAR));
22+
mesf(" GETTIME_DAYOFYEAR : %d (Day of Year)", gettime(GETTIME_DAYOFYEAR));
23+
mesf(" gettimestr : %s", gettimestr("%Y-%m/%d %H:%M:%S",19));
24+
close();
2525
}

doc/script_commands.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3781,13 +3781,15 @@ If the player is not found, returns -1.
37813781
*gettimetick(<type>)
37823782

37833783
Valid types are :
3784-
0 - server's tick (milliseconds), unsigned int, loops every ~25 days
3785-
1 - time since the start of the current day in seconds
3786-
2 - UNIX epoch time (number of seconds elapsed since 1st of January 1970)
3784+
0 - GETTIMETICK_SYSTEM_MS - server's tick (milliseconds), unsigned int, loops every ~25 days
3785+
1 - GETTIMETICK_HOUROFDAY_S - time since the start of the current day in seconds
3786+
- Note: this only considers the value of the current hour and disregards daylight savings.
3787+
- On the day DST starts and ends, this value will have discontinuties.
3788+
2 - GETTIMETICK_UNIXTIME - UNIX epoch time (number of seconds elapsed since 1st of January 1970)
37873789

37883790
---------------------------------------
37893791

3790-
*gettime(<type>)
3792+
*gettime(<type>{, <is_localtime>})
37913793

37923794
This function returns specified information about the current system time.
37933795

@@ -3803,6 +3805,9 @@ Valid types:
38033805
7 - GETTIME_YEAR - Year
38043806
8 - GETTIME_DAYOFYEAR - Day of the year.
38053807

3808+
If <is_localtime> is true (or omitted), the output refers to the current timezone and daylight savings.
3809+
Otherwise it is in UTC.
3810+
38063811
It will only return numbers based on types.
38073812
Example :
38083813
if (gettime(GETTIME_WEEKDAY) == SATURDAY) {
@@ -3815,7 +3820,7 @@ Example :
38153820

38163821
---------------------------------------
38173822

3818-
*getcalendartime(<hour>, <minute>{, <day of month>{, <day of week>}})
3823+
*getcalendartime(<hour>, <minute>{, <day of month>{, <day of week>{, <input_is_localtime>}}})
38193824

38203825
This function returns the timestamp of the next occurrence of a given time.
38213826
If this time is later today, it will stay in the same day, otherwise, it will adjust to a future
@@ -3834,10 +3839,14 @@ Day of Week specifies a day in the week and its valid values are:
38343839
In order to use Day of Week, you must use Day of Month as -1.
38353840
If for some reason the command fails, it'll return -1.
38363841

3842+
If <input_is_localtime> is true (or omitted), then the hour and minute are interpreted according to the current timezone
3843+
and daylight savings. Otherwise they're treated as UTC.
3844+
38373845
Examples :
38383846
getcalendartime(19, 00); // Next 7 pm
38393847
getcalendartime(19, 00, 6); // Next day 6 of the month, at 7pm
38403848
getcalendartime(19, 10, -1, 1); // Next Monday, at 7:10pm
3849+
getcalendartime(19, 00, -1, -1, false); // Next 7 pm UTC
38413850

38423851
Note: If supplied with the current hour and minute, you will get the timestamp for the same
38433852
hour and minute in the next day. For example, if is now August 1st 7:00pm and you use:

npc/battleground/kvm/kvm01.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ OnCroixJoin:
153153
end;
154154

155155
OnGuillaumeQuit:
156-
//BG_Delay_Tick = gettimetick(2) + 1200;
156+
//BG_Delay_Tick = gettimetick(GETTIMETICK_UNIXTIME) + 1200;
157157
OnGuillaumeDie:
158158
if ($@KvM01BG == 2) {
159159
--.Guillaume_Count;
@@ -167,7 +167,7 @@ OnGuillaumeDie:
167167
end;
168168

169169
OnCroixQuit:
170-
//BG_Delay_Tick = gettimetick(2) + 1200;
170+
//BG_Delay_Tick = gettimetick(GETTIMETICK_UNIXTIME) + 1200;
171171
OnCroixDie:
172172
if ($@KvM01BG == 2) {
173173
--.Croix_Count;

npc/battleground/kvm/kvm02.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ OnCroixJoin:
154154
end;
155155

156156
OnGuillaumeQuit:
157-
//BG_Delay_Tick = gettimetick(2) + 1200;
157+
//BG_Delay_Tick = gettimetick(GETTIMETICK_UNIXTIME) + 1200;
158158
OnGuillaumeDie:
159159
if ($@KvM02BG == 2) {
160160
--.Guillaume_Count;
@@ -168,7 +168,7 @@ OnGuillaumeDie:
168168
end;
169169

170170
OnCroixQuit:
171-
//BG_Delay_Tick = gettimetick(2) + 1200;
171+
//BG_Delay_Tick = gettimetick(GETTIMETICK_UNIXTIME) + 1200;
172172
OnCroixDie:
173173
if ($@KvM02BG == 2) {
174174
--.Croix_Count;

npc/battleground/kvm/kvm03.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ OnCroixJoin:
154154
end;
155155

156156
OnGuillaumeQuit:
157-
//BG_Delay_Tick = gettimetick(2) + 1200;
157+
//BG_Delay_Tick = gettimetick(GETTIMETICK_UNIXTIME) + 1200;
158158
OnGuillaumeDie:
159159
if ($@KvM03BG == 2) {
160160
--.Guillaume_Count;
@@ -168,7 +168,7 @@ OnGuillaumeDie:
168168
end;
169169

170170
OnCroixQuit:
171-
//BG_Delay_Tick = gettimetick(2) + 1200;
171+
//BG_Delay_Tick = gettimetick(GETTIMETICK_UNIXTIME) + 1200;
172172
OnCroixDie:
173173
if ($@KvM03BG == 2) {
174174
--.Croix_Count;

npc/cities/niflheim.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ niflheim,350,258,1 script Cursed Spirit#nif 4_NFWISP,{
207207
next;
208208
switch(select("Touch the first book.", "Touch the second book.", "Touch the third book.", "Okay, I am leaving.")) {
209209
case 1:
210-
if (.last_mob_summon + 60 < gettimetick(2)) { // only spawn every 60 seconds, to prevent farming exploits
210+
if (.last_mob_summon + 60 < gettimetick(GETTIMETICK_UNIXTIME)) { // only spawn every 60 seconds, to prevent farming exploits
211211
.@label$ = sprintf("%s::OnMyMobDead", strnpcinfo(NPC_NAME_UNIQUE));
212212
killmonster("niflheim", .@label$);
213-
.last_mob_summon = gettimetick(2);
213+
.last_mob_summon = gettimetick(GETTIMETICK_UNIXTIME);
214214
monster("niflheim", 349, 259, "--ja--", G_RIDEWORD, 1, .@label$);
215215
}
216216
mes "[Ashe Bruce]";
@@ -343,10 +343,10 @@ niflheim,350,258,1 script Cursed Spirit#nif 4_NFWISP,{
343343
close;
344344
}
345345
}
346-
if (.last_mob_summon + 60 < gettimetick(2)) { // only spawn every 60 seconds, to prevent farming exploits
346+
if (.last_mob_summon + 60 < gettimetick(GETTIMETICK_UNIXTIME)) { // only spawn every 60 seconds, to prevent farming exploits
347347
.@label$ = sprintf("%s::OnMyMobDead", strnpcinfo(NPC_NAME_UNIQUE));
348348
killmonster("niflheim", .@label$);
349-
.last_mob_summon = gettimetick(2);
349+
.last_mob_summon = gettimetick(GETTIMETICK_UNIXTIME);
350350
monster("niflheim", 345, 259, "--ja--", G_ORC_SKELETON, 1, .@label$);
351351
monster("niflheim", 347, 261, "--ja--", G_ORC_SKELETON, 1, .@label$);
352352
monster("niflheim", 344, 253, "--ja--", G_ORC_SKELETON, 1, .@label$);

0 commit comments

Comments
 (0)