Guest User

Untitled

a guest
May 18th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 133.82 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <cstrike>
  4. #include <engine>
  5. #include <fakemeta>
  6. #include <hamsandwich>
  7. #include <xs>
  8.  
  9. #define VERSION "11.2"
  10.  
  11. new const ACTIVATE[] = "weapons/mine_activate.wav"
  12. new const DEPLOY[] = "weapons/mine_deploy.wav"
  13. new const CHARGE[] = "weapons/mine_charge.wav"
  14. new const GEIGER[] = "player/geiger1.wav"
  15. new const PING[] = "turret/tu_ping.wav"
  16. new const BUTTON[] = "buttons/button9.wav"
  17.  
  18. new const SOUND_HIT[5][] = { "debris/bustmetal1.wav", "debris/bustmetal2.wav", "debris/metal1.wav", "debris/metal2.wav", "debris/metal3.wav" }
  19.  
  20. // Defines that can be modified
  21. #define MAX_PLAYERS 32
  22.  
  23. #define ADMIN_ACCESS ADMIN_RCON
  24.  
  25. #define NOTEAM_RGB_R_COLOR 0
  26. #define NOTEAM_RGB_G_COLOR 214
  27. #define NOTEAM_RGB_B_COLOR 198
  28.  
  29. #define TEAMCT_RGB_R_COLOR 0
  30. #define TEAMCT_RGB_G_COLOR 0
  31. #define TEAMCT_RGB_B_COLOR 255
  32.  
  33. #define TEAMTE_RGB_R_COLOR 255
  34. #define TEAMTE_RGB_G_COLOR 0
  35. #define TEAMTE_RGB_B_COLOR 0
  36.  
  37. #define DELAY_ADDED_TO_USE 0.2
  38.  
  39. // Some defines, I suggest not modifying these! Only if you understand the code completely!
  40. #define RING_SIZE_CONSTANT_PROXIMITY 2.1
  41. #define RING_SIZE_CONSTANT_MOTION 9.27
  42.  
  43. #define SETTINGS_REFRESH_TIME 2.0
  44.  
  45. #define OFFSET_WEAPONID 43
  46. #define EXTRAOFFSET_WEAPONS 4
  47.  
  48. #define SMART_DISTANCE_LINE_PVS 800.0
  49. #define SMART_RADIUS_RING_SHOW 1500.0
  50. #define CONE_DROP_ANGLE_COSINUS -0.30
  51. #define EXTRALENGTH_VECTOR 200.0
  52.  
  53. #define SHOT_PENETRATION_DISTANCE 4.0
  54. #define SHOT_PENETRATION_READD_TIMES 20
  55. #define SHOT_SECOND_TEST_RADIUS 10.0
  56. #define SHOT_KNIFE_REAL_RADIUS 6.0
  57. #define SHOT_ENTITY_QUEUE_LENGTH 5
  58.  
  59. #define BOT_MIN_DISTANCE_ATTACH 400.0
  60. #define BOT_WALL_MIN_COSINUS 0.866026
  61. #define BOT_MIN_HEIGHT_ALLOW 18.0
  62. #define BOT_MIN_CROUCH_HEIGHT_ALLOW 10.0
  63. #define BOT_MAX_HEIGHT_ALLOW 55.0
  64. #define BOT_FORCE_CROUCH_HEIGHT_CONST 76.0
  65.  
  66. #define CVAR_STRING_ALLOC 100
  67. #define CVAR_MAX_ASSIGNED_VALUES 30
  68. #define CVAR_MAX_STRING_LENGTH 10
  69.  
  70. #define DMG_CS_KNIFE_BULLETS (1 << 12 | 1 << 0)
  71.  
  72. #define CONE_CALC_ANGLE_MAX 75.0
  73. #define CONE_CALC_ANGLE_MIN 2.0
  74. #define CONE_CALC_DISTANCE_MAX 400.0
  75. #define CONE_CALC_DISTANCE_MIN 10000.0
  76. #define CONE_BASE_RADIUS 200.0
  77.  
  78. // Macros, made specially to make the code easier to read
  79. #define CONVERT_TO_METERS(%0) (%0 * 0.0254)
  80.  
  81. #define get_option(%1) ccvars[%1]
  82. #define toggle_option(%1) set_pcvar_num(pcvars[%1], !get_pcvar_num(pcvars[%1]))
  83. #define get_option_float(%1) Float:ccvars[%1]
  84. #define set_option_float(%1,%2) set_pcvar_float(pcvars[%1], %2)
  85.  
  86. #define is_player_alive(%1) ((cl_is_alive & (1<<%1)) && (0 < %1 <= g_maxplayers))
  87.  
  88. #define is_grenade_c4(%1) (get_pdata_int(%1, 96) & (1<<8)) // 96 is the C4 offset
  89.  
  90. #define make_explode(%1) entity_set_float(%1, EV_FL_dmgtime, 0.0)
  91. #define grenade_can_be_used(%1) (get_option(OPTION_NADES_IN_EFFECT) & NADE_BIT[%1]) ? 1 : 0
  92. #define allow_grenade_explode(%1) (get_gametime() < entity_get_float(%1, EV_FL_fuser2)) ? 0 : 1
  93. #define get_grenade_type(%1) NadeType:entity_get_int(%1, EV_INT_iuser1)
  94. #define set_grenade_allow_explode(%1,%2) entity_set_float(%1, EV_FL_fuser2, get_gametime() + %2)
  95. #define delay_explosion(%1) entity_set_float(%1, EV_FL_dmgtime, get_gametime() + get_option_float(OPTION_EXPLOSION_DELAY_TIME))
  96. #define get_trip_grenade_end_origin(%1,%2) entity_get_vector(%1, EV_VEC_vuser1, %2)
  97. #define set_trip_grenade_end_origin(%1,%2) entity_set_vector(%1, EV_VEC_vuser1, %2)
  98. #define set_trip_grenade_fly_velocity(%1,%2) entity_set_vector(%1, EV_VEC_vuser2, %2)
  99. #define get_trip_grenade_fly_velocity(%1,%2) entity_get_vector(%1, EV_VEC_vuser2, %2)
  100. #define get_trip_grenade_middle_origin(%1,%2) entity_get_vector(%1, EV_VEC_vuser3, %2)
  101. #define set_trip_grenade_middle_origin(%1,%2) entity_set_vector(%1, EV_VEC_vuser3, %2)
  102. #define get_trip_grenade_arm_time(%1) entity_get_float(%1, EV_FL_fuser1)
  103. #define set_trip_grenade_arm_time(%1,%2) entity_set_float(%1, EV_FL_fuser1, get_gametime() + %2)
  104. #define set_trip_grenade_attached_to(%1,%2) entity_set_int(%1, EV_INT_iuser4, %2)
  105. #define get_trip_grenade_attached_to(%1) entity_get_int(%1, EV_INT_iuser4)
  106. #define get_trip_grenade_mode(%1) TripNadeMode:entity_get_int(%1, EV_INT_iuser3)
  107. #define set_trip_grenade_mode(%1,%2) entity_set_int(%1, EV_INT_iuser3, _:%2)
  108. #define play_sound(%1,%2) (get_option(OPTION_PLAY_SOUNDS)) ? emit_sound(%1, CHAN_WEAPON, %2, 1.0, ATTN_STATIC, 0, PITCH_NORM) : 0
  109. #define play_sound2(%1,%2) (get_option(OPTION_PLAY_SOUNDS)) ? emit_sound(%1, CHAN_ITEM, %2, 1.0, ATTN_STATIC, 0, PITCH_NORM) : 0
  110. #define refresh_can_use_nade(%1,%2) get_enabled_modes(%1,%2) ? (cl_can_use_nade[%2] |= (1<<%1)) : (cl_can_use_nade[%2] &= ~(1<<%1))
  111.  
  112. // Enums! First time I've ever used them. These should make the code infinitely easier to read.
  113. enum NadeRace
  114. {
  115. GRENADE_EXPLOSIVE = 0,
  116. GRENADE_FLASHBANG,
  117. GRENADE_SMOKEGREN,
  118. }
  119.  
  120. new const NADE_MODEL[][] =
  121. {
  122. "w_hegrenade.mdl",
  123. "w_flashbang.mdl",
  124. "w_smokegrenade.mdl"
  125. }
  126.  
  127. new const NADE_WPID[NadeRace] =
  128. {
  129. CSW_HEGRENADE,
  130. CSW_FLASHBANG,
  131. CSW_SMOKEGRENADE
  132. }
  133.  
  134. new const NADE_BIT[NadeRace] =
  135. {
  136. (1<<0),
  137. (1<<1),
  138. (1<<2)
  139. }
  140.  
  141. enum NadeType
  142. {
  143. NADE_DUD = -1,
  144. NADE_NORMAL,
  145. NADE_PROXIMITY,
  146. NADE_IMPACT,
  147. NADE_TRIP,
  148. NADE_MOTION,
  149. NADE_SATCHEL,
  150. NADE_HOMING
  151. }
  152.  
  153. new UNCOUNTABLE_NADE_MODES = ((1 << (_:NADE_DUD + 1)) | (1 << (_:NADE_NORMAL + 1)) | (1 << (_:NADE_IMPACT + 1)) | (1 << (_:NADE_HOMING + 1)))
  154. new const NADE_DONT_COUNT = (1<<31)
  155.  
  156. enum Fward
  157. {
  158. FWD_NONE_ACTIVE = 0,
  159. FWD_CMDSTART = (1<<0),
  160. FWD_THINK = (1<<1),
  161. FWD_SETMODEL = (1<<2),
  162. FWD_TOUCH = (1<<3),
  163. FWD_SEC_EXPLODE = (1<<4),
  164. FWD_TAKEDAMAGE = (1<<5),
  165. FWD_THINK_POST = (1<<6),
  166. FWD_MESSAGE = (1<<7),
  167. FWD_HPSYSTEM = (1<<8)
  168. }
  169.  
  170. enum ZmFunc
  171. {
  172. ZM_NO_ZM_ACTIVE = 0,
  173. ZM_ZM_ACTIVE = 1,
  174. ZM_CAN_THINK = 2,
  175. ZM_DO_ALL = 3
  176. }
  177.  
  178. enum TripNadeMode
  179. {
  180. TRIP_NOT_ATTACHED = 0,
  181. TRIP_ATTACHED,
  182. TRIP_WAITING,
  183. TRIP_SCANNING,
  184. TRIP_SHOULD_DETONATE,
  185. TRIP_DETONATED
  186. }
  187.  
  188. enum Option
  189. {
  190. // Primary Off/On cvar
  191. OPTION_ENABLE_NADE_MODES,
  192.  
  193. // General settings
  194. OPTION_FRIENDLY_FIRE,
  195. OPTION_BOT_ALLOW,
  196. OPTION_NADES_IN_EFFECT,
  197. OPTION_REMOVE_IF_DIES,
  198. OPTION_SUPPRESS_FITH,
  199. OPTION_DISPLAY_MODE_ON_DRAW,
  200. OPTION_PLAY_SOUNDS,
  201. OPTION_RESET_MODE_ON_THROW,
  202. OPTION_RESOURCE_USE,
  203. OPTION_MSG_SVC_BAD,
  204. OPTION_TEAM_PLAY,
  205. OPTION_AFFECT_OWNER,
  206. OPTION_UNITS_SYSTEM,
  207. OPTION_MONSTERMOD_SUPPORT,
  208.  
  209. // Grenade modes control menu
  210. OPTION_NORMAL_ENABLED,
  211. OPTION_PROXIMITY_ENABLED,
  212. OPTION_IMPACT_ENABLED,
  213. OPTION_TRIP_ENABLED,
  214. OPTION_MOTION_ENABLED,
  215. OPTION_SATCHEL_ENABLED,
  216. OPTION_HOMING_ENABLED,
  217.  
  218. OPTION_REACT_TRIP_G,
  219. OPTION_REACT_TRIP_F,
  220. OPTION_REACT_TRIP_S,
  221.  
  222. OPTION_PROXIMITY_LOS,
  223. OPTION_MOTION_LOS,
  224. OPTION_SATCHEL_DELAY,
  225.  
  226. // Limit settings
  227. OPTION_LIMIT_SYSTEM,
  228.  
  229. OPTION_LIMIT_PROXIMITY,
  230. OPTION_LIMIT_TRIP,
  231. OPTION_LIMIT_MOTION,
  232. OPTION_LIMIT_SATCHEL,
  233.  
  234. OPTION_INFINITE_GRENADES,
  235. OPTION_INFINITE_FLASHES,
  236. OPTION_INFINITE_SMOKES,
  237.  
  238. // Hitpoints system settings
  239. OPTION_MATERIAL_SYSTEM,
  240.  
  241. OPTION_SEC_EXPLO_AFFECT,
  242.  
  243. OPTION_HITPOINT_NORMAL,
  244. OPTION_HITPOINT_PROXIMITY,
  245. OPTION_HITPOINT_IMPACT,
  246. OPTION_HITPOINT_TRIP,
  247. OPTION_HITPOINT_MOTION,
  248. OPTION_HITPOINT_SATCHEL,
  249. OPTION_HITPOINT_HOMING,
  250.  
  251. OPTION_HITPOINT_DEATH,
  252. OPTION_HITPOINT_FF,
  253. OPTION_HITPOINT_INTER_DMG,
  254.  
  255. // Damage settings
  256. OPTION_DAMAGE_SYSTEM,
  257.  
  258. OPTION_DMG_THROUGH_WALL,
  259. OPTION_DMG_SELF,
  260. OPTION_DMG_TEAMMATES,
  261.  
  262. OPTION_DMG_NORMAL,
  263. OPTION_DMG_PROXIMITY,
  264. OPTION_DMG_IMPACT,
  265. OPTION_DMG_TRIP,
  266. OPTION_DMG_MOTION,
  267. OPTION_DMG_SATCHEL,
  268. OPTION_DMG_HOMING,
  269.  
  270. // Internal functional settings
  271. OPTION_EXPLOSION_DELAY_TIME,
  272. OPTION_RADIUS_SEC_EXPLOSION,
  273.  
  274. OPTION_ARM_TIME_TRIP,
  275. OPTION_ARM_TIME_MOTION,
  276. OPTION_ARM_TIME_SATCHEL,
  277. OPTION_ARM_TIME_PROXIMITY,
  278.  
  279. OPTION_TRIP_DETECT_DISTANCE,
  280. OPTION_TRIP_FLY_SPEED,
  281.  
  282. OPTION_RADIUS_PROXIMITY,
  283. OPTION_RADIUS_MOTION,
  284.  
  285. OPTION_HOMING_SCAN_RANGE,
  286. OPTION_HOMING_SUPER_RANGE,
  287. OPTION_HOMING_EXTRATIME,
  288. OPTION_HOMING_SPEED_ADD
  289. }
  290.  
  291. enum OptionType
  292. {
  293. TOPTION_TOGGLE = 1,
  294. TOPTION_CELL,
  295. TOPTION_FLOAT,
  296. }
  297.  
  298. enum TraceHandles
  299. {
  300. TH_LOS,
  301. TH_DMG,
  302. TH_TRIP,
  303. TH_BOT
  304. }
  305.  
  306. // Mod texts that appear when right clicking for mode change
  307. new modetext[][] = { "Normal", "Proximity", "Impact", "Trip laser", "Motion sensor", "Satchel chage", "Homing" }
  308.  
  309. // CFG data [name and file path]
  310. new const CFG_FILE_NAME[] = "nade_modes.cfg"
  311. new CFG_FILE[200]
  312.  
  313. // Current nade mode
  314. new NadeType:mode[MAX_PLAYERS + 1][NadeRace]
  315.  
  316. // Global server variables
  317. new g_maxplayers
  318.  
  319. // Cached client data [bot,alive,weapon,team]
  320. new cl_is_bot = 0
  321. new cl_is_alive = 0
  322. new cl_weapon[MAX_PLAYERS + 1]
  323. new CsTeams:cl_team[MAX_PLAYERS + 1]
  324.  
  325. // Limit system counter/blocker
  326. new cl_counter[MAX_PLAYERS + 1][NadeRace][NadeType]
  327. new cl_can_use_nade[NadeRace]
  328.  
  329. // Next +use time, used in satchel charge nade types when the delay explosion is set
  330. new Float:cl_nextusetime[MAX_PLAYERS + 1]
  331.  
  332. // Special queue used in penetration detection of grenades
  333. new cl_entity_queue[MAX_PLAYERS + 1][SHOT_ENTITY_QUEUE_LENGTH]
  334.  
  335. // Trace handles used in different situations
  336. new g_ptrace[TraceHandles]
  337.  
  338. // Hp system global variables [enable/disable, global trace attack class registration]
  339. new g_check_hpsystem = -1
  340. new Trie:trace_attack_reg_class
  341.  
  342. // First enabled modes, so that the plugin knows where to start
  343. new NadeType:g_firstenabledmode[NadeRace]
  344.  
  345. // Plugin functionality enable/disable mechanism
  346. new Fward:bs_forward_collection = FWD_NONE_ACTIVE
  347.  
  348. // Menu variables
  349. new settingsmenu[MAX_PLAYERS + 1] // Settings menu handler
  350. new cvar_menu_pos[MAX_PLAYERS + 1] // Cvar menu handler
  351. new callbacks[2] // Settings menu callbacks
  352.  
  353. // Cvars [Options]
  354. new OptionType:option_type[Option]
  355. new Array:option_value[Option]
  356. new pcvars[Option] // Cvar pointers
  357. new ccvars[Option] // Cached cvars
  358.  
  359. // Mod dependent variables [CZ/ZM]
  360. new ZmFunc:g_zombie_mod
  361. new g_botquota
  362.  
  363. // Forwards
  364. new g_FW_property, g_PFW_property
  365.  
  366. // Messages
  367. new beampoint
  368. new shockwave
  369. new nadebits
  370.  
  371.  
  372.  
  373. /* -------------------------------
  374. [Plugin Start]
  375. ------------------------------- */
  376. public plugin_precache()
  377. {
  378. // Registered before all the nade plugins
  379. RegisterHam(Ham_Think, "grenade", "fw_think")
  380. RegisterHam(Ham_Think, "grenade", "fw_track_explosion")
  381. RegisterHam(Ham_Think, "grenade", "fw_think_post", 1)
  382.  
  383. // Trace attack register trie
  384. trace_attack_reg_class = TrieCreate()
  385.  
  386. // We register this here to track shots, it is also important
  387. register_forward(FM_Spawn, "fw_spawn", 1)
  388.  
  389. beampoint = precache_model("sprites/laserbeam.spr")
  390. shockwave = precache_model("sprites/shockwave.spr")
  391. nadebits = precache_model("models/chromegibs.mdl")
  392.  
  393. precache_sound(ACTIVATE)
  394. precache_sound(CHARGE)
  395. precache_sound(DEPLOY)
  396. precache_sound(GEIGER)
  397. precache_sound(PING)
  398. precache_sound(BUTTON)
  399.  
  400. for (new i=0;i<5;i++)
  401. {
  402. precache_sound(SOUND_HIT[i])
  403. }
  404. }
  405.  
  406. public plugin_init()
  407. {
  408. // Plugin registration (normal and net)
  409. register_plugin("NadeModes", VERSION, "Nomexous & OT")
  410. register_cvar("nademodes_version", VERSION, FCVAR_SERVER|FCVAR_SPONLY)
  411.  
  412. // Commands
  413. register_clcmd("amx_nade_mode_menu", "conjure_menu", ADMIN_ACCESS, "Shows settings menu for grenade modes.")
  414. register_clcmd("amx_nmm", "conjure_menu", ADMIN_ACCESS, "Shows settings menu for grenade modes.")
  415.  
  416. register_clcmd("say /nadehelp", "conjure_help", -1, "Shows help for grenade modes.")
  417. register_clcmd("say_team /nadehelp", "conjure_help", -1, "Shows help for grenade modes.")
  418.  
  419. // General Settings Options
  420. pcvars[OPTION_FRIENDLY_FIRE] = get_cvar_pointer("mp_friendlyfire")
  421.  
  422. register_option(OPTION_ENABLE_NADE_MODES, "nademodes_enable", "1")
  423. register_option(OPTION_NADES_IN_EFFECT, "nademodes_nades_in_effect", "7", TOPTION_CELL)
  424. register_option(OPTION_MSG_SVC_BAD, "nademodes_svc_bad_error_fix", "0")
  425.  
  426. register_option(OPTION_PLAY_SOUNDS, "nademodes_play_grenade_sounds", "1")
  427. register_option(OPTION_RESOURCE_USE, "nademodes_effects", "2", TOPTION_CELL)
  428.  
  429. register_option(OPTION_DISPLAY_MODE_ON_DRAW, "nademodes_display_mode_on_draw", "1")
  430. register_option(OPTION_RESET_MODE_ON_THROW, "nademodes_reset_mode_on_throw", "0")
  431. register_option(OPTION_SUPPRESS_FITH, "nademodes_suppress_fire_in_the_hole", "0")
  432.  
  433. register_option(OPTION_BOT_ALLOW, "nademodes_bot_support", "1")
  434.  
  435. register_option(OPTION_REMOVE_IF_DIES, "nademodes_remove_if_player_dies", "0")
  436. register_option(OPTION_AFFECT_OWNER, "nademodes_affect_owner", "1")
  437. register_option(OPTION_TEAM_PLAY, "nademodes_team_play", "1")
  438. register_option(OPTION_UNITS_SYSTEM, "nademodes_unit_system", "1")
  439.  
  440. register_option(OPTION_MONSTERMOD_SUPPORT, "nademodes_monstermod_support", "0")
  441.  
  442. // General Settings Option Values
  443. register_option_value(OPTION_RESOURCE_USE, "0;1;2;3")
  444. register_option_value(OPTION_NADES_IN_EFFECT, "0;1;2;3;4;5;6;7")
  445.  
  446. // Mode Settings Options
  447. register_option(OPTION_NORMAL_ENABLED, "nademodes_normal_enabled", "1")
  448. register_option(OPTION_PROXIMITY_ENABLED, "nademodes_proximity_enabled", "1")
  449. register_option(OPTION_IMPACT_ENABLED, "nademodes_impact_enabled", "1")
  450. register_option(OPTION_TRIP_ENABLED, "nademodes_trip_enabled", "1")
  451. register_option(OPTION_MOTION_ENABLED, "nademodes_motion_enabled", "1")
  452. register_option(OPTION_SATCHEL_ENABLED, "nademodes_satchel_enabled", "1")
  453. register_option(OPTION_HOMING_ENABLED, "nademodes_homing_enabled", "1")
  454.  
  455. register_option(OPTION_REACT_TRIP_G, "nademodes_grenade_react", "1")
  456. register_option(OPTION_REACT_TRIP_F, "nademodes_flash_react", "1")
  457. register_option(OPTION_REACT_TRIP_S, "nademodes_smoke_react", "1")
  458.  
  459. register_option(OPTION_PROXIMITY_LOS, "nademodes_proximity_fov", "0")
  460. register_option(OPTION_MOTION_LOS, "nademodes_motion_fov", "1")
  461. register_option(OPTION_SATCHEL_DELAY, "nademodes_satchel_delay", "0")
  462.  
  463. // Limit Settings Options
  464. register_option(OPTION_LIMIT_SYSTEM, "nademodes_limit_system", "2", TOPTION_CELL)
  465. register_option(OPTION_LIMIT_PROXIMITY, "nademodes_proximity_limit", "5", TOPTION_CELL)
  466. register_option(OPTION_LIMIT_TRIP, "nademodes_trip_limit", "5", TOPTION_CELL)
  467. register_option(OPTION_LIMIT_MOTION, "nademodes_motion_limit", "5", TOPTION_CELL)
  468. register_option(OPTION_LIMIT_SATCHEL, "nademodes_satchel_limit", "5", TOPTION_CELL)
  469.  
  470. register_option(OPTION_INFINITE_GRENADES, "nademodes_infinite_grenades", "0")
  471. register_option(OPTION_INFINITE_FLASHES, "nademodes_infinite_flashes", "0")
  472. register_option(OPTION_INFINITE_SMOKES, "nademodes_infinite_smokes", "0")
  473.  
  474. // Limit Settings Option Values
  475. register_option_value(OPTION_LIMIT_SYSTEM, "0;1;2")
  476.  
  477. register_option_value(OPTION_LIMIT_PROXIMITY, "0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15")
  478. register_option_value(OPTION_LIMIT_TRIP, "0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15")
  479. register_option_value(OPTION_LIMIT_MOTION, "0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15")
  480. register_option_value(OPTION_LIMIT_SATCHEL, "0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15")
  481.  
  482. // Hitpoint Options
  483. register_option(OPTION_MATERIAL_SYSTEM, "nademodes_material_system", "0", TOPTION_CELL)
  484. register_option(OPTION_HITPOINT_DEATH, "nademodes_grenade_death","1")
  485.  
  486. register_option(OPTION_SEC_EXPLO_AFFECT, "nademodes_secondary_explosions_mode", "0")
  487.  
  488. register_option(OPTION_HITPOINT_NORMAL, "nademodes_hitpoints_normal", "10", TOPTION_CELL)
  489. register_option(OPTION_HITPOINT_PROXIMITY, "nademodes_hitpoints_proximity", "100", TOPTION_CELL)
  490. register_option(OPTION_HITPOINT_IMPACT, "nademodes_hitpoints_impact", "10", TOPTION_CELL)
  491. register_option(OPTION_HITPOINT_TRIP, "nademodes_hitpoints_trip", "100", TOPTION_CELL)
  492. register_option(OPTION_HITPOINT_MOTION, "nademodes_hitpoints_motion", "100", TOPTION_CELL)
  493. register_option(OPTION_HITPOINT_SATCHEL, "nademodes_hitpoints_satchel", "100", TOPTION_CELL)
  494. register_option(OPTION_HITPOINT_HOMING, "nademodes_hitpoints_homing", "10", TOPTION_CELL)
  495.  
  496. register_option(OPTION_HITPOINT_INTER_DMG, "nademodes_hitpoints_intergrenade_damage", "100", TOPTION_FLOAT)
  497. register_option(OPTION_HITPOINT_FF, "nademodes_hitpoints_friendlyfire_ammount", "50", TOPTION_FLOAT)
  498.  
  499. // Hitpoint Options Values
  500. register_option_value(OPTION_MATERIAL_SYSTEM, "0;1;2")
  501.  
  502. register_option_value(OPTION_HITPOINT_NORMAL, "0;1;10;20;30;40;50;60;70;80;90;100;110;120;130;140;150;175;200;250;300;400;500;750;1000")
  503. register_option_value(OPTION_HITPOINT_PROXIMITY, "0;1;10;20;30;40;50;60;70;80;90;100;110;120;130;140;150;175;200;250;300;400;500;750;1000")
  504. register_option_value(OPTION_HITPOINT_IMPACT, "0;1;10;20;30;40;50;60;70;80;90;100;110;120;130;140;150;175;200;250;300;400;500;750;1000")
  505. register_option_value(OPTION_HITPOINT_TRIP, "0;1;10;20;30;40;50;60;70;80;90;100;110;120;130;140;150;175;200;250;300;400;500;750;1000")
  506. register_option_value(OPTION_HITPOINT_MOTION, "0;1;10;20;30;40;50;60;70;80;90;100;110;120;130;140;150;175;200;250;300;400;500;750;1000")
  507. register_option_value(OPTION_HITPOINT_SATCHEL, "0;1;10;20;30;40;50;60;70;80;90;100;110;120;130;140;150;175;200;250;300;400;500;750;1000")
  508. register_option_value(OPTION_HITPOINT_HOMING, "0;1;10;20;30;40;50;60;70;80;90;100;110;120;130;140;150;175;200;250;300;400;500;750;1000")
  509.  
  510. register_option_value(OPTION_HITPOINT_INTER_DMG, "0;5;10;15;20;25;30;35;45;50;55;60;65;70;75;80;85;90;95;100")
  511. register_option_value(OPTION_HITPOINT_FF, "0;5;10;15;20;25;30;35;45;50;55;60;65;70;75;80;85;90;95;100")
  512.  
  513. // Damage System Option Registration
  514. register_option(OPTION_DAMAGE_SYSTEM, "nademodes_damage_system", "2", TOPTION_CELL)
  515.  
  516. register_option(OPTION_DMG_THROUGH_WALL, "nademodes_damage_through_wall", "50", TOPTION_CELL)
  517. register_option(OPTION_DMG_SELF, "nademodes_damage_self", "50", TOPTION_CELL)
  518. register_option(OPTION_DMG_TEAMMATES, "nademodes_damage_teammate", "50", TOPTION_CELL)
  519.  
  520. register_option(OPTION_DMG_NORMAL, "nademodes_damage_normal", "1.0", TOPTION_FLOAT)
  521. register_option(OPTION_DMG_IMPACT, "nademodes_damage_impact", "1.0", TOPTION_FLOAT)
  522. register_option(OPTION_DMG_PROXIMITY, "nademodes_damage_proximity", "1.0", TOPTION_FLOAT)
  523. register_option(OPTION_DMG_MOTION, "nademodes_damage_motion", "1.0", TOPTION_FLOAT)
  524. register_option(OPTION_DMG_SATCHEL, "nademodes_damage_satchel", "1.0", TOPTION_FLOAT)
  525. register_option(OPTION_DMG_TRIP, "nademodes_damage_trip", "1.0", TOPTION_FLOAT)
  526. register_option(OPTION_DMG_HOMING, "nademodes_damage_homing", "1.0", TOPTION_FLOAT)
  527.  
  528. // Damage System Option Values
  529. register_option_value(OPTION_DAMAGE_SYSTEM, "0;1;2")
  530.  
  531. register_option_value(OPTION_DMG_THROUGH_WALL, "0;5;10;15;20;25;30;35;45;50;55;60;65;70;75;80;85;90;95;100")
  532. register_option_value(OPTION_DMG_SELF, "0;5;10;15;20;25;30;35;45;50;55;60;65;70;75;80;85;90;95;100")
  533. register_option_value(OPTION_DMG_TEAMMATES, "0;5;10;15;20;25;30;35;45;50;55;60;65;70;75;80;85;90;95;100")
  534.  
  535. register_option_value(OPTION_DMG_NORMAL, "0.2;0.4;0.6;0.8;1;1.2;1.4;1.6;1.8;2;2.2;2.4;2.6;2.8;3;3.2;3.4;3.6;3.8;4;5;6;7")
  536. register_option_value(OPTION_DMG_IMPACT, "0.2;0.4;0.6;0.8;1;1.2;1.4;1.6;1.8;2;2.2;2.4;2.6;2.8;3;3.2;3.4;3.6;3.8;4;5;6;7")
  537. register_option_value(OPTION_DMG_MOTION, "0.2;0.4;0.6;0.8;1;1.2;1.4;1.6;1.8;2;2.2;2.4;2.6;2.8;3;3.2;3.4;3.6;3.8;4;5;6;7")
  538. register_option_value(OPTION_DMG_PROXIMITY, "0.2;0.4;0.6;0.8;1;1.2;1.4;1.6;1.8;2;2.2;2.4;2.6;2.8;3;3.2;3.4;3.6;3.8;4;5;6;7")
  539. register_option_value(OPTION_DMG_SATCHEL, "0.2;0.4;0.6;0.8;1;1.2;1.4;1.6;1.8;2;2.2;2.4;2.6;2.8;3;3.2;3.4;3.6;3.8;4;5;6;7")
  540. register_option_value(OPTION_DMG_TRIP, "0.2;0.4;0.6;0.8;1;1.2;1.4;1.6;1.8;2;2.2;2.4;2.6;2.8;3;3.2;3.4;3.6;3.8;4;5;6;7")
  541. register_option_value(OPTION_DMG_HOMING, "0.2;0.4;0.6;0.8;1;1.2;1.4;1.6;1.8;2;2.2;2.4;2.6;2.8;3;3.2;3.4;3.6;3.8;4;5;6;7")
  542.  
  543. // Internal Settings Float Options
  544. register_option(OPTION_EXPLOSION_DELAY_TIME, "nademodes_explosion_delay_time", "60000.0", TOPTION_FLOAT)
  545.  
  546. register_option(OPTION_RADIUS_SEC_EXPLOSION, "nademodes_secondary_explosion_radius", "275.0", TOPTION_FLOAT)
  547.  
  548. register_option(OPTION_ARM_TIME_TRIP, "nademodes_trip_grenade_arm_time", "3.0", TOPTION_FLOAT)
  549. register_option(OPTION_ARM_TIME_PROXIMITY, "nademodes_proximity_arm_time", "2.0", TOPTION_FLOAT)
  550. register_option(OPTION_ARM_TIME_MOTION, "nademodes_motion_arm_time", "2.0", TOPTION_FLOAT)
  551. register_option(OPTION_ARM_TIME_SATCHEL, "nademodes_satchel_arm_time", "2.0", TOPTION_FLOAT)
  552.  
  553. register_option(OPTION_TRIP_FLY_SPEED, "nademodes_trip_grenade_fly_speed", "400.0", TOPTION_FLOAT)
  554. register_option(OPTION_TRIP_DETECT_DISTANCE, "nademodes_trip_grenade_detection_limit", "16000.0", TOPTION_FLOAT)
  555.  
  556. register_option(OPTION_RADIUS_PROXIMITY, "nademodes_proximity_radius", "150.0", TOPTION_FLOAT)
  557. register_option(OPTION_RADIUS_MOTION, "nademodes_motion_radius", "200.0", TOPTION_FLOAT)
  558.  
  559. register_option(OPTION_HOMING_SCAN_RANGE, "nademodes_homing_detection_range", "500.0", TOPTION_FLOAT)
  560. register_option(OPTION_HOMING_SUPER_RANGE, "nademodes_homing_superhoming_range", "100.0", TOPTION_FLOAT)
  561. register_option(OPTION_HOMING_EXTRATIME, "nademodes_homing_extratime", "0.5", TOPTION_FLOAT)
  562. register_option(OPTION_HOMING_SPEED_ADD, "nademodes_homing_velocity_deviation", "60.0", TOPTION_FLOAT)
  563.  
  564. // Internal Settings Option Values
  565. register_option_value(OPTION_EXPLOSION_DELAY_TIME, "600;700;800;900;1000;1400;1800;2200;2600;3000;4000;5000;6000;10000;60000")
  566.  
  567. register_option_value(OPTION_RADIUS_SEC_EXPLOSION, "25;50;75;100;125;150;175;200;225;250;275;300;325;350")
  568.  
  569. register_option_value(OPTION_ARM_TIME_TRIP, "1;1.5;2;2.5;3;3.5;4;4.5;5")
  570. register_option_value(OPTION_ARM_TIME_PROXIMITY, "1;1.5;2;2.5;3;3.5;4;4.5;5")
  571. register_option_value(OPTION_ARM_TIME_MOTION, "1;1.5;2;2.5;3;3.5;4;4.5;5")
  572. register_option_value(OPTION_ARM_TIME_SATCHEL, "1;1.5;2;2.5;3;3.5;4;4.5;5")
  573.  
  574. register_option_value(OPTION_TRIP_FLY_SPEED, "200;250;300;350;400;450;500;550;600;650;700;750;800;850;900;1000")
  575. register_option_value(OPTION_TRIP_DETECT_DISTANCE, "400;800;1000;2000;4000;8000;16000")
  576.  
  577. register_option_value(OPTION_RADIUS_PROXIMITY, "100;110;120;130;140;150;160;170;180;190;200")
  578. register_option_value(OPTION_RADIUS_MOTION, "150;160;170;180;190;200;210;220;230;240;250")
  579.  
  580. register_option_value(OPTION_HOMING_SCAN_RANGE,"200;250;300;350;400;450;500;550;600;650;700;750;800;850;900;950;1000")
  581. register_option_value(OPTION_HOMING_SUPER_RANGE, "40;60;80;100;120;140;160;180;200;220;240;260;280;300")
  582. register_option_value(OPTION_HOMING_EXTRATIME, "0;0.1;0.2;0.3;0.4;0.5;0.6;0.7;0.8;0.9;1")
  583. register_option_value(OPTION_HOMING_SPEED_ADD, "10;15;20;25;30;35;40;45;50;55;60;65;70;75;80;85;90;95;100;125;150")
  584.  
  585. cacheCvars()
  586.  
  587. register_event("CurWeapon", "event_armnade", "b", "1=1", "2=4", "2=9", "2=25")
  588. register_event("CurWeapon", "event_curweapon", "b", "1=1")
  589. register_event("HLTV", "event_new_round", "a", "1=0", "2=0")
  590.  
  591. register_dictionary("nademodes.txt")
  592.  
  593. g_firstenabledmode[GRENADE_EXPLOSIVE] = NADE_NORMAL
  594. g_firstenabledmode[GRENADE_FLASHBANG] = NADE_NORMAL
  595. g_firstenabledmode[GRENADE_SMOKEGREN] = NADE_NORMAL
  596.  
  597. g_ptrace[TH_LOS] = create_tr2()
  598. g_ptrace[TH_DMG] = create_tr2()
  599. g_ptrace[TH_TRIP] = create_tr2()
  600. g_ptrace[TH_BOT] = create_tr2()
  601.  
  602. callbacks[0] = menu_makecallback("callback_disabled")
  603. callbacks[1] = menu_makecallback("callback_enabled")
  604.  
  605. // Register all the forwards
  606. RegisterHam(Ham_TakeDamage, "player", "fw_takedamage")
  607. RegisterHam(Ham_Killed, "player", "fw_killed_post", 1)
  608. RegisterHam(Ham_Spawn, "player", "fw_spawn_post", 1)
  609. RegisterHam(Ham_TakeDamage, "func_wall", "fw_monster_takedamage")
  610. RegisterHam(Ham_Player_PreThink, "player", "fw_playerprethink")
  611.  
  612. RegisterHam(Ham_Touch, "grenade", "fw_touch")
  613. RegisterHam(Ham_TakeDamage, "grenade", "fw_grenade_takedamage")
  614.  
  615. RegisterHam(Ham_TraceAttack, "worldspawn", "fw_global_traceattack", 1)
  616. RegisterHam(Ham_TraceAttack, "player", "fw_global_traceattack", 1)
  617.  
  618. g_FW_property = CreateMultiForward("fw_NM_nade_property_set", ET_STOP, FP_CELL, FP_CELL)
  619. g_PFW_property = CreateMultiForward("fw_NM_nade_property_set_post", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL)
  620.  
  621. register_forward(FM_CmdStart, "fw_cmdstart")
  622. register_forward(FM_SetModel, "fw_setmodel", 1)
  623. register_forward(FM_TraceLine, "fw_traceline")
  624.  
  625. register_message(get_user_msgid("SendAudio"), "fith_audio")
  626. register_message(get_user_msgid("TextMsg"), "fith_text")
  627.  
  628. set_task(SETTINGS_REFRESH_TIME, "update_forward_registration", 0, "", 0, "b", 0)
  629.  
  630. g_botquota = cvar_exists("bot_quota") ? get_cvar_pointer("bot_quota") : 0;
  631. g_zombie_mod = ZM_NO_ZM_ACTIVE // Initially we are not sure if a zombie mod is on or not
  632. }
  633.  
  634. public plugin_cfg()
  635. {
  636. // Get the config dir
  637. new config[sizeof(CFG_FILE)]
  638. get_configsdir(config, charsmax(CFG_FILE))
  639. format(CFG_FILE, charsmax(CFG_FILE), "%s/%s", config, CFG_FILE_NAME)
  640.  
  641. // Execute the CFG file
  642. if(file_exists(CFG_FILE))
  643. {
  644. server_cmd("exec %s", CFG_FILE)
  645. cacheCvars()
  646. }
  647.  
  648. AddMenuItem("Nade Mode Menu", "amx_nmm", ADMIN_ACCESS, "NadeModes")
  649. }
  650.  
  651. public plugin_end()
  652. {
  653. TrieDestroy(trace_attack_reg_class)
  654. DestroyForward(g_FW_property)
  655. DestroyForward(g_PFW_property)
  656.  
  657. free_tr2(g_ptrace[TH_LOS])
  658. free_tr2(g_ptrace[TH_DMG])
  659. free_tr2(g_ptrace[TH_TRIP])
  660. free_tr2(g_ptrace[TH_BOT])
  661.  
  662. save_cfg()
  663. }
  664.  
  665. register_option(Option:option, const name[300], const string[], OptionType:type = TOPTION_TOGGLE, flags = 0, Float:value = 0.0)
  666. {
  667. pcvars[option] = register_cvar(name, string, flags, value)
  668. option_type[option] = type
  669. return
  670. }
  671.  
  672. register_option_value(Option:option, values[CVAR_STRING_ALLOC])
  673. {
  674. if (option_type[option] == TOPTION_TOGGLE)
  675. return
  676.  
  677. option_value[option] = ArrayCreate(CVAR_STRING_ALLOC + 1)
  678. ArrayPushString(option_value[option], values)
  679. }
  680.  
  681. stock unregister_all_option_value()
  682. {
  683. for (new Option:option=OPTION_ENABLE_NADE_MODES; option <= OPTION_HOMING_SPEED_ADD; option += OPTION_FRIENDLY_FIRE)
  684. {
  685. if (option_type[option] == TOPTION_TOGGLE)
  686. return
  687.  
  688. ArrayDestroy(option_value[option])
  689. }
  690. }
  691.  
  692. cacheCvars()
  693. {
  694. for (new Option:option=OPTION_ENABLE_NADE_MODES; option <= OPTION_HOMING_SPEED_ADD; option += OPTION_FRIENDLY_FIRE)
  695. {
  696. if (option_type[option] == TOPTION_FLOAT)
  697. {
  698. ccvars[option] = _:get_pcvar_float(pcvars[option])
  699. }
  700. else
  701. {
  702. ccvars[option] = get_pcvar_num(pcvars[option])
  703. }
  704. }
  705. }
  706.  
  707. public save_cfg()
  708. {
  709. static file[3000]
  710. format(file, charsmax(file), "echo [NadeModes] Executing config file ...^n")
  711.  
  712. format(file, charsmax(file), "%s^n// General CVARS^n^n", file)
  713.  
  714. format(file, charsmax(file), "%snademodes_enable %d^n", file, get_option(OPTION_ENABLE_NADE_MODES))
  715. format(file, charsmax(file), "%snademodes_nades_in_effect %d^n", file, get_option(OPTION_NADES_IN_EFFECT))
  716.  
  717. format(file, charsmax(file), "%snademodes_effects %d^n", file, get_option(OPTION_RESOURCE_USE))
  718. format(file, charsmax(file), "%snademodes_play_grenade_sounds %d^n", file, get_option(OPTION_PLAY_SOUNDS))
  719. format(file, charsmax(file), "%snademodes_svc_bad_error_fix %d^n", file, get_option(OPTION_MSG_SVC_BAD))
  720.  
  721. format(file, charsmax(file), "%snademodes_display_mode_on_draw %d^n", file, get_option(OPTION_DISPLAY_MODE_ON_DRAW))
  722. format(file, charsmax(file), "%snademodes_reset_mode_on_throw %d^n", file, get_option(OPTION_RESET_MODE_ON_THROW))
  723. format(file, charsmax(file), "%snademodes_suppress_fire_in_the_hole %d^n", file, get_option(OPTION_SUPPRESS_FITH))
  724.  
  725. format(file, charsmax(file), "%snademodes_bot_support %d^n", file, get_option(OPTION_BOT_ALLOW))
  726.  
  727. format(file, charsmax(file), "%snademodes_remove_if_player_dies %d^n", file, get_option(OPTION_REMOVE_IF_DIES))
  728. format(file, charsmax(file), "%snademodes_affect_owner %d^n", file, get_option(OPTION_AFFECT_OWNER))
  729. format(file, charsmax(file), "%snademodes_team_play %d^n", file, get_option(OPTION_TEAM_PLAY))
  730. format(file, charsmax(file), "%snademodes_unit_system %d^n", file, get_option(OPTION_UNITS_SYSTEM))
  731.  
  732. format(file, charsmax(file), "%snademodes_monstermod_support %d^n", file, get_option(OPTION_MONSTERMOD_SUPPORT))
  733.  
  734. format(file, charsmax(file), "%s^n// Mode CVARS^n^n", file)
  735.  
  736. format(file, charsmax(file), "%snademodes_normal_enabled %d^n", file, get_option(OPTION_NORMAL_ENABLED))
  737. format(file, charsmax(file), "%snademodes_proximity_enabled %d^n", file, get_option(OPTION_PROXIMITY_ENABLED))
  738. format(file, charsmax(file), "%snademodes_impact_enabled %d^n", file, get_option(OPTION_IMPACT_ENABLED))
  739. format(file, charsmax(file), "%snademodes_trip_enabled %d^n", file, get_option(OPTION_TRIP_ENABLED))
  740. format(file, charsmax(file), "%snademodes_motion_enabled %d^n", file, get_option(OPTION_MOTION_ENABLED))
  741. format(file, charsmax(file), "%snademodes_satchel_enabled %d^n", file, get_option(OPTION_SATCHEL_ENABLED))
  742. format(file, charsmax(file), "%snademodes_homing_enabled %d^n", file, get_option(OPTION_HOMING_ENABLED))
  743.  
  744. format(file, charsmax(file), "%snademodes_grenade_react %d^n", file, get_option(OPTION_REACT_TRIP_G))
  745. format(file, charsmax(file), "%snademodes_flash_react %d^n", file, get_option(OPTION_REACT_TRIP_F))
  746. format(file, charsmax(file), "%snademodes_smoke_react %d^n", file, get_option(OPTION_REACT_TRIP_S))
  747.  
  748. format(file, charsmax(file), "%snademodes_proximity_fov %d^n", file, get_option(OPTION_PROXIMITY_LOS))
  749. format(file, charsmax(file), "%snademodes_motion_fov %d^n", file, get_option(OPTION_MOTION_LOS))
  750. format(file, charsmax(file), "%snademodes_satchel_delay %d^n", file, get_option(OPTION_SATCHEL_DELAY))
  751.  
  752. format(file, charsmax(file), "%s^n// Limit & Test CVARS^n^n", file)
  753.  
  754. format(file, charsmax(file), "%snademodes_limit_system %d^n", file, get_option(OPTION_LIMIT_SYSTEM))
  755.  
  756. format(file, charsmax(file), "%snademodes_proximity_limit %d^n", file, get_option(OPTION_LIMIT_PROXIMITY))
  757. format(file, charsmax(file), "%snademodes_trip_limit %d^n", file, get_option(OPTION_LIMIT_TRIP))
  758. format(file, charsmax(file), "%snademodes_motion_limit %d^n", file, get_option(OPTION_LIMIT_MOTION))
  759. format(file, charsmax(file), "%snademodes_satchel_limit %d^n", file, get_option(OPTION_LIMIT_SATCHEL))
  760.  
  761. format(file, charsmax(file), "%snademodes_infinite_grenades %d^n", file, get_option(OPTION_INFINITE_GRENADES))
  762. format(file, charsmax(file), "%snademodes_infinite_flashes %d^n", file, get_option(OPTION_INFINITE_FLASHES))
  763. format(file, charsmax(file), "%snademodes_infinite_smokes %d^n", file, get_option(OPTION_INFINITE_SMOKES))
  764.  
  765. format(file, charsmax(file), "%s^n// Intergrenade CVARS CVARS^n^n", file)
  766.  
  767.  
  768. format(file, charsmax(file), "%snademodes_material_system %d^n", file, get_option(OPTION_MATERIAL_SYSTEM))
  769. format(file, charsmax(file), "%snademodes_grenade_death %d^n", file, get_option(OPTION_HITPOINT_DEATH))
  770.  
  771. format(file, charsmax(file), "%snademodes_secondary_explosions_mode %d^n", file, get_option(OPTION_SEC_EXPLO_AFFECT))
  772. format(file, charsmax(file), "%snademodes_secondary_explosion_radius %f^n", file, get_option_float(OPTION_RADIUS_SEC_EXPLOSION))
  773.  
  774. format(file, charsmax(file), "%snademodes_hitpoints_normal %d^n", file, get_option(OPTION_HITPOINT_NORMAL))
  775. format(file, charsmax(file), "%snademodes_hitpoints_proximity %d^n", file, get_option(OPTION_HITPOINT_PROXIMITY))
  776. format(file, charsmax(file), "%snademodes_hitpoints_impact %d^n", file, get_option(OPTION_HITPOINT_IMPACT))
  777. format(file, charsmax(file), "%snademodes_hitpoints_trip %d^n", file, get_option(OPTION_HITPOINT_TRIP))
  778. format(file, charsmax(file), "%snademodes_hitpoints_motion %d^n", file, get_option(OPTION_HITPOINT_MOTION))
  779. format(file, charsmax(file), "%snademodes_hitpoints_satchel %d^n", file, get_option(OPTION_HITPOINT_SATCHEL))
  780. format(file, charsmax(file), "%snademodes_hitpoints_homing %d^n", file, get_option(OPTION_HITPOINT_HOMING))
  781.  
  782. format(file, charsmax(file), "%snademodes_hitpoints_intergrenade_damage %f^n", file, get_option_float(OPTION_HITPOINT_INTER_DMG))
  783. format(file, charsmax(file), "%snademodes_hitpoints_friendlyfire_ammount %f^n", file, get_option_float(OPTION_HITPOINT_FF))
  784.  
  785. format(file, charsmax(file), "%s^n// Damage CVARS^n^n", file)
  786.  
  787. format(file, charsmax(file), "%snademodes_damage_system %d^n", file, get_option(OPTION_DAMAGE_SYSTEM))
  788.  
  789. format(file, charsmax(file), "%snademodes_damage_self %d^n", file, get_option(OPTION_DMG_SELF))
  790. format(file, charsmax(file), "%snademodes_damage_through_wall %d^n", file, get_option(OPTION_DMG_THROUGH_WALL))
  791. format(file, charsmax(file), "%snademodes_damage_teammate %d^n", file, get_option(OPTION_DMG_TEAMMATES))
  792.  
  793. format(file, charsmax(file), "%snademodes_damage_normal %f^n", file, get_option_float(OPTION_DMG_NORMAL))
  794. format(file, charsmax(file), "%snademodes_damage_proximity %f^n", file, get_option_float(OPTION_DMG_PROXIMITY))
  795. format(file, charsmax(file), "%snademodes_damage_impact %f^n", file, get_option_float(OPTION_DMG_IMPACT))
  796. format(file, charsmax(file), "%snademodes_damage_trip %f^n", file, get_option_float(OPTION_DMG_TRIP))
  797. format(file, charsmax(file), "%snademodes_damage_motion %f^n", file, get_option_float(OPTION_DMG_MOTION))
  798. format(file, charsmax(file), "%snademodes_damage_satchel %f^n", file, get_option_float(OPTION_DMG_SATCHEL))
  799. format(file, charsmax(file), "%snademodes_damage_homing %f^n", file, get_option_float(OPTION_DMG_HOMING))
  800.  
  801. format(file, charsmax(file), "%s^n// Internal Funcitonal CVARS^n^n", file)
  802.  
  803. format(file, charsmax(file), "%snademodes_explosion_delay_time %f^n", file, get_option_float(OPTION_EXPLOSION_DELAY_TIME))
  804.  
  805. format(file, charsmax(file), "%snademodes_proximity_arm_time %f^n", file, get_option_float(OPTION_ARM_TIME_PROXIMITY))
  806. format(file, charsmax(file), "%snademodes_proximity_radius %f^n", file, get_option_float(OPTION_RADIUS_PROXIMITY))
  807.  
  808. format(file, charsmax(file), "%snademodes_trip_grenade_arm_time %f^n", file, get_option_float(OPTION_ARM_TIME_TRIP))
  809. format(file, charsmax(file), "%snademodes_trip_grenade_fly_speed %f^n", file, get_option_float(OPTION_TRIP_FLY_SPEED))
  810. format(file, charsmax(file), "%snademodes_trip_grenade_detection_limit %f^n", file, get_option_float(OPTION_TRIP_DETECT_DISTANCE))
  811.  
  812. format(file, charsmax(file), "%snademodes_motion_arm_time %f^n", file, get_option_float(OPTION_ARM_TIME_MOTION))
  813. format(file, charsmax(file), "%snademodes_motion_radius %f^n", file, get_option_float(OPTION_RADIUS_MOTION))
  814.  
  815. format(file, charsmax(file), "%snademodes_satchel_arm_time %f^n", file, get_option_float(OPTION_ARM_TIME_SATCHEL))
  816.  
  817. format(file, charsmax(file), "%snademodes_homing_detection_range %f^n", file, get_option_float(OPTION_HOMING_SCAN_RANGE))
  818. format(file, charsmax(file), "%snademodes_homing_superhoming_range %f^n", file, get_option_float(OPTION_HOMING_SUPER_RANGE))
  819. format(file, charsmax(file), "%snademodes_homing_extratime %f^n", file, get_option_float(OPTION_HOMING_EXTRATIME))
  820. format(file, charsmax(file), "%snademodes_homing_velocity_deviation %f^n", file, get_option_float(OPTION_HOMING_SPEED_ADD))
  821.  
  822. format(file, charsmax(file), "%s^necho [NadeModes] Settings loaded from config file", file)
  823.  
  824. delete_file(CFG_FILE)
  825. write_file(CFG_FILE, file)
  826. }
  827.  
  828. /* -------------------------------
  829. [Plugin Commands & Menus]
  830. ------------------------------- */
  831. public conjure_help(id)
  832. {
  833. static help_file[3000]
  834.  
  835. format(help_file, charsmax(help_file), "%L", id, "NADE_HTML")
  836.  
  837. delete_file("nmm.htm")
  838. write_file("nmm.htm", help_file)
  839. show_motd(id, "nmm.htm", "Mega-Nade Mod")
  840.  
  841. return PLUGIN_CONTINUE
  842. }
  843.  
  844. public conjure_menu(id, level, cid)
  845. {
  846. if (cmd_access(id, level, cid, 1))
  847. {
  848. main_menu(id)
  849. }
  850.  
  851. return PLUGIN_HANDLED
  852. }
  853.  
  854. stock main_menu(id)
  855. {
  856. static menu
  857. settingsmenu[id] = menu_create("NadeModes - Main Menu", "menu_handler")
  858. menu = settingsmenu[id]
  859.  
  860. add_option_toggle(menu, OPTION_ENABLE_NADE_MODES, "Enable nade modes", "Yes", "No")
  861.  
  862. menu_additem(menu, "Execute config file")
  863. menu_additem(menu, "General settings", _, _, get_option(OPTION_ENABLE_NADE_MODES) ? callbacks[1] : callbacks[0])
  864. menu_additem(menu, "Mode control menu", _, _, get_option(OPTION_ENABLE_NADE_MODES) ? callbacks[1] : callbacks[0])
  865. menu_additem(menu, "Mode limit & test menu", _, _, is_nademodes_enabled() ? callbacks[1] : callbacks[0])
  866. menu_additem(menu, "Hitpoints menu", _, _, is_nademodes_enabled() ? callbacks[1] : callbacks[0])
  867. menu_additem(menu, "Mode damage settings", _, _, is_nademodes_enabled() ? callbacks[1] : callbacks[0])
  868. menu_additem(menu, "Internal functional settings", _, _, is_nademodes_enabled() ? callbacks[1] : callbacks[0])
  869.  
  870. menu_display(id, settingsmenu[id])
  871. return PLUGIN_CONTINUE
  872. }
  873.  
  874. public menu_handler(id, menu, item)
  875. {
  876. if (item < 0)
  877. {
  878. return PLUGIN_HANDLED
  879. }
  880.  
  881. switch (item)
  882. {
  883. case 0:
  884. {
  885. toggle_option(OPTION_ENABLE_NADE_MODES)
  886. update_forward_registration()
  887. }
  888. case 1:
  889. {
  890. if(file_exists(CFG_FILE))
  891. {
  892. server_cmd("exec %s", CFG_FILE)
  893. update_forward_registration()
  894. }
  895. else
  896. {
  897. client_print(id, print_chat, "[NDM] Config file not found!")
  898. }
  899. }
  900.  
  901. default:
  902. {
  903. menu_destroy(menu)
  904. cvar_menu(id, 0, item - 1)
  905. return PLUGIN_HANDLED
  906. }
  907. }
  908.  
  909.  
  910. menu_destroy(menu)
  911. main_menu(id)
  912. return PLUGIN_HANDLED
  913. }
  914.  
  915. stock cvar_menu(id, page = 0, menu_set = 0)
  916. {
  917. if (menu_set <= 0)
  918. return PLUGIN_CONTINUE
  919.  
  920. static menu
  921.  
  922. switch (menu_set)
  923. {
  924. case 1:
  925. {
  926. settingsmenu[id] = menu_create("NadeModes - General Settings", "cvar_menu_handler")
  927. menu = settingsmenu[id]
  928.  
  929. add_nade_option(menu, OPTION_NADES_IN_EFFECT, "Grenades that can use the nademodes")
  930.  
  931. add_option_quatrotoggle(menu, OPTION_RESOURCE_USE, "Plugin effects", "\rOff", "\yNormal", "\ySmart Mode", "\yLow Bandwidth Mode")
  932. add_option_toggle(menu, OPTION_PLAY_SOUNDS, "Grenade sounds", "On", "Off")
  933. add_option_toggle(menu, OPTION_MONSTERMOD_SUPPORT, "Monstermod support", "On", "Off")
  934. add_option_toggle(menu, OPTION_MSG_SVC_BAD, "SVC_BAD fix", "On^n \yNote: \wTurn on when the server has this problem!^n", "Off^n \yNote: \wTurn on when the server has this problem!^n")
  935. add_option_toggle(menu, OPTION_BOT_ALLOW, "Allow bots to use the moded nades", "Yes^n", "No^n")
  936.  
  937. add_option_toggle(menu, OPTION_DISPLAY_MODE_ON_DRAW, "Display mode on draw", "Yes", "No")
  938. add_option_toggle(menu, OPTION_RESET_MODE_ON_THROW, "Reset mode on throw", "Yes^n", "No^n")
  939.  
  940. add_option_toggle(menu, OPTION_REMOVE_IF_DIES, "Remove the nades if player dies", "Yes", "No")
  941. add_option_toggle(menu, OPTION_AFFECT_OWNER, "Traps can be activated by owner", "Yes", "No")
  942. add_option_toggle(menu, OPTION_TEAM_PLAY, "Team play (teammates will not be affected by nades)", "Yes^n", "No^n")
  943.  
  944. add_option_toggle(menu, OPTION_SUPPRESS_FITH, "Suppress ^"Fire in the hole!^"", "Yes^n", "No^n")
  945.  
  946. add_option_toggle(menu, OPTION_UNITS_SYSTEM, "Unit system:", "Metric", "Inch")
  947.  
  948. }
  949. case 2:
  950. {
  951. settingsmenu[id] = menu_create("NadeModes - Mode Control", "cvar_menu_handler")
  952. menu = settingsmenu[id]
  953.  
  954. add_option_toggle(menu, OPTION_NORMAL_ENABLED, "Enable normal grenades", "Yes", "No")
  955. add_option_toggle(menu, OPTION_PROXIMITY_ENABLED, "Enable proximity grenades", "Yes", "No")
  956. add_option_toggle(menu, OPTION_IMPACT_ENABLED, "Enable impact grenades", "Yes", "No")
  957. add_option_toggle(menu, OPTION_TRIP_ENABLED, "Enable trip grenades", "Yes", "No")
  958. add_option_toggle(menu, OPTION_MOTION_ENABLED, "Enable motion sensor grenades", "Yes", "No")
  959. add_option_toggle(menu, OPTION_SATCHEL_ENABLED, "Enable satchel charge grenades", "Yes", "No")
  960. add_option_toggle(menu, OPTION_HOMING_ENABLED, "Enable homing grenades", "Yes^n", "No^n")
  961.  
  962. add_option_toggle(menu, OPTION_REACT_TRIP_G, "Trip grenade react method", "Boom", "Fly", OPTION_TRIP_ENABLED)
  963. add_option_toggle(menu, OPTION_REACT_TRIP_F, "Trip flash react method", "Boom", "Fly", OPTION_TRIP_ENABLED)
  964. add_option_toggle(menu, OPTION_REACT_TRIP_S, "Trip smoke react method", "Boom^n", "Fly^n", OPTION_TRIP_ENABLED)
  965.  
  966. add_option_toggle(menu, OPTION_PROXIMITY_LOS, "Proximity detonate only if player is in line of sight", "Yes", "No", OPTION_PROXIMITY_ENABLED)
  967. add_option_toggle(menu, OPTION_MOTION_LOS, "Motion detonate only if player is in line of sight", "Yes", "No", OPTION_MOTION_ENABLED)
  968. add_option_toggle(menu, OPTION_SATCHEL_DELAY, "Add delay between satchel explotions", "Yes", "No", OPTION_SATCHEL_ENABLED)
  969. }
  970. case 3:
  971. {
  972. settingsmenu[id] = menu_create("NadeModes - Limit & Test Menu", "cvar_menu_handler")
  973. menu = settingsmenu[id]
  974.  
  975. add_option_tritoggle(menu, OPTION_LIMIT_SYSTEM, "Limit system", "\rOff^n", "\yAvailable for each nade^n", "\yAvailable for all nades summed up^n")
  976.  
  977. add_cell_option(menu, OPTION_LIMIT_PROXIMITY, "Proximity throw limit", "grenades", OPTION_LIMIT_SYSTEM)
  978. add_cell_option(menu, OPTION_LIMIT_TRIP, "Trip grenade throw limit", "grenades", OPTION_LIMIT_SYSTEM)
  979. add_cell_option(menu, OPTION_LIMIT_MOTION, "Motion throw limit", "grenades", OPTION_LIMIT_SYSTEM)
  980. add_cell_with_space_option(menu, OPTION_LIMIT_SATCHEL, "Stachel throw limit", "grenades", OPTION_LIMIT_SYSTEM)
  981.  
  982. add_option_toggle(menu, OPTION_INFINITE_GRENADES, "Infinite grenades", "Yes", "No")
  983. add_option_toggle(menu, OPTION_INFINITE_FLASHES, "Infinite flashes", "Yes", "No")
  984. add_option_toggle(menu, OPTION_INFINITE_SMOKES, "Infinite smokes", "Yes", "No")
  985. }
  986. case 4:
  987. {
  988. settingsmenu[id] = menu_create("NadeModes - Hitpoint Menu", "cvar_menu_handler")
  989. menu = settingsmenu[id]
  990.  
  991. add_option_tritoggle(menu, OPTION_MATERIAL_SYSTEM, "Interaction system", "\rOff", "\ySecondary Explosions", "\yHit Point System")
  992.  
  993.  
  994.  
  995. switch (get_option(OPTION_MATERIAL_SYSTEM))
  996. {
  997. case 0:
  998. {
  999. add_option_toggle(menu, OPTION_HITPOINT_DEATH, "Nade death", "Explode^n", "Desintegrate^n",OPTION_MATERIAL_SYSTEM)
  1000.  
  1001. add_cell_option(menu, OPTION_HITPOINT_NORMAL, "Normal grenade hitpoints", "hitpoints", OPTION_MATERIAL_SYSTEM)
  1002. add_cell_option(menu, OPTION_HITPOINT_PROXIMITY, "Proximity grenade hitpoints", "hitpoints", OPTION_MATERIAL_SYSTEM)
  1003. add_cell_option(menu, OPTION_HITPOINT_IMPACT, "Impact grenade hitpoints", "hitpoints", OPTION_MATERIAL_SYSTEM)
  1004. add_cell_option(menu, OPTION_HITPOINT_TRIP, "Trip grenade hitpoints", "hitpoints", OPTION_MATERIAL_SYSTEM)
  1005. add_cell_option(menu, OPTION_HITPOINT_MOTION, "Motion grenade hitpoints", "hitpoints", OPTION_MATERIAL_SYSTEM)
  1006. add_cell_option(menu, OPTION_HITPOINT_SATCHEL, "Satchel grenade hitpoints", "hitpoints", OPTION_MATERIAL_SYSTEM)
  1007. add_cell_option(menu, OPTION_HITPOINT_HOMING, "Homing grenade hitpoints", "hitpoints", OPTION_MATERIAL_SYSTEM)
  1008. }
  1009.  
  1010. case 1:
  1011. {
  1012. add_option_toggle(menu, OPTION_SEC_EXPLO_AFFECT, "Secondary explosions", "\yEach nade affects each!^n", "\yHe grenade affects all^n")
  1013. add_float_unit_option(menu, OPTION_RADIUS_SEC_EXPLOSION, "Secondary explosion radius affection", "")
  1014. }
  1015.  
  1016. case 2:
  1017. {
  1018. add_option_toggle(menu, OPTION_HITPOINT_DEATH, "Nade death", "Explode^n", "Desintegrate^n",OPTION_MATERIAL_SYSTEM)
  1019.  
  1020. add_cell_option(menu, OPTION_HITPOINT_NORMAL, "Normal grenade hitpoints", "hitpoints", OPTION_NORMAL_ENABLED)
  1021. add_cell_option(menu, OPTION_HITPOINT_PROXIMITY, "Proximity grenade hitpoints", "hitpoints", OPTION_PROXIMITY_ENABLED)
  1022. add_cell_option(menu, OPTION_HITPOINT_IMPACT, "Impact grenade hitpoints", "hitpoints", OPTION_IMPACT_ENABLED)
  1023. add_cell_option(menu, OPTION_HITPOINT_TRIP, "Trip grenade hitpoints", "hitpoints", OPTION_TRIP_ENABLED)
  1024. add_cell_option(menu, OPTION_HITPOINT_MOTION, "Motion grenade hitpoints", "hitpoints", OPTION_MOTION_ENABLED)
  1025. add_cell_option(menu, OPTION_HITPOINT_SATCHEL, "Satchel grenade hitpoints", "hitpoints", OPTION_SATCHEL_ENABLED)
  1026. add_cell_option(menu, OPTION_HITPOINT_HOMING, "Homing grenade hitpoints", "hitpoints^n", OPTION_HOMING_ENABLED)
  1027.  
  1028. add_float_option(menu, OPTION_HITPOINT_FF, "Friendlyfire", "%", OPTION_MATERIAL_SYSTEM)
  1029. add_float_option(menu, OPTION_HITPOINT_INTER_DMG, "Damage between the grenades", "%", OPTION_MATERIAL_SYSTEM)
  1030.  
  1031. }
  1032. }
  1033. }
  1034. case 5:
  1035. {
  1036. settingsmenu[id] = menu_create("NadeModes - Damage Settings", "cvar_menu_handler")
  1037. menu = settingsmenu[id]
  1038.  
  1039. add_option_tritoggle(menu, OPTION_DAMAGE_SYSTEM, "Damage system", "\rOff^n", "\yActive for every mode^n", "\yEach mode configurable^n")
  1040.  
  1041. add_float_option(menu, OPTION_DMG_SELF, "Nade self damage percent", "%", OPTION_DAMAGE_SYSTEM)
  1042. add_float_option(menu, OPTION_DMG_THROUGH_WALL, "Nade through wall damage percent", "%", OPTION_DAMAGE_SYSTEM)
  1043.  
  1044. switch (get_option(OPTION_DAMAGE_SYSTEM))
  1045. {
  1046. case 0:
  1047. {
  1048. add_float_option(menu, OPTION_DMG_TEAMMATES, "Team mates damage percent", "%^n", OPTION_DAMAGE_SYSTEM)
  1049. }
  1050.  
  1051. case 1:
  1052. {
  1053. add_float_option(menu, OPTION_DMG_TEAMMATES, "Team mates damage percent", "%^n", OPTION_FRIENDLY_FIRE)
  1054.  
  1055. add_float_option(menu, OPTION_DMG_NORMAL, "Grenade general damage multiply","times")
  1056. }
  1057.  
  1058. case 2:
  1059. {
  1060. add_float_option(menu, OPTION_DMG_TEAMMATES, "Team mates damage percent", "%^n", OPTION_FRIENDLY_FIRE)
  1061.  
  1062. add_float_option(menu, OPTION_DMG_NORMAL, "Normal Grenade - damage multiply","times",OPTION_NORMAL_ENABLED)
  1063. add_float_option(menu, OPTION_DMG_PROXIMITY, "Proximity Grenade - damage multiply","times", OPTION_PROXIMITY_ENABLED)
  1064. add_float_option(menu, OPTION_DMG_IMPACT, "Impact Grenade - damage multiply","times", OPTION_IMPACT_ENABLED)
  1065. add_float_option(menu, OPTION_DMG_TRIP, "Trip Grenade - damage multiply","times", OPTION_TRIP_ENABLED)
  1066. add_float_option(menu, OPTION_DMG_MOTION, "Motion Grenade - damage multiply","times", OPTION_MOTION_ENABLED)
  1067. add_float_option(menu, OPTION_DMG_SATCHEL, "Satchel Grenade - damage multiply","times", OPTION_SATCHEL_ENABLED)
  1068. add_float_option(menu, OPTION_DMG_HOMING, "Homing Grenade - damage multiply","times", OPTION_HOMING_ENABLED)
  1069. }
  1070. }
  1071. }
  1072. case 6:
  1073. {
  1074. settingsmenu[id] = menu_create("NadeModes - Internal Functional Settings", "cvar_menu_handler")
  1075. menu = settingsmenu[id]
  1076.  
  1077. add_float_option(menu, OPTION_EXPLOSION_DELAY_TIME, "Grenade general delay explode time", "seconds^n")
  1078.  
  1079. add_float_option(menu, OPTION_ARM_TIME_PROXIMITY, "Proximity arm time", "seconds", OPTION_PROXIMITY_ENABLED)
  1080. add_float_unit_option(menu, OPTION_RADIUS_PROXIMITY, "Proximity detection radius", "^n", OPTION_PROXIMITY_ENABLED)
  1081.  
  1082. add_float_option(menu, OPTION_ARM_TIME_TRIP, "Trip grenade arm time", "seconds", OPTION_TRIP_ENABLED)
  1083. add_float_unit_option(menu, OPTION_TRIP_DETECT_DISTANCE, "Trip grenade detection distance", "", OPTION_TRIP_ENABLED)
  1084. add_float_unit_option(menu, OPTION_TRIP_FLY_SPEED, "Trip grenade fly speed", "^n", OPTION_TRIP_ENABLED)
  1085.  
  1086. add_float_option(menu, OPTION_ARM_TIME_SATCHEL, "Satchel charge arm time", "seconds^n", OPTION_SATCHEL_ENABLED)
  1087.  
  1088. add_float_option(menu, OPTION_ARM_TIME_MOTION, "Motion sensor arm time", "seconds", OPTION_MOTION_ENABLED)
  1089. add_float_unit_option(menu, OPTION_RADIUS_MOTION, "Motion sensor detection radius", "^n", OPTION_MOTION_ENABLED)
  1090.  
  1091. add_float_option(menu, OPTION_HOMING_EXTRATIME, "Homing extra arm explosion time", "seconds", OPTION_HOMING_ENABLED)
  1092. add_float_unit_option(menu, OPTION_HOMING_SCAN_RANGE, "Homing grenade detection range", "", OPTION_HOMING_ENABLED)
  1093. add_float_unit_option(menu, OPTION_HOMING_SUPER_RANGE, "Homing grenade superhoming range", "", OPTION_HOMING_ENABLED)
  1094. add_float_unit_option(menu, OPTION_HOMING_SPEED_ADD, "Homing grenade air acceleration", "", OPTION_HOMING_ENABLED)
  1095. }
  1096. }
  1097.  
  1098. cvar_menu_pos[id] = menu_set
  1099. menu_display(id, settingsmenu[id], page)
  1100. return PLUGIN_CONTINUE
  1101. }
  1102.  
  1103. stock add_option_toggle(menu, Option:control_option, const basetext[], const yestext[], const notext[], Option:displayif = Option:-1)
  1104. {
  1105. static cmd[4], itemtext[100]
  1106. num_to_str(_:control_option, cmd, charsmax(cmd))
  1107.  
  1108. format(itemtext, charsmax(itemtext), "%s: %s%s", basetext, (get_option(control_option) ? "\y" : "\r" ), (get_option(control_option) ? yestext : notext))
  1109. menu_additem(menu, itemtext, cmd, _, (displayif != Option:-1 && !get_option(displayif)) ? callbacks[0] : callbacks[1])
  1110. }
  1111.  
  1112. stock add_option_tritoggle(menu, Option:control_option, const basetext[], const text[], const text2[], const text3[], Option:displayif = Option:-1)
  1113. {
  1114. static cmd[4], itemtext[100]
  1115. num_to_str(_:control_option, cmd, charsmax(cmd))
  1116.  
  1117. format(itemtext, charsmax(itemtext), "%s:\y %s%s%s", basetext, (get_option(control_option) == 0 ? text : "" ), (get_option(control_option) == 1 ? text2 : "" ), (get_option(control_option) == 2 ? text3 : "" ))
  1118. menu_additem(menu, itemtext, cmd, _, (displayif != Option:-1 && !get_option(displayif)) ? callbacks[0] : callbacks[1])
  1119. }
  1120.  
  1121. stock add_option_quatrotoggle(menu, Option:control_option, const basetext[], const text[], const text2[], const text3[], const text4[], Option:displayif = Option:-1)
  1122. {
  1123. static cmd[4], itemtext[100]
  1124. num_to_str(_:control_option, cmd, charsmax(cmd))
  1125.  
  1126. format(itemtext, charsmax(itemtext), "%s:\y %s%s%s%s", basetext, (get_option(control_option) == 0 ? text : "" ), (get_option(control_option) == 1 ? text2 : "" ), (get_option(control_option) == 2 ? text3 : "" ), (get_option(control_option) == 3 ? text4 : "" ))
  1127. menu_additem(menu, itemtext, cmd, _, (displayif != Option:-1 && !get_option(displayif)) ? callbacks[0] : callbacks[1])
  1128. }
  1129.  
  1130. stock add_nade_option(menu, Option:control_option, const basetext[])
  1131. {
  1132. static cmd[4], itemtext[100]
  1133. num_to_str(_:control_option, cmd, charsmax(cmd))
  1134.  
  1135. format(itemtext, charsmax(itemtext), "%s:%s%s%s%s^n", basetext, (get_option(control_option) ? "\y" : " \rNone" ), ((get_option(control_option) & NADE_BIT[GRENADE_EXPLOSIVE]) ? " He" : ""), ((get_option(control_option) & NADE_BIT[GRENADE_FLASHBANG]) ? " Flash" : ""), ((get_option(control_option) & NADE_BIT[GRENADE_SMOKEGREN]) ? " Smoke" : ""))
  1136. menu_additem(menu, itemtext, cmd, _, _)
  1137. }
  1138.  
  1139. stock add_float_option(menu, Option:control_option, const basetext[], const unit[], Option:displayif = Option:-1)
  1140. {
  1141. static cmd[4], itemtext[100], value[20]
  1142. float_to_str(get_option_float(control_option), value, charsmax(value))
  1143. format(value, charsmax(value), "%0.2f", get_option_float(control_option))
  1144.  
  1145. num_to_str(_:control_option, cmd, charsmax(cmd))
  1146.  
  1147. format(itemtext, charsmax(itemtext), "%s: \y%s \r%s", basetext, value, unit)
  1148. menu_additem(menu, itemtext, cmd, _, (displayif != Option:-1 && !get_option(displayif)) ? callbacks[0] : callbacks[1])
  1149. }
  1150.  
  1151. stock add_cell_option(menu, Option:control_option, const basetext[], const unit[], Option:displayif = Option:-1)
  1152. {
  1153. static cmd[4], itemtext[100], value[20]
  1154. num_to_str(get_option(control_option), value, charsmax(value))
  1155. format(value, charsmax(value), "%d", get_option(control_option))
  1156. if (!get_option(control_option))
  1157. {
  1158. value = "Off"
  1159. }
  1160.  
  1161. num_to_str(_:control_option, cmd, charsmax(cmd))
  1162.  
  1163. format(itemtext, charsmax(itemtext), "%s: \y%s \r%s", basetext, value, get_option(control_option) ? unit : "")
  1164. menu_additem(menu, itemtext, cmd, _, (displayif != Option:-1 && !get_option(displayif)) ? callbacks[0] : callbacks[1])
  1165. }
  1166.  
  1167. stock add_cell_with_space_option(menu, Option:control_option, const basetext[], const unit[], Option:displayif = Option:-1)
  1168. {
  1169. static cmd[4], itemtext[100], value[20]
  1170. num_to_str(get_option(control_option), value, charsmax(value))
  1171. format(value, charsmax(value), "%d", get_option(control_option))
  1172. if (!get_option(control_option))
  1173. {
  1174. value = "Off"
  1175. }
  1176.  
  1177. num_to_str(_:control_option, cmd, charsmax(cmd))
  1178.  
  1179. format(itemtext, charsmax(itemtext), "%s: \y%s \r%s^n", basetext, value, get_option(control_option) ? unit : "")
  1180. menu_additem(menu, itemtext, cmd, _, (displayif != Option:-1 && !get_option(displayif)) ? callbacks[0] : callbacks[1])
  1181. }
  1182.  
  1183. stock add_float_unit_option(menu, Option:control_option, const basetext[], const extratext[], Option:displayif = Option:-1)
  1184. {
  1185. static cmd[4], itemtext[100], value[20]
  1186. format(value, charsmax(value), "%0.2f", get_option(OPTION_UNITS_SYSTEM) ? CONVERT_TO_METERS(get_option_float(control_option)) : get_option_float(control_option))
  1187.  
  1188. num_to_str(_:control_option, cmd, charsmax(cmd))
  1189.  
  1190. format(itemtext, charsmax(itemtext), "%s: \y%s \r%s%s", basetext, value, get_option(OPTION_UNITS_SYSTEM) ? "meters" : "inches", extratext)
  1191. menu_additem(menu, itemtext, cmd, _, (displayif != Option:-1 && !get_option(displayif)) ? callbacks[0] : callbacks[1])
  1192. }
  1193.  
  1194.  
  1195. public cvar_menu_handler(id, menu, item)
  1196. {
  1197. new access, info[4], callback
  1198. menu_item_getinfo(menu, item, access, info, charsmax(info), _, _, callback)
  1199.  
  1200. if (item < 0)
  1201. {
  1202. save_cfg()
  1203. update_forward_registration()
  1204. main_menu(id)
  1205. return PLUGIN_HANDLED
  1206. }
  1207.  
  1208. new cvar = str_to_num(info)
  1209.  
  1210. switch (option_type[Option:cvar])
  1211. {
  1212. case TOPTION_TOGGLE:
  1213. {
  1214. toggle_option(Option:cvar)
  1215. }
  1216. case TOPTION_CELL:
  1217. {
  1218. new value_string[CVAR_STRING_ALLOC];
  1219. ArrayGetString(option_value[Option:cvar], 0, value_string, charsmax(value_string))
  1220. format(value_string, charsmax(value_string), "%s;", value_string)
  1221.  
  1222. new values[CVAR_MAX_ASSIGNED_VALUES][CVAR_MAX_STRING_LENGTH]
  1223. new true_value[CVAR_MAX_ASSIGNED_VALUES]
  1224.  
  1225. new last = 0, newpos = 0, k = 0;
  1226.  
  1227. for (new i=0;i<CVAR_STRING_ALLOC;i++)
  1228. {
  1229. if(equal(value_string[i], ";", 1))
  1230. {
  1231. newpos = i
  1232. }
  1233.  
  1234. if (newpos > last)
  1235. {
  1236. for (new j=last;j<newpos;j++)
  1237. {
  1238. format(values[k], CVAR_MAX_STRING_LENGTH - 1, "%s%s", values[k], value_string[j])
  1239. }
  1240.  
  1241. last = newpos + 1
  1242. k++
  1243. }
  1244.  
  1245. if (k == CVAR_MAX_ASSIGNED_VALUES)
  1246. {
  1247. break
  1248. }
  1249. }
  1250.  
  1251. new bool:ok = false
  1252. new counter = 0
  1253.  
  1254. for (new i=0;i<k;i++)
  1255. {
  1256. counter++
  1257.  
  1258. true_value[i] = str_to_num(values[i])
  1259.  
  1260. if (ok == true)
  1261. {
  1262. set_pcvar_num(pcvars[Option:cvar], true_value[i])
  1263. counter = 0
  1264. break
  1265. }
  1266.  
  1267. if (true_value[i] == get_option(Option:cvar))
  1268. ok = true
  1269. }
  1270.  
  1271. if (counter == k)
  1272. {
  1273. set_pcvar_num(pcvars[Option:cvar], true_value[0])
  1274. }
  1275. }
  1276. case TOPTION_FLOAT:
  1277. {
  1278. new value_string_float[CVAR_STRING_ALLOC];
  1279. ArrayGetString(option_value[Option:cvar], 0, value_string_float, charsmax(value_string_float))
  1280. format(value_string_float, charsmax(value_string_float), "%s;", value_string_float)
  1281.  
  1282. new values_float[CVAR_MAX_ASSIGNED_VALUES][CVAR_MAX_STRING_LENGTH]
  1283. new Float:true_value_float[CVAR_MAX_ASSIGNED_VALUES]
  1284.  
  1285. new last = 0, newpos = 0, k = 0;
  1286.  
  1287. for (new i=0;i<CVAR_STRING_ALLOC;i++)
  1288. {
  1289. if(equal(value_string_float[i], ";", 1))
  1290. {
  1291. newpos = i
  1292. }
  1293.  
  1294. if (newpos > last)
  1295. {
  1296. for (new j=last;j<newpos;j++)
  1297. {
  1298. format(values_float[k], CVAR_MAX_STRING_LENGTH - 1, "%s%s", values_float[k], value_string_float[j])
  1299. }
  1300.  
  1301. last = newpos + 1
  1302. k++
  1303. }
  1304.  
  1305. if (k == CVAR_MAX_ASSIGNED_VALUES)
  1306. {
  1307. break
  1308. }
  1309. }
  1310.  
  1311. new bool:ok=false
  1312. new counter = 0
  1313.  
  1314. for (new i=0;i<k;i++)
  1315. {
  1316. counter++
  1317.  
  1318. true_value_float[i] = str_to_float(values_float[i])
  1319.  
  1320. if (ok == true)
  1321. {
  1322. set_pcvar_float(pcvars[Option:cvar], true_value_float[i])
  1323. counter = 0
  1324. break
  1325. }
  1326.  
  1327. if (true_value_float[i] == get_option_float(Option:cvar))
  1328. ok = true
  1329. }
  1330.  
  1331. if (counter == k)
  1332. {
  1333. set_pcvar_float(pcvars[Option:cvar], true_value_float[0])
  1334. }
  1335.  
  1336. }
  1337. }
  1338.  
  1339. menu_destroy(menu)
  1340. update_forward_registration()
  1341. cvar_menu(id, item / 7, cvar_menu_pos[id])
  1342. save_cfg()
  1343. return PLUGIN_HANDLED
  1344. }
  1345.  
  1346. public callback_disabled(id, menu, item)
  1347. {
  1348. return ITEM_DISABLED
  1349. }
  1350.  
  1351. public callback_enabled(id, menu, item)
  1352. {
  1353. return ITEM_ENABLED
  1354. }
  1355.  
  1356. /* -------------------------------
  1357. [Client Internet Forwards]
  1358. ------------------------------- */
  1359. public client_connect(id)
  1360. {
  1361. mode[id][GRENADE_EXPLOSIVE] = FirstEnabledMode(GRENADE_EXPLOSIVE)
  1362. mode[id][GRENADE_FLASHBANG] = FirstEnabledMode(GRENADE_FLASHBANG)
  1363. mode[id][GRENADE_SMOKEGREN] = FirstEnabledMode(GRENADE_SMOKEGREN)
  1364.  
  1365. resetCounter(id)
  1366. }
  1367.  
  1368. public client_putinserver(id)
  1369. {
  1370. // Add the bot property if user is bot
  1371. if (is_user_bot(id))
  1372. {
  1373. cl_is_bot |= (1<<id)
  1374.  
  1375. if (g_botquota != 0)
  1376. {
  1377. // Delay for private data to initialize
  1378. if (get_pcvar_num(g_botquota))
  1379. set_task(0.1, "task_botHamHooks", id)
  1380. }
  1381. }
  1382. }
  1383.  
  1384. public task_botHamHooks(id)
  1385. {
  1386. if (g_botquota == 0 || !is_user_connected(id))
  1387. return
  1388.  
  1389. // Check again for safety
  1390. if (is_user_bot(id) && get_pcvar_num(g_botquota) > 0)
  1391. {
  1392. // Post spawn fix for cz bots, since RegisterHam does not work for them
  1393. RegisterHamFromEntity(Ham_Killed, id, "fw_killed_post", 1)
  1394. RegisterHamFromEntity(Ham_Spawn, id, "fw_spawn_post", 1)
  1395. RegisterHamFromEntity(Ham_TakeDamage, id, "fw_takedamage")
  1396. RegisterHamFromEntity(Ham_Player_PreThink, id, "fw_playerprethink")
  1397.  
  1398. // Only needs to run once after ham is registed.
  1399. g_botquota = 0
  1400. }
  1401.  
  1402. // Added this if other bots that come here and don't know what to do.
  1403. fw_spawn_post(id)
  1404.  
  1405. }
  1406.  
  1407. public client_disconnect(id)
  1408. {
  1409. // Remove the bot property (doesn't matter wether it was true or false)
  1410. cl_is_bot &= ~(1<<id)
  1411.  
  1412. mode[id][GRENADE_EXPLOSIVE] = FirstEnabledMode(GRENADE_EXPLOSIVE)
  1413. mode[id][GRENADE_FLASHBANG] = FirstEnabledMode(GRENADE_FLASHBANG)
  1414. mode[id][GRENADE_SMOKEGREN] = FirstEnabledMode(GRENADE_SMOKEGREN)
  1415.  
  1416. resetCounter(id)
  1417.  
  1418. cl_nextusetime[id] = 0.0
  1419.  
  1420. cl_team[id] = CS_TEAM_UNASSIGNED
  1421. }
  1422.  
  1423. /* -------------------------------
  1424. [Forwards Registration Toggle]
  1425. ------------------------------- */
  1426. public update_forward_registration()
  1427. {
  1428. // Here we also update some global constants
  1429. cacheCvars()
  1430. g_maxplayers = get_maxplayers()
  1431.  
  1432. if (g_check_hpsystem == -1)
  1433. {
  1434. g_check_hpsystem = get_option(OPTION_MATERIAL_SYSTEM)
  1435. }
  1436. else
  1437. {
  1438. if (!is_nademodes_enabled() && get_option(OPTION_MATERIAL_SYSTEM) == 2)
  1439. {
  1440. new i=-1
  1441. while ((i = find_ent_by_class(i, "grenade")))
  1442. {
  1443. if (!is_grenade(i))
  1444. continue
  1445.  
  1446. if (entity_get_float(i, EV_FL_health))
  1447. {
  1448. entity_set_float(i, EV_FL_takedamage, DAMAGE_NO)
  1449. }
  1450. }
  1451. }
  1452.  
  1453. if (g_check_hpsystem != get_option(OPTION_MATERIAL_SYSTEM))
  1454. {
  1455. if ((get_option(OPTION_MATERIAL_SYSTEM) == 0 || get_option(OPTION_MATERIAL_SYSTEM) == 1) && g_check_hpsystem == 2)
  1456. {
  1457. new i=-1
  1458. while ((i = find_ent_by_class(i, "grenade")))
  1459. {
  1460. if (!is_grenade(i))
  1461. continue
  1462.  
  1463. if (entity_get_float(i, EV_FL_health))
  1464. {
  1465. entity_set_float(i, EV_FL_takedamage, DAMAGE_NO)
  1466. }
  1467. }
  1468. }
  1469.  
  1470. if (get_option(OPTION_MATERIAL_SYSTEM) == 2 && (g_check_hpsystem == 1 || g_check_hpsystem == 0))
  1471. {
  1472.  
  1473. new i=-1
  1474. while ((i = find_ent_by_class(i, "grenade")))
  1475. {
  1476. if (!is_grenade(i))
  1477. continue
  1478.  
  1479. if (entity_get_float(i, EV_FL_health))
  1480. {
  1481. entity_set_float(i, EV_FL_takedamage, DAMAGE_YES)
  1482. }
  1483. }
  1484. }
  1485. }
  1486.  
  1487. g_check_hpsystem = get_option(OPTION_MATERIAL_SYSTEM)
  1488. }
  1489.  
  1490. if (is_nademodes_enabled())
  1491. {
  1492. bs_forward_collection |= FWD_CMDSTART | FWD_SETMODEL | FWD_THINK | FWD_TOUCH
  1493.  
  1494. if (get_option(OPTION_DAMAGE_SYSTEM))
  1495. {
  1496. bs_forward_collection |= FWD_TAKEDAMAGE
  1497. }
  1498. else
  1499. {
  1500. bs_forward_collection &= ~FWD_TAKEDAMAGE
  1501. }
  1502.  
  1503. if (get_option(OPTION_RESOURCE_USE))
  1504. {
  1505. bs_forward_collection |= FWD_THINK_POST
  1506. }
  1507. else
  1508. {
  1509. bs_forward_collection &= ~FWD_THINK_POST
  1510. }
  1511.  
  1512. if (!get_option(OPTION_MATERIAL_SYSTEM) || get_option(OPTION_MATERIAL_SYSTEM) > 2 || get_option(OPTION_MATERIAL_SYSTEM) < 0)
  1513. {
  1514. bs_forward_collection &= ~(FWD_SEC_EXPLODE | FWD_HPSYSTEM)
  1515. }
  1516.  
  1517. if (get_option(OPTION_MATERIAL_SYSTEM) == 1)
  1518. {
  1519. bs_forward_collection |= FWD_SEC_EXPLODE
  1520. }
  1521. else
  1522. {
  1523. bs_forward_collection &= ~FWD_SEC_EXPLODE
  1524. }
  1525.  
  1526. if (get_option(OPTION_MATERIAL_SYSTEM) == 2)
  1527. {
  1528. bs_forward_collection |= FWD_HPSYSTEM
  1529. }
  1530. else
  1531. {
  1532. bs_forward_collection &= ~FWD_HPSYSTEM
  1533. }
  1534.  
  1535. if (get_option(OPTION_SUPPRESS_FITH))
  1536. {
  1537. bs_forward_collection |= FWD_MESSAGE
  1538. }
  1539. else
  1540. {
  1541. bs_forward_collection &= ~FWD_MESSAGE
  1542. }
  1543.  
  1544. }
  1545. else
  1546. {
  1547. bs_forward_collection = FWD_NONE_ACTIVE
  1548. }
  1549. }
  1550. /* -------------------------------
  1551. [Events]
  1552. ------------------------------- */
  1553. public event_armnade(id)
  1554. {
  1555. static nade
  1556.  
  1557. switch (read_data(2))
  1558. {
  1559. case CSW_HEGRENADE: nade = _:GRENADE_EXPLOSIVE
  1560. case CSW_FLASHBANG: nade = _:GRENADE_FLASHBANG
  1561. case CSW_SMOKEGRENADE: nade = _:GRENADE_SMOKEGREN
  1562. default: return PLUGIN_CONTINUE
  1563. }
  1564.  
  1565. if (!is_nademodes_enabled())
  1566. return PLUGIN_CONTINUE
  1567.  
  1568. if (get_option(OPTION_INFINITE_GRENADES + Option:nade))
  1569. {
  1570. cs_set_user_bpammo(id, NADE_WPID[NadeRace:nade], 2000)
  1571. }
  1572.  
  1573. if (!(cl_can_use_nade[NadeRace:nade] & (1<<id)))
  1574. {
  1575. client_print(id, print_center, "Mode: Not allowed to throw anymore!")
  1576. return PLUGIN_CONTINUE
  1577. }
  1578.  
  1579. if (get_option(OPTION_DISPLAY_MODE_ON_DRAW) && grenade_can_be_used(NadeRace:nade))
  1580. {
  1581. client_print(id, print_center, "Mode: %s", modetext[_:mode[id][NadeRace:nade]])
  1582. }
  1583.  
  1584. if (!is_mode_enabled(id, mode[id][NadeRace:nade], NadeRace:nade))
  1585. {
  1586. changemode(id, NadeRace:nade)
  1587. }
  1588.  
  1589. return PLUGIN_CONTINUE
  1590. }
  1591.  
  1592. public event_curweapon(id)
  1593. {
  1594. cl_weapon[id] = read_data(2)
  1595. }
  1596.  
  1597. public event_new_round()
  1598. {
  1599. static players[32], count, id
  1600. get_players(players, count)
  1601.  
  1602. for (new i=0;i<count;i++)
  1603. {
  1604. id = players[i]
  1605. resetCounter(id)
  1606. }
  1607.  
  1608. static ent
  1609.  
  1610. ent = -1
  1611. while ((ent = find_ent_by_class(ent, "grenade")))
  1612. {
  1613. if(is_grenade(ent) && get_grenade_type(ent) != NADE_NORMAL)
  1614. entity_set_int(ent, EV_INT_flags, entity_get_int(ent, EV_INT_flags) | FL_KILLME)
  1615. }
  1616.  
  1617. cacheCvars()
  1618.  
  1619. g_zombie_mod &= ~ZM_CAN_THINK // Disable thinking of ents before the first infection (this will prevent false explosions)
  1620.  
  1621. return PLUGIN_CONTINUE
  1622. }
  1623.  
  1624. /* -------------------------------
  1625. [Message Engine Forwads]
  1626. ------------------------------- */
  1627. public fith_audio(msg_id, msg_dest, entity)
  1628. {
  1629. if (!(bs_forward_collection & FWD_MESSAGE))
  1630. return PLUGIN_CONTINUE
  1631.  
  1632. // Get the string that holds the message and test it to see wether to block it or not
  1633. static string[18]
  1634. get_msg_arg_string(2, string, charsmax(string))
  1635.  
  1636. if (equal(string, "%!MRAD_FIREINHOLE")) return PLUGIN_HANDLED
  1637.  
  1638. return PLUGIN_CONTINUE
  1639. }
  1640.  
  1641. public fith_text(msg_id, msg_dest, entity)
  1642. {
  1643. if (!(bs_forward_collection & FWD_MESSAGE))
  1644. return PLUGIN_CONTINUE
  1645.  
  1646. static string[18]
  1647.  
  1648. // Get the string that holds the message and test it to see wether to block it or not
  1649. if (get_msg_args() == 5) // CS
  1650. {
  1651. get_msg_arg_string(5, string, charsmax(string))
  1652. }
  1653. else
  1654. {
  1655. if (get_msg_args() == 6) // CZ
  1656. {
  1657. get_msg_arg_string(6, string, charsmax(string))
  1658. }
  1659. else
  1660. {
  1661. return PLUGIN_CONTINUE
  1662. }
  1663. }
  1664.  
  1665. return (equal(string, "#Fire_in_the_hole")) ? PLUGIN_HANDLED : PLUGIN_CONTINUE
  1666. }
  1667.  
  1668. /* -------------------------------
  1669. [Ham & Fakemeta Forwards]
  1670. ------------------------------- */
  1671. public fw_playerprethink(id)
  1672. {
  1673. if (!is_user_connected(id) || is_user_connecting(id) || is_user_hltv(id))
  1674. return HAM_IGNORED
  1675.  
  1676. switch (cs_get_user_team(id))
  1677. {
  1678. case CS_TEAM_T: cl_team[id] = CS_TEAM_T
  1679. case CS_TEAM_CT: cl_team[id] = CS_TEAM_CT
  1680. default: return HAM_IGNORED
  1681. }
  1682.  
  1683. return HAM_IGNORED
  1684. }
  1685.  
  1686. public fw_cmdstart(id, uc_handle, seed)
  1687. {
  1688. if (!(bs_forward_collection & FWD_CMDSTART))
  1689. return FMRES_IGNORED
  1690.  
  1691. if (!(cl_is_alive & (1<<id)))
  1692. return FMRES_IGNORED
  1693.  
  1694. static bool:key[MAX_PLAYERS + 1] = {false, ...}
  1695.  
  1696. static buttons
  1697. buttons = get_uc(uc_handle, UC_Buttons)
  1698.  
  1699. if (!(buttons & IN_USE))
  1700. {
  1701. cl_nextusetime[id] = 0.0
  1702. }
  1703.  
  1704. if (buttons & IN_ATTACK)
  1705. {
  1706. switch (cl_weapon[id])
  1707. {
  1708. case CSW_HEGRENADE: if (!(cl_can_use_nade[GRENADE_EXPLOSIVE] & (1<<id))) set_uc(uc_handle, UC_Buttons, buttons & ~IN_ATTACK)
  1709. case CSW_FLASHBANG: if (!(cl_can_use_nade[GRENADE_FLASHBANG] & (1<<id))) set_uc(uc_handle, UC_Buttons, buttons & ~IN_ATTACK)
  1710. case CSW_SMOKEGRENADE: if (!(cl_can_use_nade[GRENADE_SMOKEGREN] & (1<<id))) set_uc(uc_handle, UC_Buttons, buttons & ~IN_ATTACK)
  1711. }
  1712. }
  1713.  
  1714. if (buttons & IN_ATTACK2)
  1715. {
  1716. if (!key[id])
  1717. {
  1718. switch (cl_weapon[id])
  1719. {
  1720. case CSW_HEGRENADE: if (cl_can_use_nade[GRENADE_EXPLOSIVE] & (1<<id)) changemode(id, GRENADE_EXPLOSIVE)
  1721. case CSW_FLASHBANG: if (cl_can_use_nade[GRENADE_FLASHBANG] & (1<<id)) changemode(id, GRENADE_FLASHBANG)
  1722. case CSW_SMOKEGRENADE: if (cl_can_use_nade[GRENADE_SMOKEGREN] & (1<<id)) changemode(id, GRENADE_SMOKEGREN)
  1723. }
  1724. }
  1725.  
  1726. key[id] = true
  1727. }
  1728. else
  1729. {
  1730. key[id] = false
  1731. }
  1732.  
  1733. return FMRES_IGNORED
  1734. }
  1735.  
  1736. public fw_setmodel(ent, model[])
  1737. {
  1738. if (!pev_valid(ent))
  1739. {
  1740. return FMRES_IGNORED
  1741. }
  1742.  
  1743. // Not yet thrown
  1744. if (entity_get_float(ent, EV_FL_gravity) == 0.0)
  1745. {
  1746. return FMRES_IGNORED
  1747. }
  1748.  
  1749. for (new i=0;i<3;i++)
  1750. {
  1751. if (containi(model, NADE_MODEL[i]) != -1)
  1752. {
  1753. set_pdata_int(ent, OFFSET_WEAPONID, NADE_WPID[NadeRace:i], EXTRAOFFSET_WEAPONS)
  1754.  
  1755. if (bs_forward_collection & FWD_SETMODEL)
  1756. grenade_process(pev(ent, pev_owner), ent, NadeRace:i)
  1757.  
  1758. break
  1759. }
  1760. }
  1761.  
  1762. return FMRES_IGNORED
  1763. }
  1764.  
  1765. grenade_process(id, grenade, NadeRace:nade)
  1766. {
  1767. if ((cl_is_bot & (1<<id)) && get_option(OPTION_BOT_ALLOW) && grenade_can_be_used(nade))
  1768. {
  1769. // We place the NADE_TRIP last so we can easily make another choice if it doesn't work ;)
  1770. static const NadeType:random_vec[] = {NADE_NORMAL, NADE_IMPACT, NADE_MOTION, NADE_PROXIMITY, NADE_HOMING, NADE_TRIP}
  1771. static NadeType:decision
  1772.  
  1773. decision = random_vec[random_num(0, charsmax(random_vec))]
  1774. mode[id][nade] = decision
  1775.  
  1776. if (is_mode_enabled(id, mode[id][nade], nade))
  1777. {
  1778. if (decision == NADE_TRIP)
  1779. {
  1780. static loop[4][2] = { {0, 1}, {0, -1}, {1, 1}, {1, -1} }
  1781. // Search in order: axis +X axis -X axis +Y axis -Y axis
  1782.  
  1783. new Float:origin[3], Float:end[3], Float:fdest[3], Float:calc_vector[3], Float:height, Float: minimum, Float:distance = 9999999.999, Float:fraction
  1784.  
  1785. entity_get_vector(id, EV_VEC_origin, origin)
  1786.  
  1787. xs_vec_copy(origin, end)
  1788. end[2] += 16000.0
  1789.  
  1790. engfunc(EngFunc_TraceLine, origin, end, IGNORE_MONSTERS, id, g_ptrace[TH_BOT])
  1791.  
  1792. get_tr2(g_ptrace[TH_BOT], TR_vecEndPos, end)
  1793.  
  1794. xs_vec_sub(end, origin, end)
  1795.  
  1796. height = xs_vec_len(end)
  1797.  
  1798.  
  1799. xs_vec_copy(origin, end)
  1800. end[2] -= 16000.0
  1801.  
  1802. engfunc(EngFunc_TraceLine, origin, end, IGNORE_MONSTERS, id, g_ptrace[TH_BOT])
  1803.  
  1804. get_tr2(g_ptrace[TH_BOT], TR_vecEndPos, end)
  1805.  
  1806. xs_vec_sub(end, origin, end)
  1807.  
  1808. height += xs_vec_len(end)
  1809.  
  1810. if ( height > BOT_FORCE_CROUCH_HEIGHT_CONST)
  1811. {
  1812. minimum = BOT_MIN_HEIGHT_ALLOW
  1813. }
  1814. else
  1815. {
  1816. minimum = BOT_MIN_CROUCH_HEIGHT_ALLOW
  1817. height -= BOT_MIN_CROUCH_HEIGHT_ALLOW
  1818.  
  1819. }
  1820.  
  1821. if ( height > BOT_MAX_HEIGHT_ALLOW )
  1822. {
  1823. height = BOT_MAX_HEIGHT_ALLOW
  1824. }
  1825.  
  1826. if (xs_vec_len(end) < height)
  1827. {
  1828. xs_vec_mul_scalar(end, - random_float(minimum - xs_vec_len(end),height - xs_vec_len(end)) / xs_vec_len(end), end)
  1829. xs_vec_add(end, origin, origin)
  1830. }
  1831. else
  1832. {
  1833. if (xs_vec_len(end) < height)
  1834. {
  1835. xs_vec_mul_scalar(end, (xs_vec_len(end) - random_float(minimum, height)) / xs_vec_len(end), end)
  1836. xs_vec_add(end, origin, origin)
  1837. }
  1838. else
  1839. {
  1840. xs_vec_mul_scalar(end, (xs_vec_len(end) - random_float(minimum, height)) / xs_vec_len(end), end)
  1841. xs_vec_add(end, origin, origin)
  1842. }
  1843. }
  1844.  
  1845. for(new i=0;i<4;i++)
  1846. {
  1847. // Add search direction
  1848. xs_vec_copy(origin, end)
  1849. end[loop[i][0]] = origin[loop[i][0]] + (16000.0 * float(loop[i][1]))
  1850.  
  1851. // Trace to get the entity where we can attach our nade
  1852. engfunc(EngFunc_TraceLine, origin, end, IGNORE_MONSTERS, id, g_ptrace[TH_BOT])
  1853.  
  1854. // Get fraction to see if it has hited something
  1855. get_tr2(g_ptrace[TH_BOT], TR_flFraction, fraction)
  1856.  
  1857. if (fraction < 1.0)
  1858. {
  1859. if ( (!is_attachable_surface(get_tr2(g_ptrace[TH_BOT], TR_pHit))) || get_tr2(g_ptrace[TH_BOT], TR_AllSolid) )
  1860. {
  1861. continue
  1862. }
  1863.  
  1864. // Get plane normal for the wall
  1865. get_tr2(g_ptrace[TH_BOT], TR_vecPlaneNormal, calc_vector)
  1866.  
  1867. // Check if we have a wall
  1868. if ( xs_vec_dot(calc_vector, Float:{0.0,0.0,1.0}) > BOT_WALL_MIN_COSINUS || xs_vec_dot(calc_vector, Float:{0.0,0.0,1.0}) < (-BOT_WALL_MIN_COSINUS) )
  1869. {
  1870. continue
  1871. }
  1872.  
  1873. // We use the end point for extra calculations
  1874. get_tr2(g_ptrace[TH_BOT], TR_vecEndPos, end)
  1875.  
  1876. xs_vec_sub(origin, end, calc_vector)
  1877.  
  1878. if (xs_vec_len(calc_vector) < distance)
  1879. {
  1880. distance = xs_vec_len(calc_vector)
  1881. xs_vec_normalize(calc_vector, calc_vector)
  1882. xs_vec_mul_scalar(calc_vector, 1.5, calc_vector)
  1883. xs_vec_add(end, calc_vector, end)
  1884. xs_vec_copy(end, fdest)
  1885. }
  1886. }
  1887.  
  1888. }
  1889.  
  1890. for(new i=0;i<2;i++)
  1891. {
  1892. for(new j=2;j<4;j++)
  1893. {
  1894. // Add search direction
  1895. xs_vec_copy(origin, end)
  1896.  
  1897. end[loop[i][0]] = origin[loop[i][0]] + (16000.0 * float(loop[i][1]))
  1898. end[loop[j][0]] = origin[loop[j][0]] + (16000.0 * float(loop[j][1]))
  1899.  
  1900. engfunc(EngFunc_TraceLine, origin, end, IGNORE_MONSTERS, id, g_ptrace[TH_BOT])
  1901.  
  1902. get_tr2(g_ptrace[TH_BOT], TR_flFraction, fraction)
  1903.  
  1904. if (fraction < 1.0)
  1905. {
  1906. if ( (!is_attachable_surface(get_tr2(g_ptrace[TH_BOT], TR_pHit))) || get_tr2(g_ptrace[TH_BOT], TR_AllSolid) )
  1907. {
  1908. continue
  1909. }
  1910.  
  1911. get_tr2(g_ptrace[TH_BOT], TR_vecPlaneNormal, calc_vector)
  1912.  
  1913. if ( xs_vec_dot(calc_vector, Float:{0.0,0.0,1.0}) > BOT_WALL_MIN_COSINUS || xs_vec_dot(calc_vector, Float:{0.0,0.0,1.0}) < (-BOT_WALL_MIN_COSINUS) )
  1914. {
  1915. continue
  1916. }
  1917.  
  1918. get_tr2(g_ptrace[TH_BOT], TR_vecEndPos, end)
  1919.  
  1920. xs_vec_sub(origin, end, calc_vector)
  1921.  
  1922. if (xs_vec_len(calc_vector) < distance)
  1923. {
  1924. distance = xs_vec_len(calc_vector)
  1925. xs_vec_normalize(calc_vector, calc_vector)
  1926. xs_vec_mul_scalar(calc_vector, 3.0, calc_vector)
  1927. xs_vec_add(end, calc_vector, end)
  1928. xs_vec_copy(end, fdest)
  1929. }
  1930.  
  1931. }
  1932.  
  1933. }
  1934. }
  1935.  
  1936. xs_vec_sub(fdest, origin, calc_vector)
  1937.  
  1938. if (xs_vec_len(calc_vector) <= BOT_MIN_DISTANCE_ATTACH)
  1939. {
  1940. xs_vec_normalize(calc_vector, calc_vector)
  1941. xs_vec_mul_scalar(calc_vector, 20.0, calc_vector)
  1942. entity_set_vector(grenade, EV_VEC_velocity, calc_vector)
  1943. entity_set_int(grenade, EV_INT_movetype, MOVETYPE_FLY)
  1944. entity_set_origin(grenade, fdest)
  1945. set_grenade_type(grenade, mode[id][nade])
  1946.  
  1947. }
  1948. else
  1949. {
  1950. decision = random_vec[random_num(0, charsmax(random_vec) - 1)]
  1951. mode[id][nade] = decision
  1952. set_grenade_type(grenade, mode[id][nade])
  1953. }
  1954.  
  1955. }
  1956. else
  1957. {
  1958. set_grenade_type(grenade, mode[id][nade])
  1959. }
  1960. }
  1961. else
  1962. {
  1963. mode[id][nade] = NADE_NORMAL
  1964. set_grenade_type(grenade, mode[id][nade])
  1965. }
  1966.  
  1967. return
  1968. }
  1969.  
  1970. if (is_nademodes_enabled() && is_mode_enabled(id, mode[id][nade], nade) && grenade_can_be_used(nade))
  1971. {
  1972. set_grenade_type(grenade, mode[id][nade])
  1973. }
  1974. else
  1975. {
  1976. changemode(id,nade);
  1977. set_grenade_type(grenade, mode[id][nade])
  1978. }
  1979.  
  1980. if (get_option(OPTION_RESET_MODE_ON_THROW))
  1981. {
  1982. mode[id][nade] = NADE_NORMAL
  1983. }
  1984.  
  1985. return
  1986. }
  1987.  
  1988. public fw_spawn(ent)
  1989. {
  1990. if (!pev_valid(ent))
  1991. return FMRES_IGNORED
  1992.  
  1993. static classname[32]
  1994. pev(ent, pev_classname, classname, charsmax(classname))
  1995.  
  1996. if(!TrieKeyExists(trace_attack_reg_class, classname))
  1997. {
  1998. RegisterHam(Ham_TraceAttack, classname, "fw_global_traceattack", 1)
  1999. TrieSetCell(trace_attack_reg_class, classname, true)
  2000. }
  2001.  
  2002. return FMRES_IGNORED
  2003. }
  2004.  
  2005. public fw_track_explosion(grenade)
  2006. {
  2007. if (entity_get_float(grenade, EV_FL_dmgtime) >= get_gametime())
  2008. return HAM_IGNORED
  2009.  
  2010. if (is_grenade_c4(grenade))
  2011. return HAM_IGNORED
  2012.  
  2013. new NadeType:type, owner
  2014. owner = entity_get_edict(grenade, EV_ENT_owner)
  2015. type = get_grenade_type(grenade)
  2016.  
  2017. if (!is_user_connected(owner) || is_user_connecting(owner) || cl_team[owner] == CS_TEAM_UNASSIGNED)
  2018. {
  2019. entity_set_int(grenade, EV_INT_flags, entity_get_int(grenade, EV_INT_flags) | FL_KILLME)
  2020. return HAM_IGNORED
  2021. }
  2022.  
  2023. if (_:type & NADE_DONT_COUNT)
  2024. {
  2025. return HAM_IGNORED
  2026. }
  2027. else
  2028. {
  2029. type &= ~NadeType:NADE_DONT_COUNT
  2030.  
  2031. if (get_grenade_race(grenade) == _:GRENADE_SMOKEGREN)
  2032. {
  2033. if (entity_get_float(grenade, EV_FL_animtime) == 0.0)
  2034. {
  2035. return HAM_IGNORED
  2036. }
  2037. else
  2038. {
  2039. entity_set_float(grenade, EV_FL_animtime, 0.0)
  2040. }
  2041.  
  2042. clear_line(grenade)
  2043. }
  2044. else
  2045. {
  2046. clear_line(grenade)
  2047. }
  2048.  
  2049. if (!(_:UNCOUNTABLE_NADE_MODES & (1 << (_:type + 1))))
  2050. {
  2051. cl_counter[owner][NadeRace:get_grenade_race(grenade)][type] -= 1
  2052. refresh_can_use_nade(owner, GRENADE_EXPLOSIVE)
  2053. refresh_can_use_nade(owner, GRENADE_FLASHBANG)
  2054. refresh_can_use_nade(owner, GRENADE_SMOKEGREN)
  2055. }
  2056.  
  2057. entity_set_int(grenade, EV_INT_iuser1, entity_get_int(grenade, EV_INT_iuser1) | NADE_DONT_COUNT)
  2058. }
  2059.  
  2060. if (!(bs_forward_collection & FWD_SEC_EXPLODE))
  2061. return HAM_IGNORED
  2062.  
  2063. new Float:origin[3]
  2064. new Float:range
  2065. entity_get_vector(grenade, EV_VEC_origin, origin)
  2066. range = get_option_float(OPTION_RADIUS_SEC_EXPLOSION)
  2067.  
  2068. new i
  2069. i = g_maxplayers
  2070.  
  2071. if (!get_option(OPTION_SEC_EXPLO_AFFECT) && get_grenade_race(grenade) == _:GRENADE_EXPLOSIVE)
  2072. {
  2073. while ((i = find_ent_in_sphere(i, origin, range)))
  2074. {
  2075. if (i == grenade)
  2076. continue
  2077.  
  2078. if (is_grenade(i, true))
  2079. {
  2080. if (entity_get_float(i, EV_FL_animtime) == 0.0 && get_grenade_race(i) == _:GRENADE_SMOKEGREN)
  2081. {
  2082. continue
  2083. }
  2084.  
  2085. make_explode(i)
  2086.  
  2087. if (get_grenade_race(i) == _:GRENADE_SMOKEGREN)
  2088. {
  2089. entity_set_int(i, EV_INT_flags, entity_get_int(i, EV_INT_flags) | FL_ONGROUND)
  2090. dllfunc(DLLFunc_Think, i)
  2091. }
  2092. }
  2093. }
  2094. }
  2095. else
  2096. {
  2097. static race
  2098. race = get_grenade_race(grenade)
  2099.  
  2100. while ((i = find_ent_in_sphere(i, origin, range)))
  2101. {
  2102. if (i == grenade)
  2103. continue
  2104.  
  2105. if (is_grenade(i, true))
  2106. {
  2107. if (get_grenade_race(i) == race)
  2108. {
  2109. if (entity_get_float(i, EV_FL_animtime) == 0.0 && race == _:GRENADE_SMOKEGREN)
  2110. {
  2111. continue
  2112. }
  2113.  
  2114. make_explode(i)
  2115.  
  2116. if (race == _:GRENADE_SMOKEGREN)
  2117. {
  2118. entity_set_int(i, EV_INT_flags, entity_get_int(i, EV_INT_flags) | FL_ONGROUND)
  2119. dllfunc(DLLFunc_Think, i)
  2120. }
  2121. }
  2122. }
  2123. }
  2124. }
  2125.  
  2126. return HAM_IGNORED
  2127. }
  2128.  
  2129. public fw_think(ent)
  2130. {
  2131. if (!(bs_forward_collection & FWD_THINK) || !is_valid_ent(ent))
  2132. return HAM_IGNORED
  2133.  
  2134. if (is_grenade_c4(ent))
  2135. return HAM_IGNORED
  2136.  
  2137. if ((g_zombie_mod & ZM_ZM_ACTIVE) && !(g_zombie_mod & ZM_CAN_THINK) && !(get_grenade_type(ent) == NADE_TRIP && (TRIP_ATTACHED <= get_trip_grenade_mode(ent) <= TRIP_WAITING)))
  2138. return HAM_IGNORED
  2139.  
  2140. static i, Float:origin[3], Float:porigin[3], Float:fraction, owner, bs_holds
  2141. static Float:radius, affect_owner, team_play, los
  2142.  
  2143. affect_owner = get_option(OPTION_AFFECT_OWNER)
  2144. team_play = get_option(OPTION_TEAM_PLAY)
  2145.  
  2146. entity_get_vector(ent, EV_VEC_origin, origin)
  2147.  
  2148. owner = entity_get_edict(ent, EV_ENT_owner)
  2149.  
  2150. if (!is_user_connected(owner) || is_user_connecting(owner) || cl_team[owner] == CS_TEAM_UNASSIGNED)
  2151. {
  2152. entity_set_int(ent, EV_INT_flags, entity_get_int(ent, EV_INT_flags) | FL_KILLME)
  2153. return HAM_IGNORED
  2154. }
  2155.  
  2156. switch (get_grenade_type(ent))
  2157. {
  2158. case NADE_DUD:
  2159. {
  2160. return HAM_SUPERCEDE
  2161. }
  2162.  
  2163. case NADE_NORMAL:
  2164. {
  2165. return HAM_IGNORED
  2166. }
  2167.  
  2168. case NADE_PROXIMITY:
  2169. {
  2170. if (!allow_grenade_explode(ent))
  2171. return HAM_IGNORED
  2172.  
  2173. if (entity_get_float(ent, EV_FL_fuser4) <= get_gametime())
  2174. play_sound(ent, BUTTON);
  2175.  
  2176. i = -1
  2177. radius = get_option_float(OPTION_RADIUS_PROXIMITY)
  2178. los = get_option(OPTION_PROXIMITY_LOS)
  2179.  
  2180. while ((i = find_ent_in_sphere(i, origin, radius)))
  2181. {
  2182. if (i > g_maxplayers)
  2183. {
  2184. if (get_option(OPTION_MONSTERMOD_SUPPORT))
  2185. {
  2186. if (is_ent_monster(i))
  2187. {
  2188. entity_get_vector(i, EV_VEC_origin, porigin)
  2189.  
  2190. engfunc(EngFunc_TraceLine, origin, porigin, IGNORE_MONSTERS, 0, g_ptrace[TH_LOS])
  2191. get_tr2(g_ptrace[TH_LOS], TR_flFraction, fraction)
  2192.  
  2193. if (fraction < 1.0)
  2194. continue
  2195.  
  2196. make_explode(ent)
  2197. return HAM_IGNORED
  2198. }
  2199. else
  2200. continue
  2201. }
  2202.  
  2203. return HAM_IGNORED
  2204. }
  2205.  
  2206. if (!is_player_alive(i))
  2207. continue
  2208.  
  2209. if (los)
  2210. {
  2211. entity_get_vector(i, EV_VEC_origin, porigin)
  2212.  
  2213. engfunc(EngFunc_TraceLine, origin, porigin, IGNORE_MONSTERS, 0, g_ptrace[TH_LOS])
  2214. get_tr2(g_ptrace[TH_LOS], TR_flFraction, fraction)
  2215.  
  2216. if (fraction < 1.0)
  2217. continue
  2218. }
  2219.  
  2220. if (i == owner)
  2221. {
  2222. if (affect_owner)
  2223. {
  2224. make_explode(ent)
  2225. return HAM_IGNORED
  2226. }
  2227. else
  2228. {
  2229. continue
  2230. }
  2231. }
  2232.  
  2233. if (!team_play)
  2234. {
  2235. make_explode(ent)
  2236. return HAM_IGNORED
  2237. }
  2238. else
  2239. {
  2240. if (cl_team[i] != cl_team[owner])
  2241. {
  2242. make_explode(ent)
  2243. return HAM_IGNORED
  2244. }
  2245. }
  2246. }
  2247. return HAM_IGNORED
  2248. }
  2249.  
  2250. case NADE_TRIP:
  2251. {
  2252. static hit, Float:point[3], Float:normal[3], Float:temp[3], Float:end[3], Float:fly[3]
  2253. static Float:fly_speed, Float:detect_distance, Float:arm_time
  2254.  
  2255. fly_speed = get_option_float(OPTION_TRIP_FLY_SPEED)
  2256. detect_distance = get_option_float(OPTION_TRIP_DETECT_DISTANCE)
  2257. arm_time = get_option_float(OPTION_ARM_TIME_TRIP)
  2258.  
  2259. switch (get_trip_grenade_mode(ent))
  2260. {
  2261. case TRIP_NOT_ATTACHED, TRIP_DETONATED:
  2262. {
  2263. return HAM_IGNORED
  2264. }
  2265.  
  2266. case TRIP_ATTACHED:
  2267. {
  2268. static loop[6][2] = { {2, 1}, {2, -1}, {0, 1}, {0, -1}, {1, 1}, {1, -1} }
  2269. // Search in order: +Z axis -Z axis +X axis -X axis +Y axis -Y axis
  2270.  
  2271. for (new i; i < 6; i++)
  2272. {
  2273. xs_vec_copy(origin, point)
  2274.  
  2275. point[loop[i][0]] = origin[loop[i][0]] + (2.0 * float(loop[i][1]))
  2276.  
  2277. engfunc(EngFunc_TraceLine, origin, point, IGNORE_MONSTERS, ent, g_ptrace[TH_TRIP])
  2278.  
  2279. get_tr2(g_ptrace[TH_TRIP], TR_flFraction, fraction)
  2280.  
  2281. if (fraction < 1.0)
  2282. {
  2283. hit = get_tr2(g_ptrace[TH_TRIP], TR_pHit)
  2284.  
  2285. if (!is_attachable_surface(hit))
  2286. {
  2287. set_grenade_type(ent, NADE_DUD)
  2288. return HAM_IGNORED
  2289. }
  2290.  
  2291. get_tr2(g_ptrace[TH_TRIP], TR_vecPlaneNormal, normal)
  2292.  
  2293. set_trip_grenade_attached_to(ent, hit)
  2294.  
  2295. // Calculate and store fly velocity.
  2296. xs_vec_mul_scalar(normal, fly_speed, temp)
  2297. set_trip_grenade_fly_velocity(ent, temp)
  2298.  
  2299. // Calculate and store endpoint.
  2300. xs_vec_mul_scalar(normal, detect_distance, temp)
  2301. xs_vec_add(temp, origin, end)
  2302.  
  2303. // Trace to it
  2304. engfunc(EngFunc_TraceLine, origin, end, IGNORE_MONSTERS, ent, g_ptrace[TH_TRIP])
  2305. get_tr2(g_ptrace[TH_TRIP], TR_flFraction, fraction)
  2306.  
  2307. // Final endpoint with no possible wall collision
  2308. xs_vec_mul_scalar(normal, (detect_distance * fraction), temp)
  2309. xs_vec_add(temp, origin, end)
  2310. set_trip_grenade_end_origin(ent, end)
  2311.  
  2312. xs_vec_mul_scalar(temp, 0.5, temp)
  2313. xs_vec_add(temp, origin, temp)
  2314. set_trip_grenade_middle_origin(ent, temp)
  2315.  
  2316. set_trip_grenade_arm_time(ent, arm_time)
  2317.  
  2318. play_sound(ent, DEPLOY)
  2319.  
  2320. entity_set_vector(ent, EV_VEC_velocity, Float:{0.0, 0.0, 0.0}) // Stop if from moving
  2321.  
  2322. entity_set_int(ent, EV_INT_sequence, 0) // Otherwise, grenade might make wierd motions.
  2323.  
  2324. vector_to_angle(normal, normal)
  2325.  
  2326. entity_set_vector(ent, EV_VEC_angles, normal)
  2327.  
  2328. set_trip_grenade_mode(ent, TRIP_WAITING)
  2329.  
  2330. set_task(0.1, "trip_activation", ent)
  2331.  
  2332. return HAM_IGNORED
  2333. }
  2334. }
  2335.  
  2336. // If we reach here, we have serious problems. This means that the grenade hit something like a func_breakable
  2337. // that disappeared before the scan was able to take place. Now, the grenade is floating in mid air. So we just
  2338. // kaboom it!!!
  2339.  
  2340. make_explode(ent)
  2341.  
  2342. if (NadeRace:get_grenade_race(ent) == GRENADE_SMOKEGREN)
  2343. {
  2344. entity_set_int(ent, EV_INT_flags, entity_get_int(ent, EV_INT_flags) | FL_ONGROUND)
  2345. }
  2346.  
  2347. return HAM_IGNORED
  2348. }
  2349.  
  2350. case TRIP_WAITING:
  2351. {
  2352.  
  2353. if (!is_attachable_surface(get_trip_grenade_attached_to(ent)))
  2354. {
  2355. make_explode(ent)
  2356.  
  2357. if (NadeRace:get_grenade_race(ent) == GRENADE_SMOKEGREN)
  2358. {
  2359. entity_set_int(ent, EV_INT_flags, entity_get_int(ent, EV_INT_flags) | FL_ONGROUND)
  2360. clear_line(ent)
  2361. }
  2362.  
  2363. return HAM_IGNORED
  2364. }
  2365.  
  2366. if (get_gametime() > get_trip_grenade_arm_time(ent))
  2367. {
  2368. set_trip_grenade_mode(ent, TRIP_SCANNING)
  2369. play_sound(ent, ACTIVATE)
  2370. }
  2371.  
  2372. return HAM_IGNORED
  2373. }
  2374.  
  2375. case TRIP_SCANNING:
  2376. {
  2377. if (!is_attachable_surface(get_trip_grenade_attached_to(ent)))
  2378. {
  2379. make_explode(ent)
  2380.  
  2381. if (NadeRace:get_grenade_race(ent) == GRENADE_SMOKEGREN)
  2382. {
  2383. entity_set_int(ent, EV_INT_flags, entity_get_int(ent, EV_INT_flags) | FL_ONGROUND)
  2384. clear_line(ent)
  2385. }
  2386.  
  2387. return HAM_IGNORED
  2388. }
  2389.  
  2390. get_trip_grenade_end_origin(ent, end)
  2391. engfunc(EngFunc_TraceLine, end, origin, DONT_IGNORE_MONSTERS, 0, g_ptrace[TH_TRIP])
  2392.  
  2393. static target
  2394. target = get_tr2(g_ptrace[TH_TRIP], TR_pHit)
  2395.  
  2396. if (is_player_alive(target))
  2397. {
  2398. if (owner == target)
  2399. {
  2400. if (affect_owner)
  2401. {
  2402. set_trip_grenade_mode(ent, TRIP_SHOULD_DETONATE)
  2403. entity_set_float(ent, EV_FL_nextthink, get_gametime() + 0.001)
  2404. return HAM_IGNORED
  2405. }
  2406. else
  2407. {
  2408. entity_set_float(ent, EV_FL_nextthink, get_gametime() + 0.001)
  2409. return HAM_IGNORED
  2410. }
  2411. }
  2412.  
  2413. if (!team_play)
  2414. {
  2415. set_trip_grenade_mode(ent, TRIP_SHOULD_DETONATE)
  2416. }
  2417. else
  2418. {
  2419. if (cl_team[owner] != cl_team[target])
  2420. set_trip_grenade_mode(ent, TRIP_SHOULD_DETONATE)
  2421. }
  2422. }
  2423. else if (get_option(OPTION_MONSTERMOD_SUPPORT) && is_ent_monster(target))
  2424. {
  2425. set_trip_grenade_mode(ent, TRIP_SHOULD_DETONATE)
  2426. }
  2427.  
  2428. entity_set_float(ent, EV_FL_nextthink, get_gametime() + 0.001)
  2429. return HAM_IGNORED
  2430. }
  2431.  
  2432. case TRIP_SHOULD_DETONATE:
  2433. {
  2434. static mode
  2435. mode = get_trip_grenade_react_method(ent)
  2436. set_trip_grenade_mode(ent, TRIP_DETONATED)
  2437.  
  2438. clear_line(ent)
  2439. play_sound(ent, ACTIVATE)
  2440.  
  2441. if (mode == 0)
  2442. {
  2443. cl_counter[owner][NadeRace:get_grenade_race(ent)][NADE_TRIP] -= 1
  2444.  
  2445. refresh_can_use_nade(owner, GRENADE_EXPLOSIVE)
  2446. refresh_can_use_nade(owner, GRENADE_FLASHBANG)
  2447. refresh_can_use_nade(owner, GRENADE_SMOKEGREN)
  2448.  
  2449. get_trip_grenade_fly_velocity(ent, fly)
  2450. get_trip_grenade_end_origin(ent, end)
  2451. entity_set_vector(ent, EV_VEC_velocity, fly) // Send the grenade on its way.
  2452. set_grenade_type(ent, NADE_IMPACT) // Kaboom!
  2453. }
  2454. else
  2455. {
  2456. make_explode(ent)
  2457.  
  2458. if (NadeRace:get_grenade_race(ent) == GRENADE_SMOKEGREN)
  2459. {
  2460. entity_set_int(ent, EV_INT_flags, entity_get_int(ent, EV_INT_flags) | FL_ONGROUND)
  2461. clear_line(ent)
  2462. }
  2463. }
  2464.  
  2465. return HAM_IGNORED
  2466. }
  2467. }
  2468. }
  2469.  
  2470. case NADE_MOTION:
  2471. {
  2472. if (!allow_grenade_explode(ent))
  2473. return HAM_IGNORED
  2474.  
  2475. static Float:v[3], Float:velocity
  2476.  
  2477. i = -1
  2478. bs_holds = 0
  2479. radius = get_option_float(OPTION_RADIUS_MOTION)
  2480. los = get_option(OPTION_MOTION_LOS)
  2481.  
  2482. while ((i = find_ent_in_sphere(i, origin, radius)))
  2483. {
  2484. if (i > g_maxplayers)
  2485. {
  2486. entity_set_int(ent, EV_INT_iuser2, bs_holds)
  2487.  
  2488. if (get_option(OPTION_MONSTERMOD_SUPPORT))
  2489. {
  2490. if (is_ent_monster(i))
  2491. {
  2492. entity_get_vector(i, EV_VEC_origin, porigin)
  2493.  
  2494. engfunc(EngFunc_TraceLine, origin, porigin, IGNORE_MONSTERS, 0, g_ptrace[TH_LOS])
  2495. get_tr2(g_ptrace[TH_LOS], TR_flFraction, fraction)
  2496.  
  2497. if (fraction < 1.0)
  2498. continue
  2499.  
  2500. entity_get_vector(i, EV_VEC_velocity, v)
  2501. velocity = xs_vec_len(v)
  2502.  
  2503. if (velocity > 100.0)
  2504. {
  2505. make_explode(ent)
  2506. return HAM_IGNORED
  2507. }
  2508. }
  2509. else
  2510. continue
  2511. }
  2512.  
  2513. return HAM_IGNORED
  2514. }
  2515.  
  2516. if (!is_player_alive(i))
  2517. continue
  2518.  
  2519. if (los)
  2520. {
  2521. entity_get_vector(i, EV_VEC_origin, porigin)
  2522.  
  2523. engfunc(EngFunc_TraceLine, origin, porigin, IGNORE_MONSTERS, 0, g_ptrace[TH_LOS])
  2524. get_tr2(g_ptrace[TH_LOS], TR_flFraction, fraction)
  2525.  
  2526. if (fraction < 1.0)
  2527. continue
  2528. }
  2529.  
  2530. entity_get_vector(i, EV_VEC_velocity, v)
  2531. velocity = xs_vec_len(v)
  2532.  
  2533. if (velocity > 200.0)
  2534. {
  2535. if (i == owner)
  2536. {
  2537. if (affect_owner)
  2538. {
  2539. make_explode(ent)
  2540. return HAM_IGNORED
  2541. }
  2542. else
  2543. {
  2544. bs_holds |= (1<<i)
  2545. continue
  2546. }
  2547. }
  2548. if (!team_play)
  2549. {
  2550. make_explode(ent)
  2551. return HAM_IGNORED
  2552. }
  2553. else
  2554. {
  2555. if (cl_team[i] != cl_team[owner])
  2556. {
  2557. make_explode(ent)
  2558. return HAM_IGNORED
  2559. }
  2560. }
  2561.  
  2562. bs_holds |= (1<<i)
  2563. entity_set_int(ent, EV_INT_iuser2, bs_holds)
  2564. play_sound(ent, GEIGER)
  2565. }
  2566. else if (velocity == 0.0)
  2567. {
  2568. continue
  2569. }
  2570. else
  2571. {
  2572. play_sound(ent, GEIGER)
  2573.  
  2574. // Add the player to the bitsum if he is moving
  2575. bs_holds |= (1<<i)
  2576. }
  2577.  
  2578. }
  2579.  
  2580. entity_set_int(ent, EV_INT_iuser2, bs_holds)
  2581. return HAM_IGNORED
  2582. }
  2583.  
  2584. case NADE_SATCHEL:
  2585. {
  2586. if (!allow_grenade_explode(ent))
  2587. return HAM_IGNORED
  2588.  
  2589. if (entity_get_int(owner, EV_INT_button) & IN_USE)
  2590. {
  2591. if (get_option(OPTION_SATCHEL_DELAY))
  2592. {
  2593. if (cl_nextusetime[owner] > get_gametime())
  2594. {
  2595. return HAM_IGNORED
  2596. }
  2597. else
  2598. {
  2599. cl_nextusetime[owner] = get_gametime() + DELAY_ADDED_TO_USE
  2600. }
  2601. }
  2602.  
  2603. make_explode(ent)
  2604.  
  2605. if (NadeRace:get_grenade_race(ent) == GRENADE_SMOKEGREN)
  2606. {
  2607. entity_set_int(ent, EV_INT_flags, entity_get_int(ent, EV_INT_flags) | FL_ONGROUND)
  2608. }
  2609. }
  2610.  
  2611.  
  2612. return HAM_IGNORED
  2613. }
  2614.  
  2615. case NADE_HOMING:
  2616. {
  2617. static target, Float:extravel
  2618. target = entity_get_int(ent, EV_INT_iuser2)
  2619. extravel = get_option_float(OPTION_HOMING_SPEED_ADD)
  2620.  
  2621. if (target == 0)
  2622. {
  2623. static i, Float:distance
  2624. i = -1
  2625. distance = get_option_float(OPTION_HOMING_SCAN_RANGE)
  2626.  
  2627. while ((i = find_ent_in_sphere(i, origin, distance)))
  2628. {
  2629. if (i > g_maxplayers)
  2630. {
  2631. if (get_option(OPTION_MONSTERMOD_SUPPORT))
  2632. {
  2633. if (is_ent_monster(i))
  2634. {
  2635. static Float:o[3]
  2636. entity_get_vector(i, EV_VEC_origin, o)
  2637. static Float:new_distance
  2638. new_distance = get_distance_f(o, origin)
  2639.  
  2640. if (new_distance < distance)
  2641. {
  2642. distance = new_distance
  2643. entity_set_int(ent, EV_INT_iuser2, i)
  2644. }
  2645. }
  2646. else
  2647. {
  2648. continue
  2649. }
  2650. }
  2651. else
  2652. break
  2653. }
  2654.  
  2655. if (!is_player_alive(i))
  2656. continue
  2657.  
  2658. if (i == owner)
  2659. continue
  2660.  
  2661. if ((cl_team[i] != cl_team[owner] && team_play) || !team_play)
  2662. {
  2663. static Float:o[3]
  2664. entity_get_vector(i, EV_VEC_origin, o)
  2665. static Float:new_distance
  2666. new_distance = get_distance_f(o, origin)
  2667.  
  2668. if (new_distance < distance)
  2669. {
  2670. distance = new_distance
  2671. entity_set_int(ent, EV_INT_iuser2, i)
  2672. }
  2673. }
  2674. }
  2675.  
  2676. return HAM_IGNORED
  2677. }
  2678. else if (!(cl_is_alive & (1<<target)) && target <= g_maxplayers)
  2679. {
  2680. return HAM_IGNORED
  2681. }
  2682. else if (is_in_los(ent, target))
  2683. {
  2684. //set_user_rendering(target)
  2685. static Float:velocity[3], Float:aim[3], Float:targetorigin[3], Float:velocity_normal[3], Float:aim_normal[3]
  2686.  
  2687. entity_get_vector(target, EV_VEC_origin, targetorigin)
  2688.  
  2689. entity_get_vector(ent, EV_VEC_velocity, velocity)
  2690.  
  2691. xs_vec_sub(targetorigin, origin, aim)
  2692.  
  2693. xs_vec_normalize(velocity, velocity_normal)
  2694. xs_vec_normalize(aim, aim_normal)
  2695.  
  2696. play_sound(ent, PING)
  2697.  
  2698. if (velocity_normal[0] < aim_normal[0])
  2699. {
  2700. velocity[0] += extravel
  2701. }
  2702. else if (velocity_normal[0] > aim_normal[0])
  2703. {
  2704. velocity[0] -= extravel
  2705. }
  2706.  
  2707. if (velocity_normal[1] < aim_normal[1])
  2708. {
  2709. velocity[1] += extravel
  2710. }
  2711. else if (velocity_normal[1] > aim_normal[1])
  2712. {
  2713. velocity[1] -= extravel
  2714. }
  2715.  
  2716. if (velocity_normal[2] < aim_normal[2])
  2717. {
  2718. velocity[2] += extravel
  2719. }
  2720. else if (velocity_normal[2] > aim_normal[2])
  2721. {
  2722. velocity[2] -= extravel
  2723. }
  2724.  
  2725. velocity[2] += 5.0
  2726.  
  2727. entity_set_vector(ent, EV_VEC_velocity, velocity)
  2728.  
  2729. // When within blasting range, make our homing grenade think much much faster; results in better homing.
  2730. if (get_distance_f(origin, targetorigin) < get_option_float(OPTION_HOMING_SUPER_RANGE))
  2731. {
  2732. entity_set_float(ent, EV_FL_nextthink, (get_gametime() + 0.05))
  2733. }
  2734. else
  2735. {
  2736. entity_set_float(ent, EV_FL_nextthink, (get_gametime() + 0.15))
  2737. }
  2738. }
  2739.  
  2740. return HAM_IGNORED
  2741. }
  2742. }
  2743.  
  2744. return HAM_IGNORED
  2745. }
  2746.  
  2747. public trip_activation(ent)
  2748. {
  2749. if (is_valid_ent(ent))
  2750. play_sound(ent, CHARGE)
  2751. }
  2752.  
  2753. public fw_think_post(ent)
  2754. {
  2755. if (!is_valid_ent(ent))
  2756. return HAM_IGNORED
  2757.  
  2758. if (is_grenade_c4(ent))
  2759. return HAM_IGNORED
  2760.  
  2761. static owner, Float:origin[3], Float:gametime, bs_affected
  2762.  
  2763. gametime = get_gametime()
  2764.  
  2765. if (entity_get_float(ent, EV_FL_dmgtime) <= gametime)
  2766. return HAM_IGNORED
  2767.  
  2768. entity_get_vector(ent, EV_VEC_origin, origin)
  2769. owner = entity_get_edict(ent, EV_ENT_owner)
  2770.  
  2771. if (!is_user_connected(owner) || is_user_connecting(owner) || cl_team[owner] == CS_TEAM_UNASSIGNED)
  2772. {
  2773. entity_set_int(ent, EV_INT_flags, entity_get_int(ent, EV_INT_flags) | FL_KILLME)
  2774. return HAM_IGNORED
  2775. }
  2776.  
  2777. if (!(bs_forward_collection & FWD_THINK_POST))
  2778. {
  2779. switch (get_grenade_type(ent))
  2780. {
  2781. case NADE_PROXIMITY:
  2782. {
  2783. // We do this for the sound of the entity
  2784. if (entity_get_float(ent, EV_FL_fuser4) <= gametime)
  2785. entity_set_float(ent, EV_FL_fuser4, gametime + 2.0)
  2786. }
  2787. case NADE_TRIP:
  2788. {
  2789. // We do this in order to make the trip nades be 10000% more accurate!
  2790. entity_set_float(ent, EV_FL_nextthink, get_gametime() + 0.001)
  2791. }
  2792. }
  2793.  
  2794. return HAM_IGNORED
  2795. }
  2796.  
  2797. bs_affected = 0
  2798.  
  2799. if (get_option(OPTION_RESOURCE_USE) != 3)
  2800. {
  2801. bs_affected = ~0
  2802. }
  2803. else
  2804. {
  2805. static team_play, affect_owner
  2806. team_play = get_option(OPTION_TEAM_PLAY)
  2807. affect_owner = get_option(OPTION_AFFECT_OWNER)
  2808.  
  2809. if (!team_play)
  2810. {
  2811. bs_affected = affect_owner ? ~0 : ~(1<<owner)
  2812. }
  2813. else
  2814. {
  2815. for (new i=1;i<=g_maxplayers;i++)
  2816. {
  2817. if (!is_user_connected(i))
  2818. continue
  2819.  
  2820. if (affect_owner & i == owner)
  2821. bs_affected |= (1<<i)
  2822.  
  2823. if (team_play && cs_get_user_team(i) != cs_get_user_team(owner))
  2824. bs_affected |= (1<<i)
  2825. }
  2826. }
  2827. }
  2828.  
  2829. switch (get_grenade_type(ent))
  2830. {
  2831. case NADE_PROXIMITY:
  2832. {
  2833. if (!allow_grenade_explode(ent))
  2834. return HAM_IGNORED
  2835.  
  2836. if (entity_get_float(ent, EV_FL_fuser4) <= gametime)
  2837. {
  2838. entity_set_float(ent, EV_FL_fuser4, gametime + 2.0)
  2839.  
  2840. if (entity_get_int(ent, EV_INT_flags) & FL_ONGROUND)
  2841. {
  2842. if (!get_option(OPTION_TEAM_PLAY) || ((g_zombie_mod & ZM_ZM_ACTIVE) && !(g_zombie_mod & ZM_CAN_THINK)))
  2843. {
  2844. if (get_option(OPTION_RESOURCE_USE) == 1)
  2845. {
  2846. show_ring(origin, get_option_float(OPTION_RADIUS_PROXIMITY) * RING_SIZE_CONSTANT_PROXIMITY, 5)
  2847. }
  2848. else
  2849. {
  2850. static i
  2851. i = -1
  2852.  
  2853. while ( (i = find_ent_in_sphere(i, origin, SMART_RADIUS_RING_SHOW)) )
  2854. {
  2855. if (i > g_maxplayers)
  2856. break
  2857.  
  2858. if (!(cl_is_alive & (1<<i)) || (cl_is_bot & (1<<i)))
  2859. continue
  2860.  
  2861. if (bs_affected & (1<<i))
  2862. show_ring(origin, get_option_float(OPTION_RADIUS_PROXIMITY) * RING_SIZE_CONSTANT_PROXIMITY, 5, _, _, _, i)
  2863. }
  2864. }
  2865. }
  2866. else
  2867. {
  2868. switch (cl_team[owner])
  2869. {
  2870. case CS_TEAM_T:
  2871. {
  2872. if (get_option(OPTION_RESOURCE_USE) == 1)
  2873. {
  2874. show_ring(origin, get_option_float(OPTION_RADIUS_PROXIMITY) * RING_SIZE_CONSTANT_PROXIMITY, 5, TEAMTE_RGB_R_COLOR, TEAMTE_RGB_G_COLOR, TEAMTE_RGB_B_COLOR)
  2875. }
  2876. else
  2877. {
  2878. static i
  2879. i = -1
  2880.  
  2881. while ( (i = find_ent_in_sphere(i, origin, SMART_RADIUS_RING_SHOW)) )
  2882. {
  2883. if (i > g_maxplayers)
  2884. break
  2885.  
  2886. if (!(cl_is_alive & (1<<i)) || (cl_is_bot & (1<<i)))
  2887. continue
  2888.  
  2889. if (bs_affected & (1<<i))
  2890. show_ring(origin, get_option_float(OPTION_RADIUS_PROXIMITY) * RING_SIZE_CONSTANT_PROXIMITY, 5, TEAMTE_RGB_R_COLOR, TEAMTE_RGB_G_COLOR, TEAMTE_RGB_B_COLOR, i)
  2891. }
  2892. }
  2893.  
  2894. }
  2895. case CS_TEAM_CT:
  2896. {
  2897. if (get_option(OPTION_RESOURCE_USE) == 1)
  2898. {
  2899. show_ring(origin, get_option_float(OPTION_RADIUS_PROXIMITY) * RING_SIZE_CONSTANT_PROXIMITY, 5, TEAMCT_RGB_R_COLOR, TEAMCT_RGB_G_COLOR, TEAMCT_RGB_B_COLOR)
  2900. }
  2901. else
  2902. {
  2903. static i
  2904. i = -1
  2905.  
  2906. while ( (i = find_ent_in_sphere(i, origin, SMART_RADIUS_RING_SHOW)) )
  2907. {
  2908. if (i > g_maxplayers)
  2909. break
  2910.  
  2911. if (!(cl_is_alive & (1<<i)) || (cl_is_bot & (1<<i)))
  2912. continue
  2913.  
  2914. if (bs_affected & (1<<i))
  2915. show_ring(origin, get_option_float(OPTION_RADIUS_PROXIMITY) * RING_SIZE_CONSTANT_PROXIMITY, 5, TEAMCT_RGB_R_COLOR, TEAMCT_RGB_G_COLOR, TEAMCT_RGB_B_COLOR, i)
  2916. }
  2917. }
  2918. }
  2919. }
  2920. }
  2921. }
  2922. }
  2923. }
  2924.  
  2925. case NADE_MOTION:
  2926. {
  2927. static bs_holds
  2928. bs_holds = entity_get_int(ent, EV_INT_iuser2)
  2929.  
  2930. if (bs_holds && entity_get_float(ent, EV_FL_fuser4) <= gametime)
  2931. {
  2932. entity_set_float(ent, EV_FL_fuser4, get_gametime() + 0.1)
  2933.  
  2934. if (!get_option(OPTION_TEAM_PLAY) || ((g_zombie_mod & ZM_ZM_ACTIVE) && !(g_zombie_mod & ZM_CAN_THINK)))
  2935. {
  2936. if ( get_option(OPTION_RESOURCE_USE) == 1)
  2937. {
  2938. show_ring(origin, get_option_float(OPTION_RADIUS_MOTION) * RING_SIZE_CONSTANT_MOTION, 1)
  2939. }
  2940. else
  2941. {
  2942. for (new i=1;i<=g_maxplayers;i++)
  2943. {
  2944. if ((bs_holds & (1<<i)) && (bs_affected & (1<<i)))
  2945. show_ring(origin, get_option_float(OPTION_RADIUS_MOTION) * RING_SIZE_CONSTANT_MOTION, 1, _, _, _, i)
  2946. }
  2947. }
  2948. }
  2949. else
  2950. {
  2951. switch (cl_team[owner])
  2952. {
  2953. case CS_TEAM_T:
  2954. {
  2955. if ( get_option(OPTION_RESOURCE_USE) == 1 )
  2956. {
  2957. show_ring(origin, get_option_float(OPTION_RADIUS_MOTION) * RING_SIZE_CONSTANT_MOTION, 1, TEAMTE_RGB_R_COLOR, TEAMTE_RGB_G_COLOR, TEAMTE_RGB_B_COLOR)
  2958. }
  2959. else
  2960. {
  2961. for (new i=1;i<=g_maxplayers;i++)
  2962. {
  2963. if ((bs_holds & (1<<i)) && (bs_affected & (1<<i)))
  2964. show_ring(origin, get_option_float(OPTION_RADIUS_MOTION) * RING_SIZE_CONSTANT_MOTION, 1, TEAMTE_RGB_R_COLOR, TEAMTE_RGB_G_COLOR, TEAMTE_RGB_B_COLOR, i)
  2965. }
  2966. }
  2967. }
  2968. case CS_TEAM_CT:
  2969. {
  2970. if ( get_option(OPTION_RESOURCE_USE) == 1 )
  2971. {
  2972. show_ring(origin, get_option_float(OPTION_RADIUS_MOTION) * RING_SIZE_CONSTANT_MOTION, 1, TEAMCT_RGB_R_COLOR, TEAMCT_RGB_G_COLOR, TEAMCT_RGB_B_COLOR)
  2973. }
  2974. else
  2975. {
  2976. for (new i=1;i<=g_maxplayers;i++)
  2977. {
  2978. if ((bs_holds & (1<<i)) && (bs_affected & (1<<i)))
  2979. show_ring(origin, get_option_float(OPTION_RADIUS_MOTION) * RING_SIZE_CONSTANT_MOTION, 1, TEAMCT_RGB_R_COLOR, TEAMCT_RGB_G_COLOR, TEAMCT_RGB_B_COLOR, i)
  2980. }
  2981. }
  2982. }
  2983. default:
  2984. {
  2985. if ( get_option(OPTION_RESOURCE_USE) == 1 )
  2986. {
  2987. show_ring(origin, get_option_float(OPTION_RADIUS_MOTION) * RING_SIZE_CONSTANT_MOTION, 1, _, _, _)
  2988. }
  2989. else
  2990. {
  2991. for (new i=1;i<=g_maxplayers;i++)
  2992. {
  2993. if ((bs_holds & (1<<i)) && (bs_affected & (1<<i)))
  2994. show_ring(origin, get_option_float(OPTION_RADIUS_MOTION) * RING_SIZE_CONSTANT_MOTION, 1, _, _, _, i)
  2995. }
  2996. }
  2997. }
  2998. }
  2999. }
  3000. }
  3001. }
  3002.  
  3003. case NADE_TRIP:
  3004. {
  3005. if (get_trip_grenade_mode(ent) != TRIP_SCANNING)
  3006. return HAM_IGNORED
  3007.  
  3008. // We do this in order to make the trip nades be 10000% more accurate!
  3009. entity_set_float(ent, EV_FL_nextthink, get_gametime() + 0.001)
  3010.  
  3011. if (entity_get_float(ent, EV_FL_fuser4) <= gametime)
  3012. {
  3013. new Float:end[3]
  3014. get_trip_grenade_end_origin(ent, end)
  3015.  
  3016. if (get_option(OPTION_RESOURCE_USE) == 1)
  3017. {
  3018. if (!get_option(OPTION_TEAM_PLAY) || ((g_zombie_mod & ZM_ZM_ACTIVE) && !(g_zombie_mod & ZM_CAN_THINK)))
  3019. {
  3020. draw_line_from_entity_broadcast(ent, end, 5, _, _, _)
  3021. }
  3022. else
  3023. {
  3024. switch (cl_team[owner])
  3025. {
  3026. case CS_TEAM_T:
  3027. {
  3028. draw_line_from_entity_broadcast(ent, end, 5, TEAMTE_RGB_R_COLOR, TEAMTE_RGB_G_COLOR, TEAMTE_RGB_B_COLOR)
  3029. }
  3030. case CS_TEAM_CT:
  3031. {
  3032. draw_line_from_entity_broadcast(ent, end, 5, TEAMCT_RGB_R_COLOR, TEAMCT_RGB_G_COLOR, TEAMCT_RGB_B_COLOR)
  3033. }
  3034. default:
  3035. {
  3036. draw_line_from_entity_broadcast(ent, end, 5, _, _, _)
  3037. }
  3038. }
  3039. }
  3040.  
  3041. entity_set_float(ent, EV_FL_fuser4, gametime + 0.5)
  3042. return HAM_IGNORED
  3043. }
  3044.  
  3045. static Float:first[3], Float:second[3], Float:porigin[3], Float:anglefraction, Float:third[3], Float:fourth[3]
  3046.  
  3047. xs_vec_sub(origin,end,first)
  3048.  
  3049. anglefraction = 1.0 - calc_cone_angle_from_distance(xs_vec_len(first))
  3050.  
  3051. if (xs_vec_len(first) <= SMART_DISTANCE_LINE_PVS)
  3052. {
  3053. get_trip_grenade_middle_origin(ent, first)
  3054.  
  3055. if (!get_option(OPTION_TEAM_PLAY) || ((g_zombie_mod & ZM_ZM_ACTIVE) && !(g_zombie_mod & ZM_CAN_THINK)))
  3056. {
  3057. draw_line_from_entity(ent, end, 5, _, _, _, 0, first)
  3058. }
  3059. else
  3060. {
  3061. switch (cl_team[owner])
  3062. {
  3063. case CS_TEAM_T:
  3064. {
  3065. draw_line_from_entity(ent, end, 5, TEAMTE_RGB_R_COLOR, TEAMTE_RGB_G_COLOR, TEAMTE_RGB_B_COLOR, 0, first)
  3066. }
  3067. case CS_TEAM_CT:
  3068. {
  3069. draw_line_from_entity(ent, end, 5, TEAMCT_RGB_R_COLOR, TEAMCT_RGB_G_COLOR, TEAMCT_RGB_B_COLOR, 0, first)
  3070. }
  3071. default:
  3072. {
  3073. draw_line_from_entity(ent, end, 5, _, _, _, 0, first)
  3074. }
  3075. }
  3076. }
  3077.  
  3078. entity_set_float(ent, EV_FL_fuser4, gametime + 0.5)
  3079. return HAM_IGNORED
  3080. }
  3081.  
  3082. xs_vec_mul_scalar(first,EXTRALENGTH_VECTOR / xs_vec_len(first),first)
  3083. xs_vec_sub(end,first,fourth)
  3084. xs_vec_add(origin,first,first)
  3085.  
  3086. static players[32],num,id
  3087. get_players(players,num,"ac")
  3088.  
  3089. for (new i=0;i<num;i++)
  3090. {
  3091. id = players[i]
  3092. entity_get_vector(id, EV_VEC_origin, porigin)
  3093.  
  3094. xs_vec_sub(porigin, fourth, second)
  3095. xs_vec_normalize(second, second)
  3096.  
  3097. xs_vec_sub(porigin, first, third)
  3098. xs_vec_normalize(third, third)
  3099.  
  3100. xs_vec_sub(first,fourth,first)
  3101. xs_vec_normalize(first,first)
  3102.  
  3103. if ( xs_vec_dot(first,second) <= CONE_DROP_ANGLE_COSINUS || (0 - xs_vec_dot(first,third)) <= CONE_DROP_ANGLE_COSINUS )
  3104. continue
  3105.  
  3106. if (bs_affected & (1<<id))
  3107. {
  3108. if ( xs_vec_dot(first, second) >= anglefraction )
  3109. {
  3110. if (!get_option(OPTION_TEAM_PLAY) || ((g_zombie_mod & ZM_ZM_ACTIVE) && !(g_zombie_mod & ZM_CAN_THINK)))
  3111. {
  3112. draw_line_from_entity(ent, end, 5, _, _, _, id)
  3113. }
  3114. else
  3115. {
  3116. switch (cl_team[owner])
  3117. {
  3118. case CS_TEAM_T:
  3119. {
  3120. draw_line_from_entity(ent, end, 5, TEAMTE_RGB_R_COLOR, TEAMTE_RGB_G_COLOR, TEAMTE_RGB_B_COLOR, id)
  3121. }
  3122. case CS_TEAM_CT:
  3123. {
  3124. draw_line_from_entity(ent, end, 5, TEAMCT_RGB_R_COLOR, TEAMCT_RGB_G_COLOR, TEAMCT_RGB_B_COLOR, id)
  3125. }
  3126. default:
  3127. {
  3128. draw_line_from_entity(ent, end, 5, _, _, _, id)
  3129. }
  3130. }
  3131. }
  3132. }
  3133. else
  3134. {
  3135. if ( (0 - xs_vec_dot(first, third)) >= anglefraction )
  3136. {
  3137. if (!get_option(OPTION_TEAM_PLAY) || ((g_zombie_mod & ZM_ZM_ACTIVE) && !(g_zombie_mod & ZM_CAN_THINK)))
  3138. {
  3139. draw_line_from_entity(ent, end, 5, _, _, _, id)
  3140. }
  3141. else if (bs_affected & (1<<id))
  3142. {
  3143. switch (cl_team[owner])
  3144. {
  3145. case CS_TEAM_T:
  3146. {
  3147. draw_line_from_entity(ent, end, 5, TEAMTE_RGB_R_COLOR, TEAMTE_RGB_G_COLOR, TEAMTE_RGB_B_COLOR, id)
  3148. }
  3149. case CS_TEAM_CT:
  3150. {
  3151. draw_line_from_entity(ent, end, 5, TEAMCT_RGB_R_COLOR, TEAMCT_RGB_G_COLOR, TEAMCT_RGB_B_COLOR, id)
  3152. }
  3153. default:
  3154. {
  3155. draw_line_from_entity(ent, end, 5, _, _, _, id)
  3156. }
  3157. }
  3158. }
  3159. }
  3160. }
  3161. }
  3162. }
  3163.  
  3164. entity_set_float(ent, EV_FL_fuser4, gametime + 0.5)
  3165.  
  3166. }
  3167. }
  3168.  
  3169. default : return HAM_IGNORED
  3170. }
  3171.  
  3172. return HAM_IGNORED
  3173. }
  3174.  
  3175. public fw_touch(toucher, touched)
  3176. {
  3177. if (!(bs_forward_collection & FWD_TOUCH))
  3178. return HAM_IGNORED
  3179.  
  3180. switch (get_grenade_type(toucher))
  3181. {
  3182. case NADE_IMPACT:
  3183. {
  3184. if (is_solid(touched))
  3185. {
  3186. make_explode(toucher)
  3187.  
  3188. entity_set_float(toucher, EV_FL_nextthink, get_gametime() + 0.001)
  3189.  
  3190. if (NadeRace:get_grenade_race(toucher) == GRENADE_SMOKEGREN)
  3191. {
  3192. entity_set_int(toucher, EV_INT_flags, entity_get_int(toucher, EV_INT_flags) | FL_ONGROUND)
  3193. }
  3194. }
  3195. }
  3196.  
  3197. case NADE_TRIP:
  3198. {
  3199. static classname[10]
  3200. entity_get_string(touched, EV_SZ_classname, classname, charsmax(classname))
  3201.  
  3202. if (get_trip_grenade_mode(toucher) > TRIP_NOT_ATTACHED || is_user_connected(touched))
  3203. {
  3204. return HAM_IGNORED
  3205. }
  3206. else
  3207. {
  3208. if (is_solid(touched))
  3209. {
  3210. entity_set_int(toucher, EV_INT_movetype, MOVETYPE_NONE)
  3211. set_trip_grenade_mode(toucher, TRIP_ATTACHED)
  3212. return (containi(classname, "door") != -1) ? HAM_SUPERCEDE : HAM_IGNORED
  3213. }
  3214. }
  3215. }
  3216. }
  3217.  
  3218. return HAM_IGNORED
  3219. }
  3220.  
  3221. public fw_spawn_post(id)
  3222. {
  3223. if (is_user_alive(id))
  3224. {
  3225. cl_is_alive |= (1<<id)
  3226. }
  3227. else
  3228. {
  3229. cl_is_alive &= ~(1<<id)
  3230. }
  3231.  
  3232. return HAM_IGNORED
  3233. }
  3234.  
  3235. public fw_killed_post(id, attacker, gib)
  3236. {
  3237. if (is_user_alive(id))
  3238. {
  3239. cl_is_alive |= (1<<id)
  3240. }
  3241. else
  3242. {
  3243. cl_is_alive &= ~(1<<id)
  3244. }
  3245.  
  3246. if (!get_option(OPTION_REMOVE_IF_DIES))
  3247. return HAM_IGNORED
  3248.  
  3249. mode[id][GRENADE_EXPLOSIVE] = FirstEnabledMode(GRENADE_EXPLOSIVE)
  3250. mode[id][GRENADE_FLASHBANG] = FirstEnabledMode(GRENADE_FLASHBANG)
  3251. mode[id][GRENADE_SMOKEGREN] = FirstEnabledMode(GRENADE_SMOKEGREN)
  3252.  
  3253. resetCounter(id)
  3254. removeNades(id)
  3255.  
  3256.  
  3257. return HAM_IGNORED
  3258. }
  3259.  
  3260. public fw_takedamage(victim, inflictor, attacker, Float:damage, damagebits)
  3261. {
  3262. if (!(bs_forward_collection & FWD_TAKEDAMAGE))
  3263. return HAM_IGNORED
  3264.  
  3265. static aclassname[7], iclassname[8]
  3266.  
  3267. entity_get_string(attacker, EV_SZ_classname, aclassname, charsmax(aclassname))
  3268. entity_get_string(inflictor, EV_SZ_classname, iclassname, charsmax(iclassname))
  3269.  
  3270. if ((damagebits & DMG_BLAST))
  3271. return HAM_IGNORED
  3272.  
  3273. if (!equal(aclassname, "player") || !equal(iclassname, "grenade"))
  3274. return HAM_IGNORED
  3275.  
  3276. if (attacker == victim)
  3277. {
  3278. damage *= (get_option_float(OPTION_DMG_SELF) / 100.0)
  3279. }
  3280. else
  3281. {
  3282. if (cl_team[attacker] == cl_team[victim] && get_option(OPTION_FRIENDLY_FIRE))
  3283. {
  3284. damage *= 0.02 * get_option_float(OPTION_DMG_TEAMMATES)
  3285. }
  3286. }
  3287.  
  3288. static Float:origin[3], Float:user_origin[3], Float:fraction
  3289.  
  3290. entity_get_vector(victim, EV_VEC_origin, user_origin)
  3291. entity_get_vector(inflictor, EV_VEC_origin, origin)
  3292. origin[2] += 2.0
  3293. engfunc(EngFunc_TraceLine, user_origin, origin, IGNORE_MONSTERS, victim, g_ptrace[TH_DMG])
  3294.  
  3295. get_tr2(g_ptrace[TH_DMG], TR_flFraction, fraction)
  3296.  
  3297. if (fraction < 1.0)
  3298. {
  3299. damage *= (get_option_float(OPTION_DMG_THROUGH_WALL) / 100.0)
  3300. }
  3301.  
  3302. if ( get_option(OPTION_DAMAGE_SYSTEM) == 1)
  3303. {
  3304. damage *= get_option_float(OPTION_DMG_NORMAL)
  3305. }
  3306. else
  3307. {
  3308. new type = _:get_grenade_type(inflictor)
  3309. type &= ~NADE_DONT_COUNT
  3310.  
  3311. switch ( type )
  3312. {
  3313. case NADE_NORMAL:
  3314. {
  3315. damage *= get_option_float(OPTION_DMG_NORMAL)
  3316. }
  3317.  
  3318. case NADE_PROXIMITY:
  3319. {
  3320. damage *= get_option_float(OPTION_DMG_PROXIMITY)
  3321. }
  3322.  
  3323. case NADE_IMPACT:
  3324. {
  3325. damage *= get_option_float(OPTION_DMG_IMPACT)
  3326. }
  3327.  
  3328. case NADE_TRIP:
  3329. {
  3330. damage *= get_option_float(OPTION_DMG_TRIP)
  3331. }
  3332.  
  3333. case NADE_MOTION:
  3334. {
  3335. damage *= get_option_float(OPTION_DMG_MOTION)
  3336. }
  3337.  
  3338. case NADE_SATCHEL:
  3339. {
  3340. damage *= get_option_float(OPTION_DMG_SATCHEL)
  3341. }
  3342.  
  3343. case NADE_HOMING:
  3344. {
  3345. damage *= get_option_float(OPTION_DMG_HOMING)
  3346. }
  3347.  
  3348. default:
  3349. {
  3350. damage *= get_option_float(OPTION_DMG_NORMAL)
  3351. }
  3352. }
  3353. }
  3354.  
  3355. SetHamParamFloat(4, damage)
  3356.  
  3357. return HAM_HANDLED
  3358. }
  3359.  
  3360. public fw_monster_takedamage(victim, inflictor, attacker, Float:damage, damagebits)
  3361. {
  3362. if (!(bs_forward_collection & FWD_TAKEDAMAGE) || !get_option(OPTION_MONSTERMOD_SUPPORT))
  3363. return HAM_IGNORED
  3364.  
  3365. static aclassname[7], iclassname[8]
  3366.  
  3367. entity_get_string(attacker, EV_SZ_classname, aclassname, charsmax(aclassname))
  3368. entity_get_string(inflictor, EV_SZ_classname, iclassname, charsmax(iclassname))
  3369.  
  3370. if ((damagebits & DMG_BLAST))
  3371. return HAM_IGNORED
  3372.  
  3373. if (!equal(aclassname, "player") || !equal(iclassname, "grenade"))
  3374. return HAM_IGNORED
  3375.  
  3376. static Float:origin[3], Float:user_origin[3], Float:fraction
  3377.  
  3378. entity_get_vector(victim, EV_VEC_origin, user_origin)
  3379. entity_get_vector(inflictor, EV_VEC_origin, origin)
  3380. origin[2] += 2.0
  3381. engfunc(EngFunc_TraceLine, user_origin, origin, IGNORE_MONSTERS, victim, g_ptrace[TH_DMG])
  3382.  
  3383. get_tr2(g_ptrace[TH_DMG], TR_flFraction, fraction)
  3384.  
  3385. if (fraction < 1.0)
  3386. {
  3387. damage *= (get_option_float(OPTION_DMG_THROUGH_WALL) / 100.0)
  3388. }
  3389.  
  3390. if ( get_option(OPTION_DAMAGE_SYSTEM) == 1)
  3391. {
  3392. damage *= get_option_float(OPTION_DMG_NORMAL)
  3393. }
  3394. else
  3395. {
  3396. new type = _:get_grenade_type(inflictor)
  3397. type &= ~NADE_DONT_COUNT
  3398.  
  3399. switch ( type )
  3400. {
  3401. case NADE_NORMAL:
  3402. {
  3403. damage *= get_option_float(OPTION_DMG_NORMAL)
  3404. }
  3405.  
  3406. case NADE_PROXIMITY:
  3407. {
  3408. damage *= get_option_float(OPTION_DMG_PROXIMITY)
  3409. }
  3410.  
  3411. case NADE_IMPACT:
  3412. {
  3413. damage *= get_option_float(OPTION_DMG_IMPACT)
  3414. }
  3415.  
  3416. case NADE_TRIP:
  3417. {
  3418. damage *= get_option_float(OPTION_DMG_TRIP)
  3419. }
  3420.  
  3421. case NADE_MOTION:
  3422. {
  3423. damage *= get_option_float(OPTION_DMG_MOTION)
  3424. }
  3425.  
  3426. case NADE_SATCHEL:
  3427. {
  3428. damage *= get_option_float(OPTION_DMG_SATCHEL)
  3429. }
  3430.  
  3431. case NADE_HOMING:
  3432. {
  3433. damage *= get_option_float(OPTION_DMG_HOMING)
  3434. }
  3435.  
  3436. default:
  3437. {
  3438. damage *= get_option_float(OPTION_DMG_NORMAL)
  3439. }
  3440. }
  3441. }
  3442.  
  3443. SetHamParamFloat(4, damage)
  3444.  
  3445. return HAM_HANDLED
  3446. }
  3447.  
  3448. public fw_grenade_takedamage(grenade, inflictor, attacker, Float:damage, bits)
  3449. {
  3450. if (!(bs_forward_collection & FWD_HPSYSTEM))
  3451. return HAM_IGNORED
  3452.  
  3453. if (inflictor == grenade)
  3454. {
  3455. SetHamReturnInteger(0)
  3456. return HAM_SUPERCEDE
  3457. }
  3458.  
  3459. new Float:health, Float:origin[3], ok = false
  3460. health = entity_get_float(grenade, EV_FL_health)
  3461.  
  3462. if (!(1 <= attacker <= g_maxplayers))
  3463. return HAM_SUPERCEDE
  3464.  
  3465. if ((entity_get_int(grenade, EV_INT_flags) & FL_GODMODE) || (entity_get_float(grenade, EV_FL_takedamage) == DAMAGE_NO))
  3466. return HAM_SUPERCEDE
  3467.  
  3468. entity_get_vector(grenade, EV_VEC_origin, origin)
  3469.  
  3470. if (entity_get_edict(grenade, EV_ENT_owner) != attacker && cl_team[entity_get_edict(grenade, EV_ENT_owner)] == cl_team[attacker])
  3471. {
  3472. damage *= get_option_float(OPTION_HITPOINT_FF) / 100.0
  3473. ok = true
  3474. }
  3475.  
  3476. new string[8]
  3477. entity_get_string(inflictor, EV_SZ_classname, string, charsmax(string))
  3478.  
  3479. if (equal(string,"grenade"))
  3480. {
  3481. damage *= get_option_float(OPTION_HITPOINT_INTER_DMG) / 100.0
  3482. ok = true
  3483. }
  3484.  
  3485. play_sound2(grenade, SOUND_HIT[random_num(0,4)])
  3486.  
  3487. if (floatcmp(damage,health) != -1)
  3488. {
  3489. static NadeType:type, owner
  3490. owner = entity_get_edict(grenade, EV_ENT_owner)
  3491. type = get_grenade_type(grenade)
  3492. type &= ~NadeType:NADE_DONT_COUNT
  3493.  
  3494. if (get_option(OPTION_HITPOINT_DEATH))
  3495. {
  3496. make_explode(grenade)
  3497.  
  3498. if (NadeRace:get_grenade_race(grenade) == GRENADE_SMOKEGREN)
  3499. {
  3500. entity_set_int(grenade, EV_INT_flags, entity_get_int(grenade, EV_INT_flags) | FL_ONGROUND)
  3501. dllfunc(DLLFunc_Think, grenade)
  3502. clear_line(grenade)
  3503. }
  3504.  
  3505. return HAM_SUPERCEDE
  3506. }
  3507.  
  3508. entity_set_int(grenade, EV_INT_flags, entity_get_int(grenade, EV_INT_flags) | FL_KILLME)
  3509.  
  3510. if (!(_:UNCOUNTABLE_NADE_MODES & (1 << (_:type + 1))))
  3511. {
  3512. cl_counter[owner][NadeRace:get_grenade_race(grenade)][type] -= 1
  3513. refresh_can_use_nade(owner, GRENADE_EXPLOSIVE)
  3514. refresh_can_use_nade(owner, GRENADE_FLASHBANG)
  3515. refresh_can_use_nade(owner, GRENADE_SMOKEGREN)
  3516. }
  3517.  
  3518. if (get_option(OPTION_RESOURCE_USE))
  3519. metal_gibs(origin)
  3520.  
  3521. clear_line(grenade)
  3522.  
  3523. return HAM_SUPERCEDE
  3524. }
  3525.  
  3526. if (ok)
  3527. {
  3528. SetHamParamFloat(4, damage)
  3529. return HAM_HANDLED
  3530. }
  3531.  
  3532. return HAM_IGNORED
  3533. }
  3534.  
  3535. public fw_traceline(Float:start[3], Float:end[3], conditions, id, trace)
  3536. {
  3537. if (!(bs_forward_collection & FWD_HPSYSTEM))
  3538. return FMRES_IGNORED
  3539.  
  3540. if (!is_player_alive(id))
  3541. return FMRES_IGNORED
  3542.  
  3543. if (cl_weapon[id] != CSW_KNIFE)
  3544. return FMRES_IGNORED
  3545.  
  3546. if (pev_valid(get_tr2(trace,TR_pHit)))
  3547. return FMRES_IGNORED
  3548.  
  3549. static Float:vec_end[3], i
  3550. i = g_maxplayers
  3551.  
  3552. get_tr2(trace, TR_vecEndPos, vec_end)
  3553.  
  3554. while ((i = find_ent_in_sphere(i, vec_end, SHOT_SECOND_TEST_RADIUS)))
  3555. {
  3556. if (is_grenade(i, true))
  3557. {
  3558. static Float:origin[3]
  3559. pev(i,pev_origin,origin)
  3560. xs_vec_sub(origin,vec_end,origin)
  3561. if (xs_vec_len(origin) > SHOT_KNIFE_REAL_RADIUS)
  3562. continue
  3563.  
  3564. set_tr2(trace, TR_pHit, i)
  3565. break
  3566. }
  3567. }
  3568.  
  3569. return FMRES_HANDLED
  3570. }
  3571.  
  3572. public fw_global_traceattack(ent, attacker, Float:damage, Float:direction[3], tracehdl, damagebits)
  3573. {
  3574. if (!(bs_forward_collection & FWD_HPSYSTEM))
  3575. return FMRES_IGNORED
  3576.  
  3577. if (attacker > g_maxplayers || attacker < 1)
  3578. return HAM_IGNORED
  3579.  
  3580. if (cl_weapon[attacker] == CSW_KNIFE)
  3581. return HAM_IGNORED
  3582.  
  3583. static Float:origin[3],Float:offs[3]
  3584. pev(attacker,pev_origin,origin)
  3585. pev(attacker,pev_view_ofs,offs)
  3586. xs_vec_add(origin,offs,origin)
  3587.  
  3588. static Float:end[3], Float:point[3], Float:origin_nade[3], Float:track[3]
  3589. get_tr2(tracehdl,TR_vecEndPos,end)
  3590.  
  3591. xs_vec_sub(end,origin,point)
  3592. xs_vec_mul_scalar(point, SHOT_PENETRATION_DISTANCE / xs_vec_len(point), point)
  3593. xs_vec_add(end, point, end)
  3594.  
  3595. static grenade
  3596. static bool:ok
  3597. static bool:reset_queue
  3598.  
  3599. grenade = -1
  3600. reset_queue = false
  3601.  
  3602. while ((grenade = find_ent_by_class(grenade,"grenade")))
  3603. {
  3604. if (entity_get_float(grenade, EV_FL_dmgtime) < get_gametime())
  3605. continue
  3606.  
  3607. ok = false
  3608. entity_get_vector(grenade, EV_VEC_origin, origin_nade)
  3609.  
  3610. for (new i=0;i<SHOT_ENTITY_QUEUE_LENGTH;i++)
  3611. {
  3612. if (grenade == cl_entity_queue[attacker][i])
  3613. {
  3614. cl_entity_queue[attacker][i] = 0;
  3615. ok = true;
  3616. reset_queue = true;
  3617. break;
  3618. }
  3619. }
  3620.  
  3621. if (ok)
  3622. {
  3623. continue;
  3624. }
  3625.  
  3626. engfunc(EngFunc_TraceModel,origin,end,HULL_POINT,grenade,g_ptrace[TH_DMG])
  3627.  
  3628. if(get_tr2(g_ptrace[TH_DMG],TR_pHit) == grenade)
  3629. {
  3630. ExecuteHamB(Ham_TraceAttack, grenade, attacker, damage, direction, g_ptrace[TH_DMG], damagebits)
  3631.  
  3632. insert_in_queue(attacker, grenade)
  3633. }
  3634. else
  3635. {
  3636. new times = 1
  3637.  
  3638. xs_vec_sub(origin_nade, end, track)
  3639.  
  3640. while (times != SHOT_PENETRATION_READD_TIMES + 1 && xs_vec_len(track) > SHOT_SECOND_TEST_RADIUS)
  3641. {
  3642. xs_vec_add(end, point, track)
  3643.  
  3644. for (new i=1;i<=times;++i)
  3645. {
  3646. xs_vec_add(track, point, track)
  3647. }
  3648.  
  3649. xs_vec_sub(origin_nade, track, track)
  3650.  
  3651. times++;
  3652. }
  3653.  
  3654. if ( xs_vec_len(track) <= SHOT_SECOND_TEST_RADIUS )
  3655. {
  3656. set_tr2(g_ptrace[TH_DMG], TR_pHit, grenade)
  3657.  
  3658. xs_vec_add(origin_nade, track, track)
  3659. set_tr2(g_ptrace[TH_DMG], TR_vecEndPos, track)
  3660.  
  3661. ExecuteHamB(Ham_TraceAttack, grenade, attacker, (damage / 2), direction, g_ptrace[TH_DMG], damagebits)
  3662.  
  3663. insert_in_queue(attacker, grenade)
  3664. }
  3665. }
  3666. }
  3667.  
  3668. if (reset_queue)
  3669. {
  3670. for (new i=0;i<SHOT_ENTITY_QUEUE_LENGTH;i++)
  3671. {
  3672. cl_entity_queue[attacker][i] = 0
  3673. }
  3674. }
  3675.  
  3676. return HAM_IGNORED
  3677. }
  3678.  
  3679. /* -------------------------------
  3680. [Plugin Zombie Mod Compatibility Forwards]
  3681. ------------------------------- */
  3682. public zp_user_infected_post(id, infector)
  3683. {
  3684. g_zombie_mod |= ZM_DO_ALL
  3685.  
  3686. // Reset the mode on infection
  3687. mode[id][GRENADE_EXPLOSIVE] = FirstEnabledMode(GRENADE_EXPLOSIVE)
  3688. mode[id][GRENADE_FLASHBANG] = FirstEnabledMode(GRENADE_FLASHBANG)
  3689. mode[id][GRENADE_SMOKEGREN] = FirstEnabledMode(GRENADE_SMOKEGREN)
  3690.  
  3691. resetCounter(id)
  3692. removeNades(id)
  3693.  
  3694. return PLUGIN_CONTINUE
  3695. }
  3696.  
  3697. public event_infect(id, attacker)
  3698. {
  3699. g_zombie_mod |= ZM_DO_ALL
  3700.  
  3701. // Reset the mode on infection
  3702. mode[id][GRENADE_EXPLOSIVE] = FirstEnabledMode(GRENADE_EXPLOSIVE)
  3703. mode[id][GRENADE_FLASHBANG] = FirstEnabledMode(GRENADE_FLASHBANG)
  3704. mode[id][GRENADE_SMOKEGREN] = FirstEnabledMode(GRENADE_SMOKEGREN)
  3705.  
  3706. resetCounter(id)
  3707. removeNades(id)
  3708.  
  3709. return PLUGIN_CONTINUE
  3710. }
  3711.  
  3712. /* -------------------------------
  3713. [Usefull Functions -> NadeMode Tolls]
  3714. ------------------------------- */
  3715. stock is_nademodes_enabled()
  3716. {
  3717. if (get_option(OPTION_ENABLE_NADE_MODES))
  3718. {
  3719. return ((get_option(OPTION_NORMAL_ENABLED)<<0) | (get_option(OPTION_PROXIMITY_ENABLED)<<1) | (get_option(OPTION_IMPACT_ENABLED)<<2) | (get_option(OPTION_TRIP_ENABLED)<<3) | (get_option(OPTION_MOTION_ENABLED)<<4) | (get_option(OPTION_SATCHEL_ENABLED)<<5) | (get_option(OPTION_HOMING_ENABLED)<<6))
  3720. }
  3721.  
  3722. return 0
  3723. }
  3724.  
  3725. stock NadeType:FirstEnabledMode(NadeRace:race)
  3726. {
  3727. if (is_mode_cvarenabled(g_firstenabledmode[race], race))
  3728. return g_firstenabledmode[race]
  3729.  
  3730. for (new NadeType:i=NADE_NORMAL;i<=NADE_HOMING;i++)
  3731. {
  3732. if (is_mode_cvarenabled(i, race))
  3733. {
  3734. g_firstenabledmode[race] = i
  3735. return i
  3736. }
  3737. }
  3738.  
  3739. return NADE_NORMAL
  3740. }
  3741.  
  3742. public is_mode_cvarenabled(NadeType:type, NadeRace:nade)
  3743. {
  3744. switch (type)
  3745. {
  3746. case NADE_NORMAL:
  3747. {
  3748. return get_option(OPTION_NORMAL_ENABLED)
  3749. }
  3750.  
  3751. case NADE_PROXIMITY:
  3752. {
  3753. return get_option(OPTION_PROXIMITY_ENABLED)
  3754. }
  3755.  
  3756. case NADE_IMPACT:
  3757. {
  3758. return get_option(OPTION_IMPACT_ENABLED)
  3759. }
  3760.  
  3761. case NADE_TRIP:
  3762. {
  3763. return get_option(OPTION_TRIP_ENABLED)
  3764. }
  3765.  
  3766. case NADE_MOTION:
  3767. {
  3768. return get_option(OPTION_MOTION_ENABLED)
  3769. }
  3770.  
  3771. case NADE_SATCHEL:
  3772. {
  3773. return get_option(OPTION_SATCHEL_ENABLED)
  3774. }
  3775.  
  3776. case NADE_HOMING:
  3777. {
  3778. return get_option(OPTION_HOMING_ENABLED)
  3779. }
  3780. }
  3781.  
  3782. return 0
  3783. }
  3784.  
  3785. public is_mode_enabled(id, NadeType:type, NadeRace:nade)
  3786. {
  3787. switch (type)
  3788. {
  3789. case NADE_NORMAL:
  3790. {
  3791. return get_option(OPTION_NORMAL_ENABLED)
  3792. }
  3793.  
  3794. case NADE_PROXIMITY:
  3795. {
  3796. if (!get_option(OPTION_PROXIMITY_ENABLED))
  3797. return 0
  3798.  
  3799. if (!get_option(OPTION_LIMIT_SYSTEM))
  3800. return 1
  3801.  
  3802. if (!get_option(OPTION_LIMIT_PROXIMITY))
  3803. return 1
  3804.  
  3805. if (get_option(OPTION_LIMIT_SYSTEM) == 1 && cl_counter[id][nade][type] < get_option(OPTION_LIMIT_PROXIMITY))
  3806. return 1
  3807.  
  3808. if (get_option(OPTION_LIMIT_SYSTEM) == 2 && (cl_counter[id][GRENADE_EXPLOSIVE][type] + cl_counter[id][GRENADE_SMOKEGREN][type] + cl_counter[id][GRENADE_FLASHBANG][type]) < get_option(OPTION_LIMIT_PROXIMITY))
  3809. return 1
  3810.  
  3811. return 0
  3812. }
  3813.  
  3814. case NADE_IMPACT:
  3815. {
  3816. return get_option(OPTION_IMPACT_ENABLED)
  3817. }
  3818.  
  3819. case NADE_TRIP:
  3820. {
  3821. if (!get_option(OPTION_TRIP_ENABLED))
  3822. return 0
  3823.  
  3824. if (!get_option(OPTION_LIMIT_SYSTEM))
  3825. return 1
  3826.  
  3827. if (!get_option(OPTION_LIMIT_TRIP))
  3828. return 1
  3829.  
  3830. if (get_option(OPTION_LIMIT_SYSTEM) == 1 && cl_counter[id][nade][type] < get_option(OPTION_LIMIT_TRIP))
  3831. return 1
  3832.  
  3833. if (get_option(OPTION_LIMIT_SYSTEM) == 2 && (cl_counter[id][GRENADE_EXPLOSIVE][type] + cl_counter[id][GRENADE_SMOKEGREN][type] + cl_counter[id][GRENADE_FLASHBANG][type]) < get_option(OPTION_LIMIT_TRIP))
  3834. return 1
  3835.  
  3836. return 0
  3837. }
  3838.  
  3839. case NADE_MOTION:
  3840. {
  3841. if (!get_option(OPTION_MOTION_ENABLED))
  3842. return 0
  3843.  
  3844. if (!get_option(OPTION_LIMIT_SYSTEM))
  3845. return 1
  3846.  
  3847. if (!get_option(OPTION_LIMIT_MOTION))
  3848. return 1
  3849.  
  3850. if (get_option(OPTION_LIMIT_SYSTEM) == 1 && cl_counter[id][nade][type] < get_option(OPTION_LIMIT_MOTION))
  3851. return 1
  3852.  
  3853. if (get_option(OPTION_LIMIT_SYSTEM) == 2 && (cl_counter[id][GRENADE_EXPLOSIVE][type] + cl_counter[id][GRENADE_SMOKEGREN][type] + cl_counter[id][GRENADE_FLASHBANG][type]) < get_option(OPTION_LIMIT_MOTION))
  3854. return 1
  3855.  
  3856. return 0
  3857. }
  3858.  
  3859. case NADE_SATCHEL:
  3860. {
  3861. if (!get_option(OPTION_SATCHEL_ENABLED))
  3862. return 0
  3863.  
  3864. if (!get_option(OPTION_LIMIT_SYSTEM))
  3865. return 1
  3866.  
  3867. if (!get_option(OPTION_LIMIT_SATCHEL))
  3868. return 1
  3869.  
  3870. if (get_option(OPTION_LIMIT_SYSTEM) == 1 && cl_counter[id][nade][type] < get_option(OPTION_LIMIT_SATCHEL))
  3871. return 1
  3872.  
  3873. if (get_option(OPTION_LIMIT_SYSTEM) == 2 && (cl_counter[id][GRENADE_EXPLOSIVE][type] + cl_counter[id][GRENADE_SMOKEGREN][type] + cl_counter[id][GRENADE_FLASHBANG][type]) < get_option(OPTION_LIMIT_SATCHEL))
  3874. return 1
  3875.  
  3876. return 0
  3877. }
  3878.  
  3879. case NADE_HOMING:
  3880. {
  3881. return get_option(OPTION_HOMING_ENABLED)
  3882. }
  3883. }
  3884.  
  3885. return 1
  3886. }
  3887.  
  3888. public get_enabled_modes(id, NadeRace:nade)
  3889. {
  3890. for (new NadeType:type = NADE_NORMAL; type <= NADE_HOMING; type = type + NADE_PROXIMITY)
  3891. {
  3892. if (is_mode_enabled(id, type, nade))
  3893. return 1
  3894. }
  3895.  
  3896. return 0;
  3897. }
  3898.  
  3899.  
  3900. public changemode(id, NadeRace:NADE_TYPE)
  3901. {
  3902. if (!(grenade_can_be_used(NADE_TYPE)))
  3903. {
  3904. return
  3905. }
  3906.  
  3907. if (!is_mode_enabled(id, ++mode[id][NADE_TYPE], NADE_TYPE))
  3908. {
  3909. changemode(id, NADE_TYPE)
  3910. return
  3911. }
  3912.  
  3913. switch (mode[id][NADE_TYPE])
  3914. {
  3915. case NADE_NORMAL:
  3916. {
  3917. client_print(id, print_center, "Mode - Normal")
  3918. }
  3919.  
  3920. case NADE_PROXIMITY:
  3921. {
  3922. client_print(id, print_center, "Mode - Proximity")
  3923. }
  3924.  
  3925. case NADE_IMPACT:
  3926. {
  3927. client_print(id, print_center, "Mode - Impact")
  3928. }
  3929.  
  3930. case NADE_TRIP:
  3931. {
  3932. client_print(id, print_center, "Mode - Trip laser")
  3933. }
  3934.  
  3935. case NADE_MOTION:
  3936. {
  3937. client_print(id, print_center, "Mode - Motion sensor")
  3938. }
  3939.  
  3940. case NADE_SATCHEL:
  3941. {
  3942. client_print(id, print_center, "Mode - Satchel charge")
  3943. }
  3944.  
  3945. case NADE_HOMING:
  3946. {
  3947. client_print(id, print_center, "Mode - Homing")
  3948. }
  3949.  
  3950. default:
  3951. {
  3952. mode[id][NADE_TYPE] = NADE_DUD
  3953. changemode(id, NADE_TYPE)
  3954. }
  3955. }
  3956. }
  3957.  
  3958. resetCounter(id)
  3959. {
  3960. cl_counter[id][GRENADE_EXPLOSIVE][NADE_MOTION] = 0
  3961. cl_counter[id][GRENADE_EXPLOSIVE][NADE_PROXIMITY] = 0
  3962. cl_counter[id][GRENADE_EXPLOSIVE][NADE_TRIP] = 0
  3963. cl_counter[id][GRENADE_EXPLOSIVE][NADE_SATCHEL] = 0
  3964. cl_counter[id][GRENADE_FLASHBANG][NADE_MOTION] = 0
  3965. cl_counter[id][GRENADE_FLASHBANG][NADE_PROXIMITY] = 0
  3966. cl_counter[id][GRENADE_FLASHBANG][NADE_TRIP] = 0
  3967. cl_counter[id][GRENADE_FLASHBANG][NADE_SATCHEL] = 0
  3968. cl_counter[id][GRENADE_SMOKEGREN][NADE_MOTION] = 0
  3969. cl_counter[id][GRENADE_SMOKEGREN][NADE_PROXIMITY] = 0
  3970. cl_counter[id][GRENADE_SMOKEGREN][NADE_TRIP] = 0
  3971. cl_counter[id][GRENADE_SMOKEGREN][NADE_SATCHEL] = 0
  3972.  
  3973. cl_can_use_nade[GRENADE_EXPLOSIVE] |= (1<<id)
  3974. cl_can_use_nade[GRENADE_FLASHBANG] |= (1<<id)
  3975. cl_can_use_nade[GRENADE_SMOKEGREN] |= (1<<id)
  3976.  
  3977. return
  3978. }
  3979.  
  3980. removeNades(id)
  3981. {
  3982. static ent
  3983. ent = -1
  3984.  
  3985. // Get all the grenade entities
  3986. while ((ent = find_ent_by_class(ent, "grenade")))
  3987. {
  3988. if (entity_get_edict(ent, EV_ENT_owner) != id)
  3989. continue
  3990.  
  3991. // Set the remove property if they aren't normal nades
  3992. if(is_grenade(ent) && get_grenade_type(ent) != NADE_NORMAL)
  3993. entity_set_int(ent, EV_INT_flags , entity_get_int(ent, EV_INT_flags) | FL_KILLME)
  3994. }
  3995.  
  3996. return
  3997. }
  3998.  
  3999. /* -------------------------------
  4000. [Usefull Functions -> Grenade Property Set/Get]
  4001. ------------------------------- */
  4002. is_grenade(ent, bool:enforce = false)
  4003. {
  4004. if (!is_valid_ent(ent))
  4005. {
  4006. return 0
  4007. }
  4008.  
  4009. if (enforce)
  4010. {
  4011. if (!is_classname(ent, "grenade"))
  4012. return 0
  4013. }
  4014.  
  4015. if (is_grenade_c4(ent))
  4016. return 0
  4017.  
  4018. static weapon_id
  4019. weapon_id = cs_get_weapon_id(ent)
  4020.  
  4021. for (new i=0;i<3;i++)
  4022. {
  4023. if (weapon_id == NADE_WPID[NadeRace:i])
  4024. return 1
  4025. }
  4026.  
  4027. return 0
  4028. }
  4029.  
  4030. is_classname(ent, const string[])
  4031. {
  4032. new classname[20]
  4033.  
  4034. entity_get_string(ent, EV_SZ_classname, classname, charsmax(classname))
  4035.  
  4036. return equali(string, classname, strlen(string))
  4037. }
  4038.  
  4039. public get_grenade_race(grenade)
  4040. {
  4041. switch (cs_get_weapon_id(grenade))
  4042. {
  4043. case CSW_HEGRENADE: return _:GRENADE_EXPLOSIVE
  4044. case CSW_FLASHBANG: return _:GRENADE_FLASHBANG
  4045. case CSW_SMOKEGRENADE: return _:GRENADE_SMOKEGREN
  4046. }
  4047.  
  4048. return -1
  4049. }
  4050.  
  4051. set_grenade_type(grenade, NadeType:g_type, bool:property = true)
  4052. {
  4053. if (!is_valid_ent(grenade)) return
  4054.  
  4055. static NadeRace:nade
  4056. static owner
  4057.  
  4058. owner = entity_get_edict(grenade, EV_ENT_owner)
  4059.  
  4060. nade = NadeRace:get_grenade_race(grenade)
  4061.  
  4062. if (g_FW_property > 0 && g_type != NADE_DUD)
  4063. {
  4064. new ret
  4065. ExecuteForward(g_FW_property, ret, grenade, g_type)
  4066.  
  4067. if (ret > PLUGIN_CONTINUE)
  4068. {
  4069. if (g_PFW_property > 0)
  4070. ExecuteForward(g_PFW_property, ret, grenade, g_type, 1)
  4071.  
  4072. return
  4073. }
  4074.  
  4075. if (g_PFW_property > 0)
  4076. ExecuteForward(g_PFW_property, ret, grenade, g_type, 0)
  4077. }
  4078.  
  4079. // Set grenade properties and empty the slots so we can put some info
  4080. entity_set_int(grenade, EV_INT_iuser1, _:g_type)
  4081. entity_set_int(grenade, EV_INT_iuser2, 0)
  4082. entity_set_int(grenade, EV_INT_iuser3, 0)
  4083. entity_set_int(grenade, EV_INT_iuser4, 0)
  4084.  
  4085. entity_set_vector(grenade, EV_VEC_vuser1, Float:{0.0, 0.0, 0.0})
  4086. entity_set_vector(grenade, EV_VEC_vuser2, Float:{0.0, 0.0, 0.0})
  4087. entity_set_vector(grenade, EV_VEC_vuser3, Float:{0.0, 0.0, 0.0})
  4088. entity_set_vector(grenade, EV_VEC_vuser4, Float:{0.0, 0.0, 0.0})
  4089.  
  4090. if (property == true)
  4091. {
  4092. switch (g_type)
  4093. {
  4094. case NADE_DUD:
  4095. {
  4096. entity_set_int(grenade, EV_INT_movetype, MOVETYPE_BOUNCE)
  4097. entity_set_vector(grenade, EV_VEC_velocity, Float:{0.0, 0.0, 0.0})
  4098. }
  4099.  
  4100. case NADE_NORMAL:
  4101. {
  4102. entity_set_float(grenade, EV_FL_health, floatabs(get_option_float(OPTION_HITPOINT_NORMAL)))
  4103.  
  4104. if (get_option(OPTION_MATERIAL_SYSTEM) == 2 && get_option(OPTION_HITPOINT_NORMAL))
  4105. {
  4106. entity_set_float(grenade, EV_FL_takedamage, DAMAGE_YES)
  4107. }
  4108. }
  4109.  
  4110. case NADE_PROXIMITY:
  4111. {
  4112. delay_explosion(grenade)
  4113. set_grenade_allow_explode(grenade, get_option_float(OPTION_ARM_TIME_PROXIMITY))
  4114.  
  4115. entity_set_float(grenade, EV_FL_health, floatabs(get_option_float(OPTION_HITPOINT_PROXIMITY)))
  4116.  
  4117. if (get_option(OPTION_MATERIAL_SYSTEM) == 2 && get_option(OPTION_HITPOINT_PROXIMITY))
  4118. {
  4119. entity_set_float(grenade, EV_FL_takedamage, DAMAGE_YES)
  4120. }
  4121.  
  4122. cl_counter[owner][nade][NADE_PROXIMITY] += 1
  4123.  
  4124. refresh_can_use_nade(owner, GRENADE_EXPLOSIVE)
  4125. refresh_can_use_nade(owner, GRENADE_FLASHBANG)
  4126. refresh_can_use_nade(owner, GRENADE_SMOKEGREN)
  4127. }
  4128.  
  4129. case NADE_IMPACT:
  4130. {
  4131. delay_explosion(grenade)
  4132. entity_set_int(grenade, EV_INT_movetype, MOVETYPE_BOUNCE)
  4133.  
  4134. entity_set_float(grenade, EV_FL_health, floatabs(get_option_float(OPTION_HITPOINT_IMPACT)))
  4135.  
  4136. if (get_option(OPTION_MATERIAL_SYSTEM) == 2 && get_option(OPTION_HITPOINT_IMPACT))
  4137. {
  4138. entity_set_float(grenade, EV_FL_takedamage, DAMAGE_YES)
  4139. }
  4140. }
  4141.  
  4142. // I don't recommend setting a grenade to trip if it was another type in the first place.
  4143. case NADE_TRIP:
  4144. {
  4145. delay_explosion(grenade)
  4146.  
  4147. entity_set_float(grenade, EV_FL_health, floatabs(get_option_float(OPTION_HITPOINT_TRIP)))
  4148.  
  4149. if (get_option(OPTION_MATERIAL_SYSTEM) == 2 && get_option(OPTION_HITPOINT_TRIP))
  4150. {
  4151. entity_set_float(grenade, EV_FL_takedamage, DAMAGE_YES)
  4152. }
  4153.  
  4154. cl_counter[owner][nade][NADE_TRIP] += 1
  4155.  
  4156. refresh_can_use_nade(owner, GRENADE_EXPLOSIVE)
  4157. refresh_can_use_nade(owner, GRENADE_FLASHBANG)
  4158. refresh_can_use_nade(owner, GRENADE_SMOKEGREN)
  4159. }
  4160.  
  4161. case NADE_MOTION:
  4162. {
  4163. delay_explosion(grenade)
  4164. set_grenade_allow_explode(grenade, get_option_float(OPTION_ARM_TIME_MOTION))
  4165.  
  4166. entity_set_float(grenade, EV_FL_health, floatabs(get_option_float(OPTION_HITPOINT_MOTION)))
  4167.  
  4168. if (get_option(OPTION_MATERIAL_SYSTEM) == 2 && get_option(OPTION_HITPOINT_MOTION))
  4169. {
  4170. entity_set_float(grenade, EV_FL_takedamage, DAMAGE_YES)
  4171. }
  4172.  
  4173. cl_counter[owner][nade][NADE_MOTION] += 1
  4174.  
  4175. refresh_can_use_nade(owner, GRENADE_EXPLOSIVE)
  4176. refresh_can_use_nade(owner, GRENADE_FLASHBANG)
  4177. refresh_can_use_nade(owner, GRENADE_SMOKEGREN)
  4178. }
  4179.  
  4180. case NADE_SATCHEL:
  4181. {
  4182. delay_explosion(grenade)
  4183. set_grenade_allow_explode(grenade, get_option_float(OPTION_ARM_TIME_SATCHEL))
  4184.  
  4185. entity_set_float(grenade, EV_FL_health, floatabs(get_option_float(OPTION_HITPOINT_SATCHEL)))
  4186.  
  4187. if (get_option(OPTION_MATERIAL_SYSTEM) == 2 && get_option(OPTION_HITPOINT_SATCHEL))
  4188. {
  4189. entity_set_float(grenade, EV_FL_takedamage, DAMAGE_YES)
  4190. }
  4191.  
  4192. cl_counter[owner][nade][NADE_SATCHEL] += 1
  4193.  
  4194. refresh_can_use_nade(owner, GRENADE_EXPLOSIVE)
  4195. refresh_can_use_nade(owner, GRENADE_FLASHBANG)
  4196. refresh_can_use_nade(owner, GRENADE_SMOKEGREN)
  4197. }
  4198.  
  4199. case NADE_HOMING:
  4200. {
  4201. entity_set_float(grenade, EV_FL_dmgtime, entity_get_float(grenade, EV_FL_dmgtime) + get_option_float(OPTION_HOMING_EXTRATIME))
  4202.  
  4203. entity_set_float(grenade, EV_FL_health, floatabs(get_option_float(OPTION_HITPOINT_HOMING)))
  4204.  
  4205. if (get_option(OPTION_MATERIAL_SYSTEM) == 2 && get_option(OPTION_HITPOINT_HOMING))
  4206. {
  4207. entity_set_float(grenade, EV_FL_takedamage, DAMAGE_YES)
  4208. }
  4209. }
  4210. }
  4211. }
  4212. }
  4213.  
  4214.  
  4215.  
  4216. public get_trip_grenade_react_method(grenade)
  4217. {
  4218. new NadeRace:grenade_race = NadeRace:get_grenade_race(grenade)
  4219.  
  4220. switch (grenade_race)
  4221. {
  4222. case GRENADE_EXPLOSIVE: return get_option(OPTION_REACT_TRIP_G)
  4223. case GRENADE_FLASHBANG: return get_option(OPTION_REACT_TRIP_F)
  4224. case GRENADE_SMOKEGREN: return get_option(OPTION_REACT_TRIP_S)
  4225. }
  4226.  
  4227. return -1
  4228. }
  4229.  
  4230. /* -------------------------------
  4231. [Usefull Functions -> Surface and solid tests + line of sight]
  4232. ------------------------------- */
  4233. public bool:is_ent_monster(ent)
  4234. {
  4235. if (!pev_valid(ent))
  4236. return false
  4237.  
  4238. if (!is_classname(ent, "func_wall"))
  4239. return false
  4240.  
  4241. return !!(pev(ent, pev_flags) & FL_MONSTER)
  4242. }
  4243.  
  4244. public bool:is_solid(ent)
  4245. {
  4246. // Here we account for ent = 0, where 0 means it's part of the map (and therefore is solid)
  4247. return ( ent ? ( (entity_get_int(ent, EV_INT_solid) > SOLID_TRIGGER) ? true : false ) : true )
  4248. }
  4249.  
  4250. public bool:is_attachable_surface(entity)
  4251. {
  4252. static Float:velocity[3]
  4253.  
  4254. if (is_valid_ent(entity))
  4255. {
  4256. if (!is_solid(entity)) return false // This is for func_breakables. The entity technically exists, but isn't solid.
  4257. entity_get_vector(entity, EV_VEC_velocity, velocity) // This is for func_doors. The grenade touches the door, causing it to move.
  4258. return (xs_vec_equal(velocity, Float:{0.0, 0.0, 0.0}) ? true : false)
  4259. }
  4260.  
  4261. return true
  4262. }
  4263.  
  4264. public bool:is_in_los(grenade_ent, player)
  4265. {
  4266. static Float:start[3], Float:end[3]
  4267. entity_get_vector(grenade_ent, EV_VEC_origin, start)
  4268. entity_get_vector(player, EV_VEC_origin, end)
  4269.  
  4270. start[2] += 2.0
  4271.  
  4272. engfunc(EngFunc_TraceLine, start, end, IGNORE_MONSTERS, grenade_ent, g_ptrace[TH_LOS])
  4273.  
  4274. static Float:dist
  4275. get_tr2(g_ptrace[TH_LOS], TR_flFraction, dist)
  4276.  
  4277. return ((dist == 1.0) ? true : false)
  4278. }
  4279.  
  4280.  
  4281. // This function is limited, it returns the same values unter CONE_CALC_DISTANCE_MAX
  4282. stock Float:calc_cone_angle_from_distance(Float:distance)
  4283. {
  4284. // The angle is calculated from a formula that looks like this
  4285. // angle = atan(A*(CONE_BASE_RADIUS/(distance-B)))
  4286. static Float:A,Float:B;
  4287.  
  4288. // The constants A and B need to be calculated first, this if will only happen once
  4289. if (A == 0.0 && B == 0.0)
  4290. {
  4291. if (CONE_BASE_RADIUS == 0.0)
  4292. {
  4293. A = ((CONE_CALC_DISTANCE_MIN-CONE_CALC_DISTANCE_MAX)*floattan(CONE_CALC_ANGLE_MAX, degrees)*floattan(CONE_CALC_ANGLE_MIN, degrees))/(floattan(CONE_CALC_ANGLE_MAX, degrees)-floattan(CONE_CALC_ANGLE_MIN, degrees))
  4294. B = (CONE_CALC_DISTANCE_MAX*floattan(CONE_CALC_ANGLE_MAX, degrees) - CONE_CALC_DISTANCE_MIN*floattan(CONE_CALC_ANGLE_MIN, degrees))/(floattan(CONE_CALC_ANGLE_MAX, degrees)-floattan(CONE_CALC_ANGLE_MIN, degrees))
  4295. }
  4296. else
  4297. {
  4298. A = CONE_BASE_RADIUS;
  4299. B = CONE_CALC_DISTANCE_MAX - CONE_BASE_RADIUS/floattan(CONE_CALC_ANGLE_MAX, degrees)
  4300. }
  4301. }
  4302.  
  4303. // Return the angle in radians that is checked
  4304. return (distance < CONE_CALC_DISTANCE_MAX) ? floatatan(A/((CONE_CALC_DISTANCE_MIN)-B), radian) : floatatan(A/((distance)-B), radian)
  4305. }
  4306.  
  4307. public insert_in_queue(id, ent_id)
  4308. {
  4309. for (new i=0;i<SHOT_ENTITY_QUEUE_LENGTH;i++)
  4310. {
  4311. if (cl_entity_queue[id][i] == 0)
  4312. {
  4313. cl_entity_queue[id][i] = ent_id
  4314. break;
  4315. }
  4316.  
  4317. if (i == SHOT_ENTITY_QUEUE_LENGTH - 1)
  4318. {
  4319. server_print("[NDM] Error! Unable to save so much entities!")
  4320. server_print("[NDM] Increase the value of the ^"SHOT_ENTITY_QUEUE_LENGTH^" define and recompile!")
  4321. log_amx("[NDM] Error! Unable to save so much entities")
  4322. log_amx("[NDM] Increase the value of the ^"SHOT_ENTITY_QUEUE_LENGTH^" define and recompile!")
  4323. }
  4324. }
  4325. }
  4326. /* -------------------------------
  4327. [Message Functions]
  4328. ------------------------------- */
  4329. draw_line_from_entity(entid, Float:end[3], staytime, R = NOTEAM_RGB_R_COLOR, G = NOTEAM_RGB_G_COLOR, B = NOTEAM_RGB_B_COLOR, id = 0, Float:pvs[3] = {0.0, 0.0, 0.0})
  4330. {
  4331. ( id == 0 ) ? engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, pvs, 0) : engfunc(EngFunc_MessageBegin, get_option(OPTION_MSG_SVC_BAD) ? MSG_ONE : MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, pvs, id)
  4332. write_byte(TE_BEAMENTPOINT)
  4333. write_short(entid) // start entity
  4334. engfunc(EngFunc_WriteCoord, end[0])
  4335. engfunc(EngFunc_WriteCoord, end[1])
  4336. engfunc(EngFunc_WriteCoord, end[2])
  4337. write_short(beampoint)
  4338. write_byte(0)
  4339. write_byte(0)
  4340. write_byte(staytime)
  4341. write_byte(10)
  4342. write_byte(0)
  4343. write_byte(R)
  4344. write_byte(G)
  4345. write_byte(B)
  4346. write_byte(127)
  4347. write_byte(1)
  4348. message_end()
  4349. }
  4350.  
  4351. stock draw_line(Float:start[3], Float:end[3], staytime, R = NOTEAM_RGB_R_COLOR, G = NOTEAM_RGB_G_COLOR, B = NOTEAM_RGB_B_COLOR)
  4352. {
  4353. engfunc(EngFunc_MessageBegin, MSG_ALL, SVC_TEMPENTITY, Float:{0.0,0.0,0.0}, 0)
  4354. write_byte(TE_BEAMPOINTS)
  4355. engfunc(EngFunc_WriteCoord, start[0])
  4356. engfunc(EngFunc_WriteCoord, start[1])
  4357. engfunc(EngFunc_WriteCoord, start[2])
  4358. engfunc(EngFunc_WriteCoord, end[0])
  4359. engfunc(EngFunc_WriteCoord, end[1])
  4360. engfunc(EngFunc_WriteCoord, end[2])
  4361. write_short(beampoint)
  4362. write_byte(0)
  4363. write_byte(0)
  4364. write_byte(staytime)
  4365. write_byte(10)
  4366. write_byte(0)
  4367. write_byte(R)
  4368. write_byte(G)
  4369. write_byte(B)
  4370. write_byte(127)
  4371. write_byte(1)
  4372. message_end()
  4373. }
  4374.  
  4375. draw_line_from_entity_broadcast(entid, Float:end[3], staytime, R = NOTEAM_RGB_R_COLOR, G = NOTEAM_RGB_G_COLOR, B = NOTEAM_RGB_B_COLOR)
  4376. {
  4377. engfunc(EngFunc_MessageBegin, get_option(OPTION_MSG_SVC_BAD) ? MSG_ALL : MSG_BROADCAST, SVC_TEMPENTITY, {0.0, 0.0, 0.0}, 0)
  4378. write_byte(TE_BEAMENTPOINT)
  4379. write_short(entid) // start entity
  4380. engfunc(EngFunc_WriteCoord, end[0])
  4381. engfunc(EngFunc_WriteCoord, end[1])
  4382. engfunc(EngFunc_WriteCoord, end[2])
  4383. write_short(beampoint)
  4384. write_byte(0)
  4385. write_byte(0)
  4386. write_byte(staytime)
  4387. write_byte(10)
  4388. write_byte(0)
  4389. write_byte(R)
  4390. write_byte(G)
  4391. write_byte(B)
  4392. write_byte(127)
  4393. write_byte(1)
  4394. message_end()
  4395. }
  4396.  
  4397. clear_line(entid)
  4398. {
  4399. message_begin(MSG_ALL, SVC_TEMPENTITY)
  4400. write_byte(TE_KILLBEAM)
  4401. write_short(entid)
  4402. message_end()
  4403. }
  4404.  
  4405. show_ring(Float:origin[3], Float:addict, staytime, R = NOTEAM_RGB_R_COLOR, G = NOTEAM_RGB_G_COLOR, B = NOTEAM_RGB_B_COLOR , id = 0)
  4406. {
  4407. ( id == 0 ) ? engfunc(EngFunc_MessageBegin, get_option(OPTION_MSG_SVC_BAD) ? MSG_ALL : MSG_BROADCAST, SVC_TEMPENTITY, {0.0, 0.0, 0.0}, 0) : engfunc(EngFunc_MessageBegin, get_option(OPTION_MSG_SVC_BAD) ? MSG_ONE : MSG_ONE_UNRELIABLE , SVC_TEMPENTITY, {0.0, 0.0, 0.0}, id)
  4408. write_byte(TE_BEAMCYLINDER) // TE_BEAMCYLINDER
  4409. engfunc(EngFunc_WriteCoord, origin[0]) // start X
  4410. engfunc(EngFunc_WriteCoord, origin[1]) // start Y
  4411. engfunc(EngFunc_WriteCoord, origin[2]) // start Z
  4412. engfunc(EngFunc_WriteCoord, origin[0]) // something X
  4413. engfunc(EngFunc_WriteCoord, origin[1]) // something Y
  4414. engfunc(EngFunc_WriteCoord, origin[2] + addict) // something Z
  4415. write_short(shockwave) // sprite
  4416. write_byte(0) // startframe
  4417. write_byte(0) // framerate
  4418. write_byte(staytime) // life
  4419. write_byte(60) // width
  4420. write_byte(0) // noise
  4421. write_byte(R) // red
  4422. write_byte(G) // green
  4423. write_byte(B) // blue
  4424. write_byte(100) // brightness
  4425. write_byte(0) // speed
  4426. message_end()
  4427. }
  4428.  
  4429. metal_gibs(const Float: origin[3])
  4430. {
  4431. message_begin(get_option(OPTION_MSG_SVC_BAD) ? MSG_ALL : MSG_BROADCAST, SVC_TEMPENTITY, {0, 0, 0}, 0)
  4432. write_byte(TE_BREAKMODEL) // TE_BREAKMODEL
  4433. engfunc(EngFunc_WriteCoord,origin[0]) // x
  4434. engfunc(EngFunc_WriteCoord,origin[1]) // y
  4435. engfunc(EngFunc_WriteCoord,origin[2] + 24) // z
  4436. engfunc(EngFunc_WriteCoord,20.0) // size x
  4437. engfunc(EngFunc_WriteCoord,20.0) // size y
  4438. engfunc(EngFunc_WriteCoord,20.0) // size z
  4439. engfunc(EngFunc_WriteCoord,random_num(-50,50)) // velocity x
  4440. engfunc(EngFunc_WriteCoord,random_num(-50,50)) // velocity y
  4441. engfunc(EngFunc_WriteCoord,25.0) // velocity z
  4442. write_byte(10) // random velocity
  4443. write_short(nadebits) // model
  4444. write_byte(10) // count
  4445. write_byte(25) // life
  4446. write_byte(2) // flags: BREAK_METAL
  4447. message_end()
  4448. }
Add Comment
Please, Sign In to add comment