Parent Directory | Revision Log
Revision 17 - (view) (download)
1 : | ian | 1 | /* Time specific functions |
2 : | * | ||
3 : | * by the AMX Mod X Development Team | ||
4 : | * | ||
5 : | * This file is provided as is (no warranties). | ||
6 : | */ | ||
7 : | |||
8 : | #if defined _time_included | ||
9 : | #endinput | ||
10 : | #endif | ||
11 : | #define _time_included | ||
12 : | |||
13 : | /* Time unit types for get_time_length() */ | ||
14 : | enum | ||
15 : | { | ||
16 : | timeunit_seconds = 0, | ||
17 : | timeunit_minutes, | ||
18 : | timeunit_hours, | ||
19 : | timeunit_days, | ||
20 : | timeunit_weeks, | ||
21 : | ian | 17 | }; |
22 : | ian | 1 | |
23 : | // seconds are in each time unit | ||
24 : | #define SECONDS_IN_MINUTE 60 | ||
25 : | #define SECONDS_IN_HOUR 3600 | ||
26 : | #define SECONDS_IN_DAY 86400 | ||
27 : | #define SECONDS_IN_WEEK 604800 | ||
28 : | |||
29 : | /* Stock by Brad */ | ||
30 : | stock get_time_length(id, unitCnt, type, output[], outputLen) | ||
31 : | { | ||
32 : | // IMPORTANT: You must add register_dictionary("time.txt") in plugin_init() | ||
33 : | |||
34 : | // id: The player whose language the length should be translated to (or 0 for server language). | ||
35 : | // unitCnt: The number of time units you want translated into verbose text. | ||
36 : | // type: The type of unit (i.e. seconds, minutes, hours, days, weeks) that you are passing in. | ||
37 : | // output: The variable you want the verbose text to be placed in. | ||
38 : | // outputLen: The length of the output variable. | ||
39 : | |||
40 : | if (unitCnt > 0) | ||
41 : | { | ||
42 : | // determine the number of each time unit there are | ||
43 : | new weekCnt = 0, dayCnt = 0, hourCnt = 0, minuteCnt = 0, secondCnt = 0; | ||
44 : | |||
45 : | switch (type) | ||
46 : | { | ||
47 : | case timeunit_seconds: secondCnt = unitCnt; | ||
48 : | case timeunit_minutes: secondCnt = unitCnt * SECONDS_IN_MINUTE; | ||
49 : | case timeunit_hours: secondCnt = unitCnt * SECONDS_IN_HOUR; | ||
50 : | case timeunit_days: secondCnt = unitCnt * SECONDS_IN_DAY; | ||
51 : | case timeunit_weeks: secondCnt = unitCnt * SECONDS_IN_WEEK; | ||
52 : | } | ||
53 : | |||
54 : | weekCnt = secondCnt / SECONDS_IN_WEEK; | ||
55 : | secondCnt -= (weekCnt * SECONDS_IN_WEEK); | ||
56 : | |||
57 : | dayCnt = secondCnt / SECONDS_IN_DAY; | ||
58 : | secondCnt -= (dayCnt * SECONDS_IN_DAY); | ||
59 : | |||
60 : | hourCnt = secondCnt / SECONDS_IN_HOUR; | ||
61 : | secondCnt -= (hourCnt * SECONDS_IN_HOUR); | ||
62 : | |||
63 : | minuteCnt = secondCnt / SECONDS_IN_MINUTE; | ||
64 : | secondCnt -= (minuteCnt * SECONDS_IN_MINUTE); | ||
65 : | |||
66 : | // translate the unit counts into verbose text | ||
67 : | new maxElementIdx = -1; | ||
68 : | new timeElement[5][33]; | ||
69 : | |||
70 : | if (weekCnt > 0) | ||
71 : | format(timeElement[++maxElementIdx], 32, "%i %L", weekCnt, id, (weekCnt == 1) ? "TIME_ELEMENT_WEEK" : "TIME_ELEMENT_WEEKS"); | ||
72 : | if (dayCnt > 0) | ||
73 : | format(timeElement[++maxElementIdx], 32, "%i %L", dayCnt, id, (dayCnt == 1) ? "TIME_ELEMENT_DAY" : "TIME_ELEMENT_DAYS"); | ||
74 : | if (hourCnt > 0) | ||
75 : | format(timeElement[++maxElementIdx], 32, "%i %L", hourCnt, id, (hourCnt == 1) ? "TIME_ELEMENT_HOUR" : "TIME_ELEMENT_HOURS"); | ||
76 : | if (minuteCnt > 0) | ||
77 : | format(timeElement[++maxElementIdx], 32, "%i %L", minuteCnt, id, (minuteCnt == 1) ? "TIME_ELEMENT_MINUTE" : "TIME_ELEMENT_MINUTES"); | ||
78 : | if (secondCnt > 0) | ||
79 : | format(timeElement[++maxElementIdx], 32, "%i %L", secondCnt, id, (secondCnt == 1) ? "TIME_ELEMENT_SECOND" : "TIME_ELEMENT_SECONDS"); | ||
80 : | |||
81 : | switch(maxElementIdx) | ||
82 : | { | ||
83 : | case 0: format(output, outputLen, "%s", timeElement[0]); | ||
84 : | case 1: format(output, outputLen, "%s %L %s", timeElement[0], id, "TIME_ELEMENT_AND", timeElement[1]); | ||
85 : | case 2: format(output, outputLen, "%s, %s %L %s", timeElement[0], timeElement[1], id, "TIME_ELEMENT_AND", timeElement[2]); | ||
86 : | case 3: format(output, outputLen, "%s, %s, %s %L %s", timeElement[0], timeElement[1], timeElement[2], id, "TIME_ELEMENT_AND", timeElement[3]); | ||
87 : | case 4: format(output, outputLen, "%s, %s, %s, %s %L %s", timeElement[0], timeElement[1], timeElement[2], timeElement[3], id, "TIME_ELEMENT_AND", timeElement[4]); | ||
88 : | } | ||
89 : | } | ||
90 : | } |
Contact | ViewVC Help |
Powered by ViewVC 1.0.4 |