[Half-Life AMXX] / include / amxmisc.inc Repository:
ViewVC logotype

Annotation of /include/amxmisc.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : ian 1 /* AMX Mod X misc.
2 :     *
3 :     * by the AMX Mod X Development Team
4 :     * originally developed by OLO
5 :     *
6 :     * This file is provided as is (no warranties).
7 :     */
8 :    
9 :     #if defined _amxmisc_included
10 :     #endinput
11 :     #endif
12 :     #define _amxmisc_included
13 :    
14 :     #if !defined _amxmodx_included
15 :     #if defined AMXMOD_BCOMPAT
16 :     #include <amxmod>
17 :     #else
18 :     #include <amxmodx>
19 :     #endif
20 :     #endif
21 :    
22 :     #if defined AMXMOD_BCOMPAT
23 :     #if defined _translator_included
24 :     #define SIMPLE_T(%1) _T(%1)
25 :     #else
26 :     #define SIMPLE_T(%1) %1
27 :     #endif
28 :     #endif
29 :    
30 :     stock is_user_admin(id)
31 :     {
32 :     return ( get_user_flags(id)>0 && !(get_user_flags(id)&ADMIN_USER) );
33 :     }
34 :    
35 :     stock cmd_access(id,level,cid,num)
36 :     {
37 :     new has_access = 0;
38 :     if ( id==(is_dedicated_server()?0:1) )
39 :     {
40 :     has_access = 1;
41 :     }
42 :     else if ( level==ADMIN_ADMIN )
43 :     {
44 :     if ( is_user_admin(id) )
45 :     {
46 :     has_access = 1;
47 :     }
48 :     }
49 :     else if ( get_user_flags(id) & level )
50 :     {
51 :     has_access = 1;
52 :     }
53 :     else if (level == ADMIN_ALL)
54 :     {
55 :     has_access = 1;
56 :     }
57 :    
58 :     if ( has_access==0 )
59 :     {
60 :     #if defined AMXMOD_BCOMPAT
61 :     console_print(id, SIMPLE_T("You have no access to that command."));
62 :     #else
63 :     console_print(id,"%L",id,"NO_ACC_COM");
64 :     #endif
65 :     return 0;
66 :     }
67 :     if (read_argc() < num)
68 :     {
69 :     new hcmd[32], hinfo[128], hflag;
70 :     get_concmd(cid,hcmd,31,hflag,hinfo,127,level);
71 :     #if defined AMXMOD_BCOMPAT
72 :     console_print(id, SIMPLE_T("Usage: %s %s"), hcmd, SIMPLE_T(hinfo));
73 :     #else
74 :     console_print(id,"%L: %s %s",id,"USAGE",hcmd,hinfo);
75 :     #endif
76 :     return 0;
77 :     }
78 :    
79 :     return 1;
80 :     }
81 :    
82 :     stock access(id,level)
83 :     {
84 :     if ( level==ADMIN_ADMIN )
85 :     {
86 :     return is_user_admin(id);
87 :     }
88 :    
89 :     return (get_user_flags(id) & level);
90 :     }
91 :    
92 :     /* Flags:
93 :     * 1 - obey immunity
94 :     * 2 - allow yourself
95 :     * 4 - must be alive
96 :     * 8 - can't be bot */
97 :     stock cmd_target(id,const arg[],flags = 1)
98 :     {
99 :     new player = find_player("bl",arg);
100 :     if (player)
101 :     {
102 :     if ( player != find_player("blj",arg) )
103 :     {
104 :     #if defined AMXMOD_BCOMPAT
105 :     console_print(id, SIMPLE_T("There are more clients matching to your argument"));
106 :     #else
107 :     console_print(id,"%L",id,"MORE_CL_MATCHT");
108 :     #endif
109 :     return 0;
110 :     }
111 :     }
112 :     else if ( ( player = find_player("c",arg) )==0 && arg[0]=='#' && arg[1] )
113 :     {
114 :     player = find_player("k",str_to_num(arg[1]));
115 :     }
116 :     if (!player)
117 :     {
118 :     #if defined AMXMOD_BCOMPAT
119 :     console_print(id, SIMPLE_T("Client with that name or userid not found"));
120 :     #else
121 :     console_print(id,"%L",id,"CL_NOT_FOUND");
122 :     #endif
123 :     return 0;
124 :     }
125 :     if (flags & 1)
126 :     {
127 :     if ((get_user_flags(player)&ADMIN_IMMUNITY) && ((flags&2)?(id!=player):true) )
128 :     {
129 :     new imname[32];
130 :     get_user_name(player,imname,31);
131 :     #if defined AMXMOD_BCOMPAT
132 :     console_print(id, SIMPLE_T("Client ^"%s^" has immunity"), imname);
133 :     #else
134 :     console_print(id,"%L",id,"CLIENT_IMM",imname);
135 :     #endif
136 :     return 0;
137 :     }
138 :     }
139 :     if (flags & 4)
140 :     {
141 :     if (!is_user_alive(player))
142 :     {
143 :     new imname[32];
144 :     get_user_name(player,imname,31);
145 :     #if defined AMXMOD_BCOMPAT
146 :     console_print(id, SIMPLE_T("That action can't be performed on dead client ^"%s^""), imname);
147 :     #else
148 :     console_print(id,"%L",id,"CANT_PERF_DEAD",imname);
149 :     #endif
150 :     return 0;
151 :     }
152 :     }
153 :     if (flags & 8)
154 :     {
155 :     if (is_user_bot(player))
156 :     {
157 :     new imname[32];
158 :     get_user_name(player,imname,31);
159 :     #if defined AMXMOD_BCOMPAT
160 :     console_print(id, SIMPLE_T("That action can't be performed on bot ^"%s^""), imname);
161 :     #else
162 :     console_print(id,"%L",id,"CANT_PERF_BOT",imname);
163 :     #endif
164 :     return 0;
165 :     }
166 :     }
167 :     return player;
168 :     }
169 :    
170 :     stock show_activity( id, const name[], {Float,_}: ... )
171 :     {
172 :     new buffer[128];
173 :     format_args( buffer , 127 , 2 );
174 :     switch(get_cvar_num("amx_show_activity"))
175 :     {
176 :     case 2:
177 :     #if defined AMXMOD_BCOMPAT
178 :     client_print(0, print_chat, "%s %s: %s", is_user_admin(id) ? SIMPLE_T("ADMIN") : SIMPLE_T("PLAYER"), name, buffer);
179 :     #else
180 :     client_print(0, print_chat, "%L %s: %s", id, is_user_admin(id) ? "ADMIN" : "PLAYER" , name , buffer );
181 :     #endif
182 :     case 1:
183 :     #if defined AMXMOD_BCOMPAT
184 :     client_print(0, print_chat, "%s: %s", is_user_admin(id) ? SIMPLE_T("ADMIN") : SIMPLE_T("PLAYER"), buffer);
185 :     #else
186 :     client_print(0, print_chat, "%L: %s", id, is_user_admin(id) ? "ADMIN" : "PLAYER", buffer );
187 :     #endif
188 :     }
189 :     }
190 :    
191 :     stock colored_menus()
192 :     {
193 :     new mod_name[32];
194 :     get_modname(mod_name,31);
195 :    
196 :     return ( equal(mod_name,"cstrike") || equal(mod_name,"czero") || equal(mod_name,"dod") );
197 :     }
198 :    
199 :     stock cstrike_running()
200 :     {
201 :     new mod_name[32];
202 :     get_modname(mod_name,31);
203 :    
204 :     return ( equal(mod_name,"cstrike") || equal(mod_name,"czero") || equal(mod_name,"csv15") || equal(mod_name,"cs13") );
205 :     }
206 :    
207 :     stock is_running(const mod[])
208 :     {
209 :     new mod_name[32];
210 :     get_modname(mod_name,31);
211 :    
212 :     return equal(mod_name,mod);
213 :     }
214 :    
215 :     stock get_basedir(name[],len)
216 :     {
217 :     return get_localinfo("amxx_basedir",name,len);
218 :     }
219 :    
220 :     stock get_configsdir(name[],len)
221 :     {
222 :     return get_localinfo("amxx_configsdir",name,len);
223 :     }
224 :    
225 :     stock get_datadir(name[],len)
226 :     {
227 :     return get_localinfo("amxx_datadir",name,len);
228 :     }
229 :    
230 :     stock register_menu(const title[],keys,const function[],outside=0)
231 :     {
232 :     register_menucmd(register_menuid(title,outside),keys,function);
233 :     }
234 :    
235 :     /* Backwards Compatibility
236 :     * don't use it! */
237 :     stock get_customdir(name[],len)
238 :     {
239 :     return get_localinfo("amxx_configsdir",name,len);
240 :     }
241 :    
242 :     /* Add a menu item to Menus Front-End plugin ("amxmodmenu"):
243 :     * MENU_TEXT: Text that will be shown for this item in menu
244 :     * MENU_CMD: Command that should be executed to start menu
245 :     * MENU_ACCESS: Access required for menu
246 :     * MENU_PLUGIN: The exact case-insensitive name of plugin holding the menu command
247 :     */
248 :     stock AddMenuItem(const MENU_TEXT[], const MENU_CMD[], const MENU_ACCESS, const MENU_PLUGIN[])
249 :     {
250 :     AddMenuItem_call(MENU_TEXT, MENU_CMD, MENU_ACCESS, MENU_PLUGIN, false);
251 :     }
252 :     /* Just like above, but add menu item to "amx_menu", that should also be accessible by non-admins.
253 :     */
254 :     stock AddClientMenuItem(const MENU_TEXT[], const MENU_CMD[], const MENU_ACCESS, const MENU_PLUGIN[])
255 :     {
256 :     AddMenuItem_call(MENU_TEXT, MENU_CMD, MENU_ACCESS, MENU_PLUGIN, true);
257 :     }
258 :    
259 :     // Internal function used by above stocks.
260 :     stock AddMenuItem_call(const MENU_TEXT[], const MENU_CMD[], const MENU_ACCESS, const MENU_PLUGIN[], const bool:ADD_TO_CLIENT_MENU)
261 :     {
262 :     new pluginid = is_plugin_loaded("Menus Front-End");
263 :     if (pluginid == -1) {
264 :     log_amx("Can't add menu item ^"%s^" from plugin ^"%s^" to menu set because the Menus Front-End plugin itself is not loaded!", MENU_TEXT, MENU_PLUGIN);
265 :     return; // Menus Front-End doesn't exist, return.
266 :     }
267 :    
268 :     new filename[64], b[1];
269 :     get_plugin(pluginid, filename, 63, b, 0, b, 0, b, 0, b, 0);
270 :    
271 :     new status = callfunc_begin(ADD_TO_CLIENT_MENU ? "AddClientMenu" : "AddMenu", filename);
272 :     new bool:failed = true;
273 :     switch (status)
274 :     {
275 :     case 1: failed = false;
276 :     case 0: log_amx("Run time error! (AddMenuItem_call failed)");
277 :     case -2: log_amx("Function not found! (AddMenuItem_call failed)");
278 :     case -1: log_amx("Plugin not found! (AddMenuItem_call failed)");
279 :     }
280 :     if (failed)
281 :     {
282 :     return;
283 :     }
284 :     // Item text
285 :     callfunc_push_str(MENU_TEXT);
286 :     // Cmd
287 :     callfunc_push_str(MENU_CMD);
288 :     // Access
289 :     callfunc_push_int(MENU_ACCESS);
290 :     // Menu exists in this plugin
291 :     callfunc_push_str(MENU_PLUGIN);
292 :    
293 :     callfunc_end();
294 :     }
295 :    
296 :    
297 :     stock constraint_offset(low, high, seed, offset)
298 :     {
299 :     new numElements = high - low + 1;
300 :     offset += seed - low;
301 :    
302 :     if (offset >= 0)
303 :     {
304 :     return low + (offset % numElements);
305 :     }
306 :     else
307 :     {
308 :     return high - (abs(offset) % numElements) + 1;
309 :     }
310 :    
311 :     return 0; // Makes the compiler happy -_-
312 :     }

Contact
ViewVC Help
Powered by ViewVC 1.0.4