/[svn]/hlds/cstrike/addons/amxmodx/scripting/molotov_cocktail.sma
ViewVC logotype

Contents of /hlds/cstrike/addons/amxmodx/scripting/molotov_cocktail.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 26 - (show annotations) (download)
Sun Nov 23 19:48:46 2008 UTC (15 years, 4 months ago) by cstrike
File size: 32940 byte(s)
Removed csx/fun includes, typos, minor code optimizations
1 /*******************************************************************************
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version 2
6 * of the License, or version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 *
17 * In addition, as a special exception, the author gives permission to
18 * link the code of this program with the Half-Life Game Engine ("HL
19 * Engine") and Modified Game Libraries ("MODs") developed by Valve,
20 * L.L.C ("Valve"). You must obey the GNU General Public License in all
21 * respects for all of the code used other than the HL Engine and MODs
22 * from Valve. If you modify this file, you must extend this exception
23 * to your version of the file.
24 *
25 ********************************************************************************
26
27
28 Molotov Cocktail
29 Version 3.20
30 Maintained by: DynamicBits (Andy)
31
32 * Commands:
33 - say molotov - Buy a molotov
34 - say /molotov - Buy a molotov
35 - molotov_give <player|@all|@t|@ct|@al|@ax> - Gives molotovs to a player, a team, or everyone
36 - molotov_cocktail [0|1] - Enable/disable the plugin (If no arguments, show the status)
37 - molotov_override [0|1] - Enable/disable the HE grenade override (If no arguments, show the status)
38
39 * Cvars
40 - molotov_enabled - Enable/disable the plugin [1 = enabled; 0 = disabled] [default = 1]
41 - molotov_price - Set the molotov price [default = 1200]
42 - molotov_damage - Set the damage done by initial molotov explosion [default = 50.0]
43 - molotov_radius - Set the radius of molotov damage [default = 150.0]
44 - molotov_firetime - Duration (in seconds) of fire effects, sounds, etc. [default = 6]
45 - molotov_firedamage - Amount of damage done by fire effects (every 0.2 secs). [default = 3]
46 - molotov_ff - Disable(0)/enable(1) the ability to damage/kill someone on your team with molotov. [default = 1] (Was molotov_tk)
47 - molotov_override_he - Override the original hegrenade automatically with molotov. [default = 0] (Was molotov_tempoverride)
48 - molotov_max - Max num of molotovs able to carry. [default = 1] (Does not work with override)
49 - molotov_inmenu - Puts molotov in the end of the equipment buymenu (old menu, not VGUI). [default = 0]
50 (If the override cvar is enabled the hegrenade will be replaced instead.)
51 - molotov_buyzone - Do you have to be in buyzone? [default = 1] (If molotov_inmenu=1, this is ignored)
52 - molotov_menu - Enables menu at beginning of each round [default = 0] (Was amx_molotovmenu)
53
54 * Required Modules:
55 - Fakemeta
56 - Fakemeta Utilities
57 - Cstrike
58
59 * Changelog/Credit:
60 - DynamicBits
61 * (SVN)
62 - Removed unnecessary csx include
63 - Converted fun functions to fakemeta_util functions (removed fun include)
64 - Minor optimizations
65 - Fixed a few typos
66 * Version 3.20 (2008-11-20)
67 - My first public release
68 - Finally tracked down and fixed the intermittent crashing problem (I hope!)
69 - Modified default damage values
70 - molotov_cocktail/molotov_override commands now change settings *or* display status
71 - Broken molotov model stays closer to the explosion (looks more realistic)
72 - Task IDs are now guaranteed to be unique
73 - Modified anti-lag calculations to be more accurate (less likely to lag)
74 - Changed amx_molotovmenu CVAR to molotov_menu
75 - Changed molotov_tk CVAR to molotov_ff
76 - Changed molotov_tempoverride CVAR to molotov_override_he
77 - Preparation for support of mods other than Counter-Strike
78 - Fixed lots of coding mistakes
79 - Optimized several sections of code
80 - Corrected grammar/typos
81 - Clean up code (Removed unused code/unhelpful comments, fixed formatting, and semicolons!)
82 - Raffe (CantShoot)
83 * (Unversioned release)
84 - Originally fixed plugin to run on Linux servers
85 - Added optional menu to purchase molotov cocktails each round
86 - Moved models and sounds into proper molotov/ subdirectories
87 - Fixed molotovs not being reset upon player disconnect
88 - (Almost) fixed molotovs not being removed for new round
89 - Added @all/@ct/@t arguments to cmd_MolotovGive
90 - Changed some models/sound
91 - [ --<-@ ] Black Rose
92 * Version 3.0-3.1c ?
93 - Unknown changes
94 - SAMURAI
95 * Original plugin author
96
97
98 */
99
100 #pragma semicolon 1
101 #include <amxmodx>
102 #include <amxmisc>
103 #include <fakemeta>
104 #include <fakemeta_util>
105 #include <cstrike>
106
107 // Uncomment the following line to enable debug logging.
108 //#define MOLOTOV_DEBUG
109
110 #define AUTHORS "DynamicBits"
111
112 #define ADMIN_ACCESS ADMIN_KICK
113
114 #define ANTI_LAGG 7.0 // Defines max calculations before a flame is spawned without check if onground
115 // This is to prevent lagg at really narrow ents where you could end up with 400 calculations per flame
116 // Suggested: <= 10
117
118 #define MOLOTOV_HARD_LIMIT 10 // Maximum molotov cocktails this code is capable of handling without bugs
119 // Also how many cocktails people get with molotov_give command
120
121 #define MOLOTOV_MENU_KEYS MENU_KEY_0|MENU_KEY_1|MENU_KEY_2 // Choices to look for with optional menu
122
123 #define MOLOTOV_TASKID_BASE 1000 // What is the lowest task ID?
124 #define MOLOTOV_TASKID_OFFSET MOLOTOV_HARD_LIMIT
125 #define MOLOTOV_TASKID_BASE1 MOLOTOV_TASKID_BASE // By default, with 32 players, task ids
126 #define MOLOTOV_TASKID_BASE2 MOLOTOV_TASKID_BASE1 + (MOLOTOV_TASKID_OFFSET * 32) // from 1000 to 1959 can
127 #define MOLOTOV_TASKID_BASE3 MOLOTOV_TASKID_BASE2 + (MOLOTOV_TASKID_OFFSET * 32) // potentially be used used.
128
129 #define TEAM_UNASSIGNED 0
130 #define TEAM_ONE 1
131 #define TEAM_TWO 2
132 #define TEAM_SPECTATOR 3
133
134 new pEnabled, pPrice, pMlDamage, pMlRadius, pFireTime, pOverride;
135 new pFriendlyFire, pFireDmg, pMaxMolotovs, pBuyMenu, pBuyZone, pMolotovMenu;
136
137 new gmsgScoreInfo, gmsgDeathMsg;
138
139 new g_pAllocModel, g_vAllocModel;
140
141 new g_frags[33];
142 new g_hasMolotov[33];
143 new g_restarted;
144 new g_MaxPlayers;
145 new g_bomb_map;
146
147 new firespr, smokespr[2];
148
149 new last_Molotov_ent;
150 new g_Molotov_offset[33];
151
152 new g_g;
153
154 public plugin_init() {
155
156 register_plugin("Molotov Cocktail", "3.20SVN", AUTHORS);
157
158 register_menucmd(register_menuid("Buy Molotov Cocktail"), MOLOTOV_MENU_KEYS, "giveMolotov");
159 #if defined MOLOTOV_DEBUG
160 register_clcmd("molotov_menutest", "show_molotov_menu");
161 #endif
162
163 register_clcmd("say /molotov", "buy_molotov");
164 register_clcmd("say molotov", "buy_molotov");
165
166 register_concmd("molotov_give", "cmd_MolotovGive", ADMIN_ACCESS, "<player|@all|@t|@ct|@al|@ax> - Gives free molotov cocktails (default=10)");
167 register_concmd("molotov_override", "cmd_Override", ADMIN_ACCESS, "[0|1] - Enable/disable the HE grenade override (If no arguments, show the status)");
168 register_concmd("molotov_cocktail", "cmd_PluginStatus", ADMIN_ACCESS, "[0|1] - Enable/disable the plugin (If no arguments, show the status)");
169
170 pEnabled = register_cvar("molotov_enabled", "1", FCVAR_SPONLY);
171 pOverride = register_cvar("molotov_override_he", "0", FCVAR_SPONLY);
172 pPrice = register_cvar("molotov_price", "1200", FCVAR_SPONLY);
173 pMlDamage = register_cvar("molotov_damage", "50.0", FCVAR_SPONLY);
174 pMlRadius = register_cvar("molotov_radius", "150.0", FCVAR_SPONLY);
175 pFireTime = register_cvar("molotov_firetime", "6", FCVAR_SPONLY);
176 pFireDmg = register_cvar("molotov_firedamage", "3", FCVAR_SPONLY);
177 pFriendlyFire = register_cvar("molotov_ff", "1", FCVAR_SPONLY);
178 pMaxMolotovs = register_cvar("molotov_max", "1", FCVAR_SPONLY);
179 pBuyMenu = register_cvar("molotov_inmenu", "0", FCVAR_SPONLY);
180 pBuyZone = register_cvar("molotov_buyzone", "1", FCVAR_SPONLY);
181 pMolotovMenu = register_cvar("molotov_menu", "0", FCVAR_SPONLY);
182
183 register_event("CurWeapon", "Event_CurWeapon", "be", "1=1");
184 register_event("HLTV", "event_new_round", "a", "1=0", "2=0");
185 register_event("TextMsg", "Event_GameRestart", "a", "2=#Game_Commencing", "2=#Game_will_restart_in");
186 register_event("DeathMsg", "event_DeathMsg", "a");
187
188 register_event("ShowMenu", "event_BuyMenuT", "b", "4=#T_BuyItem", "1=575");
189 register_event("ShowMenu", "event_BuyMenuCT", "b", "4=#CT_BuyItem", "1=703");
190 register_event("ShowMenu", "event_BuyMenuT", "b", "4=#DT_BuyItem", "1=575");
191 register_event("ShowMenu", "event_BuyMenuCT", "b", "4=#DCT_BuyItem", "1=767");
192
193 register_logevent("logevent_Round_End", 2, "1=Round_End");
194
195 register_menucmd(register_menuid("#CT_BuyItem"), 1023, "handle_BuyMenuCT");
196 register_menucmd(register_menuid("#T_BuyItem"), 1023, "handle_BuyMenuT");
197
198 register_forward(FM_EmitSound, "fw_EmitSound");
199
200 g_MaxPlayers = get_maxplayers();
201
202 gmsgScoreInfo = get_user_msgid("ScoreInfo");
203 gmsgDeathMsg = get_user_msgid("DeathMsg");
204
205 g_pAllocModel = engfunc(EngFunc_AllocString, "models/molotov/p_molotov.mdl");
206 g_vAllocModel = engfunc(EngFunc_AllocString, "models/molotov/v_molotov.mdl");
207
208 g_bomb_map = engfunc(EngFunc_FindEntityByString, g_MaxPlayers, "classname", "info_bomb_target") ? 1 : 0;
209 }
210
211 public plugin_precache() {
212
213 firespr = precache_model("sprites/flame.spr");
214
215 smokespr[0] = precache_model("sprites/black_smoke3.spr");
216 smokespr[1] = precache_model("sprites/steam1.spr");
217
218 precache_sound("molotov/molotov_fire.wav");
219
220 precache_model("models/molotov/p_molotov.mdl");
221 precache_model("models/molotov/v_molotov.mdl");
222 precache_model("models/molotov/w_molotov.mdl");
223 precache_model("models/molotov/w_broke_molotov.mdl");
224
225 }
226
227 public client_disconnect(id) {
228 g_hasMolotov[id] = 0;
229 }
230
231 public fw_EmitSound(ent, channel, sample[]) {
232
233 if (equal(sample[8], "he_bounce", 9)) {
234
235 new model[32];
236 pev(ent, pev_model, model, 31);
237
238 if (equal(model[9], "lotov/w_molotov.mdl")) {
239 if (last_Molotov_ent != ent) {
240 new Float:fFriction, Float:fVelocity[3];
241
242 pev(ent, pev_friction, fFriction);
243 pev(ent, pev_velocity, fVelocity);
244
245 fFriction *= 1.3; // Increase friction to make it look more realistic
246 set_pev(ent, pev_friction, fFriction);
247 #if defined MOLOTOV_DEBUG
248 log_amx("[MC] ent:%d Friction:%f Velocity:%f/%f/%f ====================", ent, fFriction, fVelocity[0], fVelocity[1], fVelocity[2]);
249 #endif
250 last_Molotov_ent = ent;
251 grenade_explode(ent);
252
253 return FMRES_SUPERCEDE;
254 #if defined MOLOTOV_DEBUG
255 } else {
256 log_amx("[MC] last_Molotov_ent(%d) ent(%d)", last_Molotov_ent, ent);
257 #endif
258 }
259 }
260 }
261 return FMRES_IGNORED;
262 }
263
264 public Event_CurWeapon(id) {
265
266 if (!get_pcvar_num(pEnabled) || !is_user_alive(id)) {
267 return PLUGIN_CONTINUE;
268 }
269
270 if (!g_hasMolotov[id] && !get_pcvar_num(pOverride)) {
271 return PLUGIN_CONTINUE;
272 }
273
274 new WeaponID = get_user_weapon(id, WeaponID, WeaponID);
275
276 if (WeaponID != CSW_HEGRENADE) {
277 return PLUGIN_CONTINUE;
278 }
279
280 set_pev(id, pev_viewmodel, g_vAllocModel);
281 set_pev(id, pev_weaponmodel, g_pAllocModel);
282 set_pev(id, pev_weaponanim, 9);
283
284 return PLUGIN_CONTINUE;
285 }
286
287 public Event_GameRestart() {
288 g_restarted = 1;
289 }
290
291 public event_DeathMsg() {
292 g_hasMolotov[read_data(2)] = 0;
293 }
294
295 public logevent_Round_End() {
296 #if defined MOLOTOV_DEBUG
297 log_amx("[MC] ========== Round_End ==========");
298 #endif
299 reset_tasks();
300 }
301
302 stock reset_tasks() {
303 #if defined MOLOTOV_DEBUG
304 new tmpdbgid;
305 #endif
306 for (new i; i < g_MaxPlayers; i++) {
307 for (new o; o < MOLOTOV_TASKID_OFFSET; o++) { //TODO DEBUG: Verify this fixes the tasks not reset at new round issue
308 if (task_exists(MOLOTOV_TASKID_BASE1 + (MOLOTOV_TASKID_OFFSET * i) + o)) {
309 remove_task(MOLOTOV_TASKID_BASE1 + (MOLOTOV_TASKID_OFFSET * i) + o);
310 #if defined MOLOTOV_DEBUG
311 tmpdbgid = MOLOTOV_TASKID_BASE1 + (MOLOTOV_TASKID_OFFSET * i) + o;
312 log_amx("[MC] %d exists. ----------==========----------", tmpdbgid);
313 #endif
314 }
315
316 if (task_exists(MOLOTOV_TASKID_BASE2 + (MOLOTOV_TASKID_OFFSET * i) + o)) {
317 remove_task(MOLOTOV_TASKID_BASE2 + (MOLOTOV_TASKID_OFFSET * i) + o);
318 #if defined MOLOTOV_DEBUG
319 tmpdbgid = MOLOTOV_TASKID_BASE2 + (MOLOTOV_TASKID_OFFSET * i) + o;
320 log_amx("[MC] %d exists. ----------==========----------", tmpdbgid);
321 #endif
322 }
323
324 if (task_exists(MOLOTOV_TASKID_BASE3 + (MOLOTOV_TASKID_OFFSET * i) + o)) {
325 remove_task(MOLOTOV_TASKID_BASE3 + (MOLOTOV_TASKID_OFFSET * i) + o);
326 #if defined MOLOTOV_DEBUG
327 tmpdbgid = MOLOTOV_TASKID_BASE3 + (MOLOTOV_TASKID_OFFSET * i) + o;
328 log_amx("[MC] %d exists. ----------==========----------", tmpdbgid);
329 #endif
330 }
331 }
332 }
333 }
334
335 public event_new_round(id) {
336 #if defined MOLOTOV_DEBUG
337 log_amx("[MC] ========== event_new_round ==========");
338 #endif
339 if (!get_pcvar_num(pEnabled)) {
340 return PLUGIN_CONTINUE;
341 }
342
343 reset_tasks(); // DEBUG
344
345 if (get_pcvar_num(pMolotovMenu)) {
346 show_molotov_menu(id);
347 }
348
349 for (new i; i < g_MaxPlayers; i++) {
350 if (g_frags[i] && is_user_connected(i)) {
351 fm_set_user_frags(i, get_user_frags(i) + g_frags[i]);
352 }
353 g_frags[i] = 0;
354 }
355
356 if (g_restarted) {
357 for (new i; i < g_MaxPlayers; i++) {
358 g_hasMolotov[i] = 0;
359 }
360 g_restarted = 0;
361 }
362
363 if (get_pcvar_num(pOverride)) {
364 set_molotovs();
365 } else {
366 reset_molotovs();
367 }
368
369 return PLUGIN_CONTINUE;
370 }
371
372 public cmd_Override(id, level, cid) {
373
374 if (!cmd_access(id, level, cid, 1)) { // First argument (passed to molotov_override) is optional
375 return PLUGIN_HANDLED;
376 }
377
378 if (!get_pcvar_num(pEnabled)) {
379 return PLUGIN_HANDLED;
380 }
381
382 if (read_argc() == 1) { // No arguments; Display status
383 client_print(id, print_console, "Override is currently %s.", get_pcvar_num(pOverride) ? "enabled" : "disabled");
384 return PLUGIN_HANDLED;
385 }
386
387 new arg[2];
388 read_argv(1, arg, 1);
389
390 new num = str_to_num(arg);
391
392 if ((num < 0) || (num > 1) || (!isdigit(arg[0]))) { // If less than 0 or greater than 1 or not a digit
393 if (id) {
394 client_print(id, print_console, "Invalid argument(%s). Valid arguments are ^"0^" and ^"1^".", arg);
395 } else {
396 server_print("Invalid argument(%s). Valid arguments are ^"0^" and ^"1^".", arg);
397 }
398 return PLUGIN_HANDLED;
399 }
400
401 if (num == get_pcvar_num(pOverride)) {
402 if (id) {
403 client_print(id, print_console, "Override is already %s.", num ? "enabled" : "disabled");
404 } else {
405 server_print("Override is already %s.", num ? "enabled" : "disabled");
406 }
407 return PLUGIN_HANDLED;
408 }
409
410 set_pcvar_num(pOverride, num);
411
412 if (id) {
413 client_print(id, print_console, "Override was %s.", num ? "enabled" : "disabled");
414 } else {
415 server_print("Override was %s.", num ? "enabled" : "disabled");
416 }
417
418 if (num) {
419 set_molotovs();
420 } else {
421 reset_molotovs();
422 }
423
424 return PLUGIN_HANDLED;
425 }
426
427 public cmd_PluginStatus(id, level, cid) {
428 if (!cmd_access(id, level, cid, 1)) { // First argument (passed to molotov_cocktail) is optional
429 return PLUGIN_HANDLED;
430 }
431
432 if (read_argc() == 1) { // No arguments; Display status
433 client_print(id, print_console, "Plugin is currently %s.", get_pcvar_num(pEnabled) ? "enabled" : "disabled");
434 return PLUGIN_HANDLED;
435 }
436
437 new arg[2];
438 read_argv(1, arg, 1);
439
440 new num = str_to_num(arg);
441
442 if ((num < 0) || (num > 1) || (!isdigit(arg[0]))) { // If less than 0 or greater than 1 or not a digit
443 if (id) {
444 client_print(id, print_console, "Invalid argument(%s). Valid arguments are ^"0^" and ^"1^".", arg);
445 } else {
446 server_print("Invalid argument(%s). Valid arguments are ^"0^" and ^"1^".", arg);
447 }
448 return PLUGIN_HANDLED;
449 }
450
451 if (num == get_pcvar_num(pEnabled)) {
452 if (id) {
453 client_print(id, print_console, "Plugin is already %s.", num ? "enabled" : "disabled");
454 } else {
455 server_print("Plugin is already %s.", num ? "enabled" : "disabled");
456 }
457 return PLUGIN_HANDLED;
458 }
459
460 set_pcvar_num(pEnabled, num);
461
462 if (id) {
463 client_print(id, print_console, "Plugin was %s.", num ? "enabled" : "disabled");
464 } else {
465 server_print("Plugin was %s.", num ? "enabled" : "disabled");
466 }
467
468 if (num && get_pcvar_num(pOverride)) {
469 set_molotovs();
470 } else {
471 reset_molotovs();
472 }
473 return PLUGIN_HANDLED;
474 }
475
476 public cmd_MolotovGive(id, level, cid) {
477
478 #if defined MOLOTOV_DEBUG
479 log_amx("[MC] cmd_MolotovGive");
480 #endif
481 if (!cmd_access(id, level, cid, 2)) {
482 return PLUGIN_HANDLED;
483 }
484
485 new Arg1[64], target;
486 read_argv(1, Arg1, 63);
487
488 new adminName[32];
489 get_user_name(id, adminName, 31);
490
491 new targetTeam, targetTeamName[32];
492 new Players[32], iNum;
493 #if defined MOLOTOV_DEBUG
494 log_amx("[MC] cmd_MolotovGive Arg1[0](%s) Arg1[1](%s)", Arg1[0], Arg1[1]);
495 #endif
496 if (Arg1[0] == '@') {
497
498 if (equali(Arg1[1], "all")) {
499 targetTeam = 0;
500 } else if (equali(Arg1[1], "t") || equali(Arg1[1], "al")) { // CS_TEAM_T or ALLIES
501 targetTeam = TEAM_ONE;
502 } else if (equali(Arg1[1], "ct") || equali(Arg1[1], "ax")) { // CS_TEAM_CT or AXIS
503 targetTeam = TEAM_TWO;
504 }
505
506 get_players(Players, iNum, "ac"); // Bots don't understand Molotov cocktails
507
508 for (new i = 0; i < iNum; ++i) {
509 target = Players[i];
510
511 if ((targetTeam == 0) || (get_user_team(target) == targetTeam)) {
512 g_hasMolotov[target] = MOLOTOV_HARD_LIMIT;
513
514 fm_give_item(target, "weapon_hegrenade");
515 cs_set_user_bpammo(target, CSW_HEGRENADE, MOLOTOV_HARD_LIMIT);
516 emit_sound(target, CHAN_WEAPON, "items/gunpickup2.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
517 }
518 }
519
520 switch(targetTeam) {
521 case 0: {
522 targetTeamName = "everyone";
523 }
524 case 1: {
525 if (cstrike_running()) {
526 targetTeamName = "all terrorists";
527 } else if (is_running("dod")) {
528 targetTeamName = "all allies";
529 } else {
530 targetTeamName = "team 1";
531 }
532 }
533 case 2: {
534 if (cstrike_running()) {
535 targetTeamName = "all ct's";
536 } else if (is_running("dod")) {
537 targetTeamName = "all axis";
538 } else {
539 targetTeamName = "team 2";
540 }
541 }
542 }
543 client_print(0, print_chat, "ADMIN %s: has given %s %d Molotov cocktails!", adminName, targetTeamName, MOLOTOV_HARD_LIMIT);
544
545 } else {
546
547 target = cmd_target(id, Arg1, 0);
548
549 if (!is_user_connected(target) || !is_user_alive(target)) {
550 return PLUGIN_HANDLED;
551 }
552
553 new targetName[32];
554 get_user_name(target, targetName, 31);
555
556 g_hasMolotov[target] = MOLOTOV_HARD_LIMIT;
557
558 fm_give_item(target, "weapon_hegrenade");
559 cs_set_user_bpammo(target, CSW_HEGRENADE, MOLOTOV_HARD_LIMIT);
560
561 emit_sound(target, CHAN_WEAPON, "items/gunpickup2.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
562
563 client_print(target, print_chat, "ADMIN %s: has given you %d Molotov cocktails!", adminName, MOLOTOV_HARD_LIMIT);
564
565 }
566 return PLUGIN_HANDLED;
567 }
568
569 public buy_molotov(id) {
570
571 if (!get_pcvar_num(pEnabled)) {
572 return PLUGIN_HANDLED;
573 }
574
575 if (get_pcvar_num(pOverride)) {
576 if (get_pcvar_num(pBuyMenu)) {
577 client_print(id, print_center, "Buy them in the buy equipment menu.");
578 } else {
579 client_print(id, print_center, "Just buy a HE grenade and get molotov automatically!");
580 }
581 return PLUGIN_HANDLED;
582 }
583
584 if (!is_user_alive(id)) {
585 client_print(id, print_center, "You can't buy Molotov cocktails because you are dead.");
586 return PLUGIN_HANDLED;
587 }
588
589 if (!cs_get_user_buyzone(id) && get_pcvar_num(pBuyZone)) {
590 client_print(id, print_center, "You are not in a buyzone.");
591 return PLUGIN_HANDLED;
592 }
593
594 new money = cs_get_user_money(id);
595
596 if (money < get_pcvar_num(pPrice)) {
597 client_print(id, print_center, "You don't have enough $ to buy a Molotov cocktail.");
598 return PLUGIN_HANDLED;
599 }
600
601 if (g_hasMolotov[id] == get_pcvar_num(pMaxMolotovs)) {
602 if (g_hasMolotov[id] == 1) {
603 client_print(id, print_center, "You already have a Molotov cocktail.");
604 } else {
605 client_print(id, print_center, "You already have %d Molotov cocktails.", g_hasMolotov[id]);
606 }
607 return PLUGIN_HANDLED;
608 }
609
610 if (!g_hasMolotov[id] && user_has_weapon(id, CSW_HEGRENADE)) {
611 client_print(id, print_center, "You already have a HE Grenade.");
612 return PLUGIN_HANDLED;
613 }
614
615 cs_set_user_money(id, money - get_pcvar_num(pPrice));
616 fm_give_item(id, "weapon_hegrenade");
617 cs_set_user_bpammo(id, CSW_HEGRENADE, ++g_hasMolotov[id]);
618 client_print(id, print_chat, "You got a Molotov cocktail!");
619
620 return PLUGIN_HANDLED;
621 }
622
623 public event_BuyMenuCT(id) {
624
625 if (!get_pcvar_num(pEnabled) || !get_pcvar_num(pBuyMenu)) {
626 return PLUGIN_CONTINUE;
627 }
628
629 new Override = get_pcvar_num(pOverride);
630
631 new menu[1024];
632 new len = formatex(menu, 1023, "\yBuy Equipment\R$ Cost");
633
634 len += formatex(menu[len], 1023-len, "^n^n\w1. Kevlar Vest\R\y650");
635 len += formatex(menu[len], 1023-len, "^n\w2. Kevlar Vest & Helmet\R\y1000");
636 len += formatex(menu[len], 1023-len, "^n\w3. Flashbang\R\y200");
637
638 if (Override) {
639 len += formatex(menu[len], 1023-len, "^n\w4. Molotov Cocktail\R\y%d", get_pcvar_num(pPrice));
640 } else {
641 len += formatex(menu[len], 1023-len, "^n\w4. HE Grenade\R\y300");
642 }
643
644 len += formatex(menu[len], 1023-len, "^n\w5. Smoke Grenade\R\y300");
645 len += formatex(menu[len], 1023-len, "^n\w6. NightVision Goggles\R\y1250");
646 len += formatex(menu[len], 1023-len, "^n\%c7. Defuse Kit\R\y200 ", g_bomb_map ? 'w' : 'd');
647 len += formatex(menu[len], 1023-len, "^n\w8. Tactical Shield\R\y2200");
648
649 if (!Override) {
650 len += formatex(menu[len], 1023-len, "^n\w9. Molotov Cocktail\R\y%d", get_pcvar_num(pPrice));
651 }
652
653 len += formatex(menu[len], 1023-len, "^n^n\w0. Exit");
654
655 show_menu(id, read_data(1)|MENU_KEY_9, menu, -1, "#CT_BuyItem");
656
657 return PLUGIN_HANDLED;
658 }
659
660 public event_BuyMenuT(id) {
661
662 if (!get_pcvar_num(pEnabled) || !get_pcvar_num(pBuyMenu)) {
663 return PLUGIN_CONTINUE;
664 }
665
666 new Override = get_pcvar_num(pOverride);
667
668 new menu[1024];
669 new len = formatex(menu, 1023, "\yBuy Equipment\R$ Cost");
670 len += formatex(menu[len], 1023-len, "^n^n\w1. Kevlar Vest\R\y650");
671 len += formatex(menu[len], 1023-len, "^n\w2. Kevlar Vest & Helmet\R\y1000");
672 len += formatex(menu[len], 1023-len, "^n\w3. Flashbang\R\y200");
673
674 if (Override) {
675 len += formatex(menu[len], 1023-len, "^n\w4. Molotov Cocktail\R\y%d", get_pcvar_num(pPrice));
676 } else {
677 len += formatex(menu[len], 1023-len, "^n\w4. HE Grenade\R\y300");
678 }
679
680 len += formatex(menu[len], 1023-len, "^n\w5. Smoke Grenade\R\y300");
681 len += formatex(menu[len], 1023-len, "^n\w6. NightVision Goggles\R\y1250");
682
683 if (!Override) {
684 len += formatex(menu[len], 1023-len, "^n\w7. Molotov Cocktail\R\y%d", get_pcvar_num(pPrice));
685 }
686
687 len += formatex(menu[len], 1023-len, "^n^n\w0. Exit");
688
689 show_menu(id, read_data(1)|MENU_KEY_7, menu, -1, "#T_BuyItem");
690
691 return PLUGIN_HANDLED;
692 }
693
694 public handle_BuyMenuCT(id, key) {
695
696 if (key == (get_pcvar_num(pOverride) ? 3 : 8)) {
697 handle_BuyMenu(id);
698 return PLUGIN_HANDLED;
699 }
700
701 return PLUGIN_CONTINUE;
702 }
703
704 public handle_BuyMenuT(id, key) {
705
706 if (key == (get_pcvar_num(pOverride) ? 3 : 6)) {
707 handle_BuyMenu(id);
708 return PLUGIN_HANDLED;
709 }
710
711 return PLUGIN_CONTINUE;
712 }
713
714 stock handle_BuyMenu(id) {
715
716 new money = cs_get_user_money(id);
717
718 if (money < get_pcvar_num(pPrice)) {
719 client_print(id, print_center, "You don't have enough $ to buy a Molotov cocktail.");
720 return PLUGIN_HANDLED;
721 }
722
723 if (g_hasMolotov[id] == get_pcvar_num(pMaxMolotovs)) {
724 if (g_hasMolotov[id] == 1) {
725 client_print(id, print_center, "You already have a Molotov cocktail.");
726 } else {
727 client_print(id, print_center, "You already have %d Molotov cocktails.", g_hasMolotov[id]);
728 }
729 return PLUGIN_HANDLED;
730 } else if (!g_hasMolotov[id] && user_has_weapon(id, CSW_HEGRENADE)) {
731 client_print(id, print_center, "You already have a HE Grenade.");
732 return PLUGIN_HANDLED;
733 }
734
735 cs_set_user_money(id, money - get_pcvar_num(pPrice));
736 fm_give_item(id, "weapon_hegrenade");
737 cs_set_user_bpammo(id, CSW_HEGRENADE, ++g_hasMolotov[id]);
738 client_print(id, print_chat, "You got a Molotov cocktail!");
739
740 return PLUGIN_HANDLED;
741 }
742
743 public grenade_throw(id, ent, wid) {
744
745 if (!get_pcvar_num(pEnabled) || !is_user_connected(id) || wid != CSW_HEGRENADE) {
746 return PLUGIN_CONTINUE;
747 }
748
749 if (!g_hasMolotov[id] && !get_pcvar_num(pOverride)) {
750 return PLUGIN_CONTINUE;
751 }
752
753 g_hasMolotov[id]--;
754 engfunc(EngFunc_SetModel, ent, "models/molotov/w_molotov.mdl");
755 set_pev(ent, pev_nextthink, 99999.0);
756
757 return PLUGIN_CONTINUE;
758 }
759
760 public grenade_explode(ent) {
761
762 new param[6], iOrigin[3];
763 new Float:fOrigin[3];
764 new owner = pev(ent, pev_owner);
765 new ent2 = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"));
766
767 pev(ent, pev_origin, fOrigin);
768
769 #if defined MOLOTOV_DEBUG
770 new iOwnerAlive = is_user_alive(owner);
771 new iOwnerConnected = is_user_connected(owner);
772 new iEnt2Valid = pev_valid(ent2);
773 log_amx("[MC] grenade_explode ent(%d) owner(%d) ent2(%d) iOwnerAlive(%d) iOwnerConnected(%d) iEnt2Valid(%d)", ent, owner, ent2, iOwnerAlive, iOwnerConnected, iEnt2Valid);
774 #endif
775
776 param[0] = ent;
777 param[1] = ent2;
778 param[2] = owner;
779 param[3] = iOrigin[0] = floatround(fOrigin[0]);
780 param[4] = iOrigin[1] = floatround(fOrigin[1]);
781 param[5] = iOrigin[2] = floatround(fOrigin[2]);
782
783 emit_sound(ent, CHAN_AUTO, "molotov/molotov_fire.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
784
785 engfunc(EngFunc_SetModel, ent, "models/molotov/w_broke_molotov.mdl");
786
787 random_fire(iOrigin, ent2);
788 radius_damage(owner, fOrigin, get_pcvar_float(pMlDamage), get_pcvar_float(pMlRadius), DMG_BLAST);
789
790 new Float:FireTime = get_pcvar_float(pFireTime);
791
792 if (++g_Molotov_offset[owner] == MOLOTOV_HARD_LIMIT) {
793 g_Molotov_offset[owner] = 0;
794 }
795
796 set_task(0.2, "fire_damage", MOLOTOV_TASKID_BASE1 + (MOLOTOV_TASKID_OFFSET * (owner - 1)) + g_Molotov_offset[owner], param, 6, "a", floatround(FireTime / 0.2, floatround_floor));
797 set_task(1.0, "fire_sound", MOLOTOV_TASKID_BASE2 + (MOLOTOV_TASKID_OFFSET * (owner - 1)) + g_Molotov_offset[owner], param, 6, "a", floatround(FireTime) - 1);
798 set_task(FireTime, "fire_stop", MOLOTOV_TASKID_BASE3 + (MOLOTOV_TASKID_OFFSET * (owner - 1)) + g_Molotov_offset[owner], param, 6);
799
800 return PLUGIN_CONTINUE;
801 }
802
803 public fire_sound(param[]) {
804 emit_sound(param[1], CHAN_AUTO, "molotov/molotov_fire.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
805 }
806
807 public fire_stop(param[]) {
808 g_g = 0;
809
810 if (pev_valid(param[0])) { engfunc(EngFunc_RemoveEntity, param[0]); }
811 if (pev_valid(param[1])) { engfunc(EngFunc_RemoveEntity, param[1]); }
812
813 if ((last_Molotov_ent = (param[0]))) {
814 last_Molotov_ent = 0;
815 }
816 }
817
818 public fire_damage(param[]) {
819
820 new iOrigin[3], Float:fOrigin[3];
821 iOrigin[0] = param[3];
822 iOrigin[1] = param[4];
823 iOrigin[2] = param[5];
824
825 random_fire(iOrigin, param[1]);
826
827 IVecFVec(iOrigin, fOrigin);
828 radius_damage(param[2], fOrigin, get_pcvar_float(pFireDmg), get_pcvar_float(pMlRadius), DMG_BURN, 0);
829 }
830
831 stock radius_damage(attacker, Float:origin[3], Float:damage, Float:range, dmgtype, calc = 1) {
832
833 new Float:pOrigin[3], Float:dist, Float:tmpdmg;
834 new i, ateam = get_user_team(attacker), iFF = get_pcvar_num(pFriendlyFire);
835
836 while (i++ < g_MaxPlayers) {
837 if (!is_user_alive(i)) {
838 continue;
839 }
840
841 if (!iFF && ateam == get_user_team(i)) {
842 continue;
843 }
844
845 pev(i, pev_origin, pOrigin);
846 dist = get_distance_f(origin, pOrigin);
847
848 if (dist > range) {
849 continue;
850 }
851
852 if (calc) {
853 tmpdmg = damage - (damage / range) * dist;
854 } else {
855 tmpdmg = damage;
856 }
857
858 if (pev(i, pev_health) < tmpdmg) {
859 kill(attacker, i);
860 } else {
861 fm_fakedamage(i, "molotov", tmpdmg, dmgtype);
862 }
863 }
864
865 while ((i = engfunc(EngFunc_FindEntityInSphere, i, origin, range))) { // warning 211: possibly unintended assignment
866 if (pev(i, pev_takedamage)) {
867 if (calc) {
868 pev(i, pev_origin, pOrigin);
869 tmpdmg = damage - (damage / range) * get_distance_f(origin, pOrigin);
870 } else {
871 tmpdmg = damage;
872 }
873 fm_fakedamage(i, "molotov", tmpdmg, dmgtype);
874 }
875 }
876 }
877
878 stock random_fire(Origin[3], ent) {
879
880 new range = get_pcvar_num(pMlRadius);
881 new iOrigin[3];
882
883 for (new i = 1; i <= 5; i++) {
884
885 g_g = 1;
886
887 iOrigin[0] = Origin[0] + random_num(-range, range);
888 iOrigin[1] = Origin[1] + random_num(-range, range);
889 iOrigin[2] = Origin[2];
890 iOrigin[2] = ground_z(iOrigin, ent);
891
892 while (get_distance(iOrigin, Origin) > range) {
893 g_g++;
894 #if defined MOLOTOV_DEBUG
895 //log_amx("[MC] random_fire ent(%d) i(%d) g_g(%d)", ent, i, g_g);
896 #endif
897 iOrigin[0] = Origin[0] + random_num(-range, range);
898 iOrigin[1] = Origin[1] + random_num(-range, range);
899 iOrigin[2] = Origin[2];
900
901 if (g_g >= ANTI_LAGG) {
902 iOrigin[2] = ground_z(iOrigin, ent, 1);
903 } else {
904 iOrigin[2] = ground_z(iOrigin, ent);
905 }
906 }
907
908 new rand = random_num(5, 15);
909
910 message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
911 write_byte(TE_SPRITE);
912 write_coord(iOrigin[0]);
913 write_coord(iOrigin[1]);
914 write_coord(iOrigin[2] + rand * 5);
915 write_short(firespr);
916 write_byte(rand);
917 write_byte(100);
918 message_end();
919
920 if (!(i % 4)) { // Smoke every 4th flame
921 message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
922 write_byte(TE_SMOKE);
923 write_coord(iOrigin[0]);
924 write_coord(iOrigin[1]);
925 write_coord(iOrigin[2] + 120);
926 write_short(smokespr[random_num(0, 1)]);
927 write_byte(random_num(10, 30));
928 write_byte(random_num(10, 20));
929 message_end();
930 }
931 }
932 }
933
934 stock kill(k, v) {
935
936 user_silentkill(v);
937
938 new kteam = get_user_team(k);
939 new vteam = get_user_team(v);
940
941 new kfrags = get_user_frags(k) + 1;
942 new kdeaths = get_user_deaths(k);
943 if (kteam == vteam) {
944 kfrags = get_user_frags(k) - 2;
945 }
946
947 new vfrags = get_user_frags(v);
948 new vdeaths = get_user_deaths(v);
949
950 message_begin(MSG_ALL, gmsgScoreInfo);
951 write_byte(k);
952 write_short(kfrags);
953 write_short(kdeaths);
954 write_short(0);
955 write_short(kteam);
956 message_end();
957
958 message_begin(MSG_ALL, gmsgScoreInfo);
959 write_byte(v);
960 write_short(vfrags + 1);
961 write_short(vdeaths);
962 write_short(0);
963 write_short(vteam);
964 message_end();
965
966 message_begin(MSG_ALL, gmsgDeathMsg, {0,0,0}, 0);
967 write_byte(k);
968 write_byte(v);
969 write_byte(0);
970 write_string("molotov");
971 message_end();
972
973 g_frags[k]++;
974
975 if (kteam != vteam) {
976 cs_set_user_money(k, cs_get_user_money(k) + 300);
977 } else {
978 cs_set_user_money(k, cs_get_user_money(k) - 300);
979 }
980 }
981
982 stock ground_z(iOrigin[3], ent, skip = 0, iRecursion = 0) {
983
984 #if defined MOLOTOV_DEBUG
985 new iEntValid = pev_valid(ent);
986 if (iRecursion > 0) {
987 log_amx("[MC] ground_z ent(%d) iEntValid(%d) skip(%d) iRecursion(%d)", ent, iEntValid, skip, iRecursion);
988 }
989 #endif
990 iOrigin[2] += random_num(5, 80);
991
992 if (!pev_valid(ent)) { // Fix for: Run time error 10: native error (native "set_pev")
993 return iOrigin[2];
994 }
995
996 new Float:fOrigin[3];
997
998 IVecFVec(iOrigin, fOrigin);
999
1000 set_pev(ent, pev_origin, fOrigin);
1001
1002 engfunc(EngFunc_DropToFloor, ent);
1003
1004 if (!skip && !engfunc(EngFunc_EntIsOnFloor, ent)) {
1005 if (iRecursion >= ANTI_LAGG) {
1006 skip = 1;
1007 }
1008 #if defined MOLOTOV_DEBUG
1009 log_amx("[MC] ground_z ++iRecursion(%d)", ++iRecursion);
1010 return ground_z(iOrigin, ent, skip, iRecursion);
1011 #else
1012 return ground_z(iOrigin, ent, skip, ++iRecursion);
1013 #endif
1014 }
1015
1016 pev(ent, pev_origin, fOrigin);
1017
1018 return floatround(fOrigin[2]);
1019 }
1020
1021 stock reset_molotovs() {
1022 new ent = g_MaxPlayers;
1023 while ((ent = engfunc(EngFunc_FindEntityByString, ent, "model", "models/molotov/w_molotov.mdl"))) {
1024 engfunc(EngFunc_SetModel, ent, "models/w_hegrenade.mdl");
1025 }
1026 }
1027
1028 stock set_molotovs() {
1029 new ent = g_MaxPlayers;
1030 while ((ent = engfunc(EngFunc_FindEntityByString, ent, "model", "models/w_hegrenade.mdl"))) {
1031 engfunc(EngFunc_SetModel, ent, "models/molotov/w_molotov.mdl");
1032 }
1033 }
1034
1035 // This will run at event New Round if enabled
1036 public show_molotov_menu(id) {
1037 new menu[128];
1038 formatex(menu, 127, "Buy Molotov Cocktail ($%d)?^n^n1. Yes^n2. No^n^n0. Exit", get_pcvar_num(pPrice));
1039
1040 // This shows the menu for 30 seconds, I tried first with get_cvar_num("mp_buytime")*60 , but it didn't work well
1041 // when using 0.5 as mp_buytime. If you like, just change the time below
1042 show_menu(id, MOLOTOV_MENU_KEYS, menu, 30);
1043
1044 return PLUGIN_HANDLED;
1045 }
1046
1047 //Our menu function will get the player id and the key they pressed
1048 public giveMolotov(id, key) {
1049
1050 //key will start at zero
1051 switch(key) {
1052 case 0: buy_molotov(id);
1053 case 1: client_print(id, print_center, "You have chosen not to buy a Molotov cocktail");
1054 default: client_print(id, print_center, "You have chosen to exit the Molotov menu");
1055 }
1056 }

Properties

Name Value
molotov 1

Contact webmaster
ViewVC Help
Powered by ViewVC RSS 2.0 feed