[Half-Life AMXX] / timeleft.sma Repository:
ViewVC logotype

Annotation of /timeleft.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : ian 1 /* AMX Mod X
2 :     * TimeLeft Plugin
3 :     *
4 :     * by the AMX Mod X Development Team
5 :     * originally developed by OLO
6 :     *
7 :     * This file is part of AMX Mod X.
8 :     *
9 :     *
10 :     * This program is free software; you can redistribute it and/or modify it
11 :     * under the terms of the GNU General Public License as published by the
12 :     * Free Software Foundation; either version 2 of the License, or (at
13 :     * your option) any later version.
14 :     *
15 :     * This program is distributed in the hope that it will be useful, but
16 :     * WITHOUT ANY WARRANTY; without even the implied warranty of
17 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 :     * General Public License for more details.
19 :     *
20 :     * You should have received a copy of the GNU General Public License
21 :     * along with this program; if not, write to the Free Software Foundation,
22 :     * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 :     *
24 :     * In addition, as a special exception, the author gives permission to
25 :     * link the code of this program with the Half-Life Game Engine ("HL
26 :     * Engine") and Modified Game Libraries ("MODs") developed by Valve,
27 :     * L.L.C ("Valve"). You must obey the GNU General Public License in all
28 :     * respects for all of the code used other than the HL Engine and MODs
29 :     * from Valve. If you modify this file, you may extend this exception
30 :     * to your version of the file, but you are not obligated to do so. If
31 :     * you do not wish to do so, delete this exception statement from your
32 :     * version.
33 :     */
34 :    
35 :     #include <amxmodx>
36 :    
37 :     new g_TimeSet[32][2]
38 :     new g_LastTime
39 :     new g_CountDown
40 :     new g_Switch
41 :    
42 :     public plugin_init()
43 :     {
44 :     register_plugin("TimeLeft", AMXX_VERSION_STR, "AMXX Dev Team")
45 :     register_dictionary("timeleft.txt")
46 :     register_cvar("amx_time_voice", "1")
47 :     register_srvcmd("amx_time_display", "setDisplaying")
48 :     register_cvar("amx_timeleft", "00:00", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_UNLOGGED|FCVAR_SPONLY)
49 :     register_clcmd("say timeleft", "sayTimeLeft", 0, "- displays timeleft")
50 :     register_clcmd("say thetime", "sayTheTime", 0, "- displays current time")
51 :    
52 :     set_task(0.8, "timeRemain", 8648458, "", 0, "b")
53 :     }
54 :    
55 :     public sayTheTime(id)
56 :     {
57 :     if (get_cvar_num("amx_time_voice"))
58 :     {
59 :     new mhours[6], mmins[6], whours[32], wmins[32], wpm[6]
60 :    
61 :     get_time("%H", mhours, 5)
62 :     get_time("%M", mmins, 5)
63 :    
64 :     new mins = str_to_num(mmins)
65 :     new hrs = str_to_num(mhours)
66 :    
67 :     if (mins)
68 :     num_to_word(mins, wmins, 31)
69 :     else
70 :     wmins[0] = 0
71 :    
72 :     if (hrs < 12)
73 :     wpm = "am "
74 :     else
75 :     {
76 :     if (hrs > 12) hrs -= 12
77 :     wpm = "pm "
78 :     }
79 :    
80 :     if (hrs)
81 :     num_to_word(hrs, whours, 31)
82 :     else
83 :     whours = "twelve "
84 :    
85 :     client_cmd(id, "spk ^"fvox/time_is_now %s_period %s%s^"", whours, wmins, wpm)
86 :     }
87 :    
88 :     new ctime[64]
89 :    
90 :     get_time("%m/%d/%Y - %H:%M:%S", ctime, 63)
91 :     client_print(0, print_chat, "%L: %s", LANG_PLAYER, "THE_TIME", ctime)
92 :    
93 :     return PLUGIN_CONTINUE
94 :     }
95 :    
96 :     public sayTimeLeft(id)
97 :     {
98 :     if (get_cvar_float("mp_timelimit"))
99 :     {
100 :     new a = get_timeleft()
101 :    
102 :     if (get_cvar_num("amx_time_voice"))
103 :     {
104 :     new svoice[128]
105 :     setTimeVoice(svoice, 127, 0, a)
106 :     client_cmd(id, "%s", svoice)
107 :     }
108 :     client_print(0, print_chat, "%L: %d:%02d", LANG_PLAYER, "TIME_LEFT", (a / 60), (a % 60))
109 :     }
110 :     else
111 :     client_print(0, print_chat, "%L", LANG_PLAYER, "NO_T_LIMIT")
112 :    
113 :     return PLUGIN_CONTINUE
114 :     }
115 :    
116 :     setTimeText(text[], len, tmlf, id)
117 :     {
118 :     new secs = tmlf % 60
119 :     new mins = tmlf / 60
120 :    
121 :     if (secs == 0)
122 :     format(text, len, "%d %L", mins, id, (mins > 1) ? "MINUTES" : "MINUTE")
123 :     else if (mins == 0)
124 :     format(text, len, "%d %L", secs, id, (secs > 1) ? "SECONDS" : "SECOND")
125 :     else
126 :     format(text, len, "%d %L %d %L", mins, id, (mins > 1) ? "MINUTES" : "MINUTE", secs, id, (secs > 1) ? "SECONDS" : "SECOND")
127 :     }
128 :    
129 :     setTimeVoice(text[], len, flags, tmlf)
130 :     {
131 :     new temp[7][32]
132 :     new secs = tmlf % 60
133 :     new mins = tmlf / 60
134 :    
135 :     for (new a = 0;a < 7;++a)
136 :     temp[a][0] = 0
137 :    
138 :     if (secs > 0)
139 :     {
140 :     num_to_word(secs, temp[4], 31)
141 :    
142 :     if (!(flags & 8))
143 :     temp[5] = "seconds " /* there is no "second" in default hl */
144 :     }
145 :    
146 :     if (mins > 59)
147 :     {
148 :     new hours = mins / 60
149 :    
150 :     num_to_word(hours, temp[0], 31)
151 :    
152 :     if (!(flags & 8))
153 :     temp[1] = "hours "
154 :    
155 :     mins = mins % 60
156 :     }
157 :    
158 :     if (mins > 0)
159 :     {
160 :     num_to_word(mins, temp[2], 31)
161 :    
162 :     if (!(flags & 8))
163 :     temp[3] = "minutes "
164 :     }
165 :    
166 :     if (!(flags & 4))
167 :     temp[6] = "remaining "
168 :    
169 :     return format(text, len, "spk ^"vox/%s%s%s%s%s%s%s^"", temp[0], temp[1], temp[2], temp[3], temp[4], temp[5], temp[6])
170 :     }
171 :    
172 :     findDispFormat(time)
173 :     {
174 :     for (new i = 0; g_TimeSet[i][0]; ++i)
175 :     {
176 :     if (g_TimeSet[i][1] & 16)
177 :     {
178 :     if (g_TimeSet[i][0] > time)
179 :     {
180 :     if (!g_Switch)
181 :     {
182 :     g_CountDown = g_Switch = time
183 :     remove_task(8648458)
184 :     set_task(1.0, "timeRemain", 34543, "", 0, "b")
185 :     }
186 :    
187 :     return i
188 :     }
189 :     }
190 :     else if (g_TimeSet[i][0] == time)
191 :     {
192 :     return i
193 :     }
194 :     }
195 :    
196 :     return -1
197 :     }
198 :    
199 :     public setDisplaying()
200 :     {
201 :     new arg[32], flags[32], num[32]
202 :     new argc = read_argc() - 1
203 :     new i = 0
204 :    
205 :     while (i < argc && i < 32)
206 :     {
207 :     read_argv(i + 1, arg, 31)
208 :     parse(arg, flags, 31, num, 31)
209 :    
210 :     g_TimeSet[i][0] = str_to_num(num)
211 :     g_TimeSet[i][1] = read_flags(flags)
212 :    
213 :     i++
214 :     }
215 :     g_TimeSet[i][0] = 0
216 :    
217 :     return PLUGIN_HANDLED
218 :     }
219 :    
220 :     public timeRemain(param[])
221 :     {
222 :     new gmtm = get_timeleft()
223 :     new tmlf = g_Switch ? --g_CountDown : gmtm
224 :     new stimel[12]
225 :    
226 :     format(stimel, 11, "%02d:%02d", gmtm / 60, gmtm % 60)
227 :     set_cvar_string("amx_timeleft", stimel)
228 :    
229 :     if (g_Switch && gmtm > g_Switch)
230 :     {
231 :     remove_task(34543)
232 :     g_Switch = 0
233 :     set_task(0.8, "timeRemain", 8648458, "", 0, "b")
234 :    
235 :     return
236 :     }
237 :    
238 :     if (tmlf > 0 && g_LastTime != tmlf)
239 :     {
240 :     g_LastTime = tmlf
241 :     new tm_set = findDispFormat(tmlf)
242 :    
243 :     if (tm_set != -1)
244 :     {
245 :     new flags = g_TimeSet[tm_set][1]
246 :     new arg[128]
247 :    
248 :     if (flags & 1)
249 :     {
250 :     new players[32], pnum
251 :    
252 :     get_players(players, pnum, "c")
253 :    
254 :     for (new i = 0; i < pnum; i++)
255 :     {
256 :     setTimeText(arg, 127, tmlf, players[i])
257 :    
258 :     if (flags & 16)
259 :     set_hudmessage(255, 255, 255, -1.0, 0.85, 0, 0.0, 1.1, 0.1, 0.5, -1)
260 :     else
261 :     set_hudmessage(255, 255, 255, -1.0, 0.85, 0, 0.0, 3.0, 0.0, 0.5, -1)
262 :    
263 :     show_hudmessage(players[i], "%s", arg)
264 :     }
265 :     }
266 :    
267 :     if (flags & 2)
268 :     {
269 :     setTimeVoice(arg, 127, flags, tmlf)
270 :     client_cmd(0, "%s", arg)
271 :     }
272 :     }
273 :     }
274 :     }

Contact
ViewVC Help
Powered by ViewVC 1.0.4