HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /* Plugin generated by AMXX-Studio */
  2.  
  3. #include <amxmodx>
  4. #include <amxmisc>
  5. #include <cstrike>
  6. #include <fun>
  7. #include <fakemeta>
  8. #include <engine>
  9. #include <csx>
  10.  
  11. #define PLUGIN "Decoy Grenade"
  12. #define VERSION "1.0.4"
  13. #define AUTHOR "Kia"
  14.  
  15. // ===============================================================================
  16. // Editing begins here
  17. // ===============================================================================
  18.  
  19. // Time in Seconds how long the decoy grenade should make sounds //Meddig jatsza le a hangot
  20. #define DECOY_FULL_TIME 14.5
  21.  
  22. // Time in Seconds when decoy should start after default explosion //Meddig lehesen hallani a dobasi hangot
  23. #define DECOY_FIRST_DELAY 1.5
  24.  
  25. // Maximum delay between two sounds //Meddig lehessen hallani a 2. hangot
  26. #define DECOY_MAX_DELAY 1.6
  27.  
  28. // Price of Decoy Grenade in $ // Mennyibe keruljon a granat
  29. #define DECOY_PRICE 500
  30.  
  31. // ===============================================================================
  32. // and stops here. DO NOT MODIFY BELOW UNLESS YOU KNOW WHAT YOU'RE DOING
  33. // ===============================================================================
  34.  
  35. // ===============================================================================
  36. // Variables
  37. // ===============================================================================
  38.  
  39. #define TASK_ID_SOUND 9919
  40.  
  41. /* Consts */
  42.  
  43. new const g_szWeaponConsts[][] =
  44. {
  45. 0, // NULL
  46. CSW_P228,
  47. 0, // SHIELD
  48. CSW_SCOUT,
  49. 0, // HEGRENADE
  50. CSW_XM1014,
  51. 0, // C4
  52. CSW_MAC10,
  53. CSW_AUG,
  54. 0, // SMOKEGRENADE
  55. CSW_ELITE,
  56. CSW_FIVESEVEN,
  57. CSW_UMP45,
  58. CSW_SG550,
  59. CSW_GALIL,
  60. CSW_FAMAS,
  61. CSW_USP,
  62. CSW_GLOCK18,
  63. CSW_AWP,
  64. CSW_MP5NAVY,
  65. CSW_M249,
  66. CSW_M3,
  67. CSW_M4A1,
  68. CSW_TMP,
  69. CSW_G3SG1,
  70. 0, // FLASHBANG
  71. CSW_DEAGLE,
  72. CSW_SG552,
  73. CSW_AK47,
  74. 0, // KNIFE
  75. CSW_P90
  76. }
  77.  
  78. new const g_szWeaponSounds[sizeof(g_szWeaponConsts)][] =
  79. {
  80. "",
  81. "p228-1.wav",
  82. "",
  83. "scout_fire-1.wav",
  84. "",
  85. "xm1014-1.wav",
  86. "",
  87. "mac10-1.wav",
  88. "aug-1.wav",
  89. "",
  90. "elite_fire.wav",
  91. "fiveseven-1.wav",
  92. "ump45-1.wav",
  93. "sg550-1.wav",
  94. "galil-1.wav",
  95. "famas-1.wav",
  96. "usp1.wav",
  97. "glock18-1.wav",
  98. "awp1.wav",
  99. "mp5-1.wav",
  100. "m249-1.wav",
  101. "m3-1.wav",
  102. "m4a1-1.wav",
  103. "tmp-1.wav",
  104. "g3sg1-1.wav",
  105. "",
  106. "deagle-1.wav",
  107. "sg552-1.wav",
  108. "ak47-1.wav",
  109. "",
  110. "p90-1.wav"
  111. }
  112.  
  113. /* Integer */
  114.  
  115. new g_iEnt[33]
  116. new g_iEventIDSmoke
  117.  
  118. /* Boolean */
  119.  
  120. new bool:g_bHasDecoy[33]
  121.  
  122. /* Floats */
  123.  
  124. new Float:g_flDecoyOrigin[33][3]
  125.  
  126. /* Strings */
  127.  
  128. new g_szWeaponSound[33][33]
  129.  
  130. new HandleFwdPlaybackEvent;
  131. new Array:HandleGrenadePlayerIdQueue;
  132.  
  133. // ===============================================================================
  134. // plugin_init
  135. // ===============================================================================
  136.  
  137. public plugin_init()
  138. {
  139. register_plugin(PLUGIN, VERSION, AUTHOR)
  140.  
  141. /* ClCmds */
  142.  
  143. register_clcmd("say /decoy", "ClCmd_Decoy")
  144. register_clcmd("say_team /decoy", "ClCmd_Decoy")
  145.  
  146. /* Stuff */
  147.  
  148. g_iEventIDSmoke = engfunc(EngFunc_PrecacheEvent, 1, "events/createsmoke.sc")
  149. }
  150.  
  151. // ===============================================================================
  152. // client_putinserver - Called when a player joins the Server
  153. // ===============================================================================
  154.  
  155. public client_putinserver(id)
  156. {
  157. g_iEnt[id] = 0
  158. g_bHasDecoy[id] = false
  159. }
  160.  
  161. // ===============================================================================
  162. // ClCmd_Decoy - Called when a player types /decoy in the chat
  163. // ===============================================================================
  164.  
  165. public ClCmd_Decoy(id)
  166. {
  167. // If we have not enough money or if we already have a decoy grenade, block the payment.
  168. if(cs_get_user_money(id) < DECOY_PRICE || g_bHasDecoy[id] || !is_user_alive(id))
  169. return PLUGIN_HANDLED
  170.  
  171. // If the player has no Smokegrenade, give him one.
  172. if(!(user_has_weapon(id, CSW_SMOKEGRENADE)))
  173. give_item(id, "weapon_smokegrenade")
  174.  
  175. // Taking the price
  176. cs_set_user_money(id, cs_get_user_money(id) - DECOY_PRICE, 1)
  177.  
  178. // Telling the plugin that the player has a decoy.
  179. g_bHasDecoy[id] = true
  180.  
  181. return PLUGIN_HANDLED
  182. }
  183.  
  184. // ===============================================================================
  185. // Thanks to Arkshine
  186. // ===============================================================================
  187.  
  188. public grenade_throw( player, grenade, weaponId )
  189. {
  190. if( weaponId == CSW_SMOKEGRENADE && g_bHasDecoy[player] )
  191. {
  192. if( HandleGrenadePlayerIdQueue == Invalid_Array )
  193. {
  194. HandleGrenadePlayerIdQueue = ArrayCreate();
  195. }
  196.  
  197. ArrayPushCell( HandleGrenadePlayerIdQueue, player );
  198.  
  199. if( !HandleFwdPlaybackEvent )
  200. {
  201. HandleFwdPlaybackEvent = register_forward( FM_PlaybackEvent, "OnPlaybackEvent" );
  202. }
  203. }
  204. }
  205.  
  206. public OnPlaybackEvent( const flags, const client, const eventIndex, const Float:delay, const Float:origin[3] )
  207. {
  208. new player = ArrayGetCell( HandleGrenadePlayerIdQueue, 0 );
  209. if( HandleFwdPlaybackEvent && g_iEventIDSmoke == eventIndex && g_bHasDecoy[player] )
  210. {
  211. ArrayDeleteItem( HandleGrenadePlayerIdQueue, 0 );
  212.  
  213. if( !ArraySize( HandleGrenadePlayerIdQueue ) )
  214. {
  215. ArrayDestroy( HandleGrenadePlayerIdQueue );
  216.  
  217. unregister_forward( FM_PlaybackEvent, HandleFwdPlaybackEvent );
  218. HandleFwdPlaybackEvent = 0;
  219. }
  220.  
  221. g_flDecoyOrigin[player] = origin
  222. set_task(DECOY_FIRST_DELAY, "ExecuteDecoy", player)
  223. }
  224. }
  225.  
  226. // ===============================================================================
  227. // ExecuteDecoy - Responsible for playing the sounds etc.
  228. // ===============================================================================
  229.  
  230. public ExecuteDecoy(id)
  231. {
  232. // Getting the players weapon
  233. new iWeapon = get_user_weapon(id)
  234.  
  235. // Finding the right sound of the weapon
  236. for(new i = 0; i < sizeof(g_szWeaponSounds); i++)
  237. {
  238. //if(equali(iWeapon, g_szWeaponRealnames[i]))
  239. if(iWeapon == g_szWeaponConsts[i][0])
  240. formatex(g_szWeaponSound[id], charsmax(g_szWeaponSound), g_szWeaponSounds[i])
  241. else
  242. continue
  243. }
  244.  
  245. // Starting the sounds
  246. StartWeaponSounds(id)
  247. }
  248.  
  249. // ===============================================================================
  250. // StartWeaponSounds - Playing the sounds
  251. // ===============================================================================
  252.  
  253. public StartWeaponSounds(id)
  254. {
  255. // Creating a Entity which plays the sound
  256. new iEnt = create_entity("info_target")
  257. g_iEnt[id] = iEnt
  258.  
  259. // Setting its position
  260. entity_set_origin(g_iEnt[id], g_flDecoyOrigin[id])
  261.  
  262. // Playing the first sound
  263. set_task(0.1, "PlayASound", id + TASK_ID_SOUND)
  264.  
  265. // Setting the time when it should stop playing sounds
  266. set_task(DECOY_FULL_TIME, "StopDecoy", id)
  267. }
  268.  
  269. public PlayASound(id)
  270. {
  271. // Getting the actual player
  272. id -= TASK_ID_SOUND
  273.  
  274. // Getting full path
  275. new szSoundPath[64]
  276. formatex(szSoundPath, charsmax(szSoundPath), "weapons/%s", g_szWeaponSound[id])
  277.  
  278. // Playing the Sound
  279. emit_sound(g_iEnt[id], CHAN_ITEM, szSoundPath, VOL_NORM, ATTN_NONE, 0, PITCH_NORM)
  280.  
  281. // Preparing next one
  282. set_task(random_float(0.1, DECOY_MAX_DELAY), "StartWeaponSounds", id)
  283. }
  284.  
  285. public StopDecoy(id)
  286. {
  287. // Removing Task which is playing sounds
  288. if(task_exists(id + TASK_ID_SOUND))
  289. remove_task(id + TASK_ID_SOUND)
  290.  
  291. // Disabling Decoy for player
  292. g_bHasDecoy[id] = false
  293.  
  294. // Remove the Entity
  295. remove_entity(g_iEnt[id])
  296. }
  297.  
  298.  
  299.  
  300.  
  301.