HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2.  
  3. #include <hamsandwich>
  4. #include <csx>
  5.  
  6. #include <fakemeta_stocks>
  7.  
  8. //Definitions
  9. #define VERSION "0.2"
  10. #define IsPlayer(%1) (1 <= %1 <= g_iMaxPlayers && is_user_alive(%1))
  11. #define ResetLen(%1) (%1 = "")
  12.  
  13. //Enums
  14. enum {
  15. FLASHBANG,
  16. HEGRENADE,
  17. SMOKE
  18. };
  19.  
  20. enum _:eModels{
  21. VIEW,
  22. PLAYER,
  23. WORLD
  24. };
  25.  
  26. //Booleans
  27. new bool:g_bIsTouched[0x21][0x200];
  28.  
  29. //Floats
  30. new Float:g_fMultiplier[0x21];
  31. new Float:g_fValue;
  32.  
  33. //Strings
  34. new g_sMessage[0x21][0x10];
  35.  
  36. //Integers
  37. new g_pCvarDamage;
  38. new g_pCvarFade;
  39.  
  40. new g_mDeath;
  41. new g_mScreenShake;
  42. new g_mSendAudio;
  43. new g_mScreenFade;
  44.  
  45. new g_iMaxPlayers;
  46.  
  47. new g_sSprite;
  48.  
  49. //Constants
  50. new const g_sDownloadableContent[eModels + 2][] = {
  51. "models/flashbangs_can_kill/v_model.mdl",
  52. "models/flashbangs_can_kill/p_model.mdl",
  53. "models/flashbangs_can_kill/w_model.mdl",
  54. "sprites/flashbangs_can_kill/smoczek.spr",
  55. "flashbangs_can_kill/rzut.wav"
  56. };
  57.  
  58. new const g_iTaskId = 0x539;
  59. new const g_iThrownId = 0x540;
  60.  
  61. //Unused atm, maybe in next update
  62. #pragma unused g_iThrownId
  63.  
  64. public plugin_init() {
  65. //Register the plugin
  66. register_plugin("Flashbangs can kill", VERSION, "diablix")
  67.  
  68. //Define the variables
  69. g_pCvarDamage = register_cvar("flashbang_damage", "5");
  70. g_pCvarFade = register_cvar("flashbang_fade", "1");
  71.  
  72. g_mDeath = get_user_msgid("DeathMsg");
  73. g_mScreenShake = get_user_msgid("ScreenShake");
  74. g_mSendAudio = get_user_msgid("SendAudio");
  75. g_mScreenFade = get_user_msgid("ScreenFade");
  76.  
  77. g_iMaxPlayers = get_maxplayers();
  78.  
  79. g_fValue = float( get_pcvar_num(g_pCvarDamage) );
  80.  
  81. //Register messages, forward & events
  82. register_message(g_mSendAudio, "msgSendAudio");
  83. register_message(g_mScreenFade, "msgScreenFade");
  84.  
  85. register_forward(FM_Touch, "fwTouch");
  86. register_forward(FM_SetModel, "fwSetModel");
  87.  
  88. register_event("CurWeapon", "eventCurWeapon", "be");
  89.  
  90. RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_flashbang", "fwPrimAttackPost", 1);
  91. }
  92.  
  93. public plugin_precache(){
  94. //static
  95. static i;
  96.  
  97. //Precache the whole content (fakemeta way)
  98. for(i = 0 ; i < eModels ; i ++)
  99. engfunc(EngFunc_PrecacheModel, g_sDownloadableContent[i]);
  100.  
  101. engfunc(EngFunc_PrecacheSound, g_sDownloadableContent[4]);
  102. g_sSprite = engfunc(EngFunc_PrecacheModel, g_sDownloadableContent[3]);
  103. }
  104.  
  105. public eventCurWeapon(id){
  106. //Reset shake & aim multiplier
  107. g_fMultiplier[id] = 0.0;
  108.  
  109. //Clear the message
  110. ResetLen(g_sMessage[id]);
  111.  
  112. //Check for flashbang model
  113. new sModel[0x40];
  114. pev(id, pev_viewmodel2, sModel, sizeof sModel - 1);
  115. set_pev(id, pev_viewmodel2, equal(sModel, "models/v_flashbang.mdl") ? g_sDownloadableContent[VIEW] : sModel);
  116.  
  117. pev(id, pev_weaponmodel2, sModel, sizeof sModel - 1);
  118. set_pev(id, pev_weaponmodel2, equal(sModel, "models/p_flashbang.mdl") ? g_sDownloadableContent[PLAYER] : sModel);
  119. }
  120.  
  121. public grenade_throw(iPlayer, iEntity, iGrenadeIndex){
  122. if(iGrenadeIndex == CSW_FLASHBANG){
  123. //Add trail if thrown grenade is flashbang
  124. message_begin(MSG_BROADCAST, SVC_TEMPENTITY);//engfunc(EngFunc_MessageBegin, MSG_ALL, SVC_TEMPENTITY); /*FAKEMETA WAY*/
  125. write_byte(0x16);
  126. write_short(iEntity);
  127. write_short(g_sSprite);
  128. write_byte(0x2D);
  129. write_byte(0x4);
  130. write_byte(0xFF);
  131. write_byte(0xFF);
  132. write_byte(0xFF);
  133. write_byte(0xFF);
  134. message_end();
  135.  
  136. //Also emit cool sound
  137. emit_sound(iPlayer, CHAN_STATIC, g_sDownloadableContent[4], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
  138. }
  139. }
  140.  
  141. public fwPrimAttackPost(iEnt){
  142. //static ofc
  143. static iOwner;
  144. //Get entity's owner
  145. iOwner = pev(iEnt, pev_owner);
  146.  
  147. //Lets modify multiplier
  148. g_fMultiplier[iOwner] = floatround(g_fMultiplier[iOwner]) >= 0x10 ? g_fMultiplier[iOwner] : g_fMultiplier[iOwner] + 0.01;
  149.  
  150. //Float into integer
  151. new iAmt = floatround(g_fMultiplier[iOwner]);
  152.  
  153. //While iAmt >= 1
  154. while(iAmt){
  155. //Decrease the iAmt
  156. iAmt--;
  157. //Add '|' char into message (Yes, power bar)
  158. add(g_sMessage[iOwner], 0xF, "|");
  159. }
  160.  
  161. //Show power bar
  162. set_hudmessage(0xFF, strlen(g_sMessage[iOwner]) == 0xF ? 0x20 : 0xFF, strlen(g_sMessage[iOwner]) == 0xF ? 0 : 0xFF, 0.52, 0.45, 0, 0.1, 0.1, 0.2, 0.2, -1);
  163. show_hudmessage(iOwner, "POWER: [%s]", g_sMessage[iOwner]);
  164.  
  165. //Write ScreenShake message depending on user's multiplier
  166. message_begin(MSG_ONE, g_mScreenShake, {0,0,0}, iOwner);
  167. write_short(floatround(4096.0 * g_fMultiplier[iOwner]));
  168. write_short(floatround(4096.0));
  169. write_short(floatround(4096.0 * g_fMultiplier[iOwner]));
  170. message_end();
  171. }
  172.  
  173. public fwTouch(iToucher, iTouched){
  174. //Get grenade type by pdata offset (LINUX)
  175. new iGrenadeType = (get_pdata_int(iToucher, 114) & 3);
  176.  
  177. //String
  178. new sClass[0x40];
  179. //Add entity's classname into array
  180. pev(iToucher, pev_classname, sClass, sizeof sClass - 1);
  181.  
  182. if(equal(sClass, "grenade") && iGrenadeType == FLASHBANG){
  183. //Get the grenade's owner
  184. new iOwner = pev(iToucher, pev_owner);
  185.  
  186. //Remove friendly fire effect
  187. if(get_user_team(iOwner) != get_user_team(iTouched)){
  188. if(IsPlayer(iTouched) && !g_bIsTouched[iTouched][iToucher]){
  189. //Recoil effect
  190. set_pev(iTouched, pev_punchangle, {0.55, 1.0, 0.0});
  191.  
  192. //Write some screenshake for victim
  193. message_begin(MSG_ONE, g_mScreenShake, {0,0,0}, iTouched);//engfunc(EngFunc_MessageBegin, MSG_ONE, g_mScreenShake, {0,0,0}, iTouched);
  194. write_short(0xC33C);
  195. write_short(0x7A8);
  196. write_short(0xC33C);
  197. message_end();
  198.  
  199. //Ezcute damage to victim
  200. Diablix_ExecuteDamage(iOwner, iTouched, g_fValue);
  201.  
  202. //Victim has been touched by grenade's id
  203. g_bIsTouched[iTouched][iToucher] = true;
  204.  
  205. //Remove task if it exists
  206. if((task_exists(iTouched + g_iTaskId))) remove_task(iTouched + g_iTaskId);
  207.  
  208.  
  209. //Remove all the entities user's touching
  210. set_task(1.0, "taskTouched", iTouched + g_iTaskId);
  211. }
  212. }
  213. }
  214. }
  215.  
  216. public fwSetModel(iEntity, sModel[]){
  217. //Lets replace world model
  218. if(equal(sModel,"models/w_flashbang.mdl")){
  219. //Model changed succesfully
  220. engfunc(EngFunc_SetModel, iEntity, g_sDownloadableContent[WORLD]);
  221.  
  222. //Return supercede and stop the function
  223. return FMRES_SUPERCEDE;
  224. }
  225.  
  226. return FMRES_IGNORED;
  227. }
  228.  
  229. public msgScreenFade(iMessageID, iMessageDestinity, iEntity){
  230. //Make sure screenfade was made by flashbang
  231. if(get_msg_arg_int(4) == 0xFF && get_msg_arg_int(5) == 0xFF && get_msg_arg_int(6) == 0xFF && get_msg_arg_int(7) > 0xC7){
  232. //if flashbang_fade < 1 block message
  233. if(!(get_pcvar_num(g_pCvarFade)))
  234. return 1;
  235. }
  236. return 0;
  237. }
  238.  
  239. public msgSendAudio(iMessageID, iMessageDestinity, iEntity){
  240. if((get_msg_argtype(2) == ARG_STRING)){
  241. //String
  242. new sArg[0x40];
  243.  
  244. //Add audio's type into array
  245. get_msg_arg_string(2, sArg, sizeof sArg - 1);
  246.  
  247. //Block the fire in the hole message
  248. if(equal(sArg ,"%!MRAD_FIREINHOLE"))
  249. return 1; //Succes
  250. }
  251. return 0; // Continue
  252. }
  253.  
  254. public taskTouched(iTouched){
  255. //Change the temp id into normal id
  256. new id = (iTouched - g_iTaskId);
  257.  
  258. //static:)
  259. static i;
  260.  
  261. //Loop, reset variable
  262. for(i = 0 ; i < 0x200 ; i ++){
  263. //If boolean is set to false, continue
  264. if(!g_bIsTouched[id][i]) continue;
  265. // Flase = !False (true)
  266. g_bIsTouched[id][i] = !g_bIsTouched[id][i];
  267. }
  268. }
  269.  
  270. //fakedamage + some addons by me to write new deathmsg and remove suicide icon
  271. stock Diablix_ExecuteDamage(iAttacker, iVictim, Float:fDmg){
  272. //Float, String, String, Integer
  273. new Float:fHealth, sClassname[0x40], sValue[0x20], iEntity;
  274. //Classname into Array
  275. add(sClassname, sizeof sClassname - 1, "trigger_hurt");
  276. //Health (Float) into variable
  277. pev(iVictim, pev_health, fHealth);
  278.  
  279. //Block the deathmsg
  280. set_msg_block(g_mDeath, BLOCK_ONCE);
  281.  
  282. //Create the new entity
  283. iEntity = engfunc( EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, sClassname) );
  284.  
  285. //Instead of pev_valid()
  286. assert iEntity;
  287.  
  288. //Set the damage amount
  289. float_to_str(fDmg * 2, sValue, sizeof sValue - 1);
  290. fm_set_kvd(iEntity, "dmg", sValue, sClassname);
  291.  
  292. //Set the damagetype
  293. num_to_str(DMG_ALWAYSGIB, sValue, sizeof sValue - 1);
  294. fm_set_kvd(iEntity, "damagetype", sValue, sClassname);
  295.  
  296. //Set the origin (fake origin ofc)
  297. fm_set_kvd(iEntity, "origin", "8192 8192 8192", sClassname);
  298.  
  299. //Spawn the entity
  300. dllfunc(DLLFunc_Spawn, iEntity);
  301.  
  302. //Set local classname
  303. set_pev(iEntity, pev_classname, "flashbang");
  304.  
  305. //Make "fake touch"
  306. dllfunc(DLLFunc_Touch, iEntity, iVictim);
  307.  
  308. //If succesfully, remove "fake" entity
  309. engfunc(EngFunc_RemoveEntity, iEntity);
  310.  
  311. //Unlock the deathmsg
  312. set_msg_block(g_mDeath, BLOCK_NOT);
  313.  
  314. //And create the new one if it has to
  315. if(floatround((fHealth - fDmg)) < 1){
  316. make_deathmsg(iAttacker, iVictim, 0, "");
  317. //Also add frag
  318. new Float:fFrags;
  319. pev(iAttacker, pev_frags, fFrags);
  320.  
  321. set_pev(iAttacker, pev_frags, ( fFrags + 1.0) );
  322. }
  323. }
  324.  
  325. //set_kvd by fakemeta way
  326. stock fm_set_kvd(entity, const key[], const value[], const classname[] = "") {
  327. if (classname[0])
  328. set_kvd(0, KV_ClassName, classname);
  329. else {
  330. new class[0x20];
  331. pev(entity, pev_classname, class, sizeof class - 1);
  332. set_kvd(0, KV_ClassName, class);
  333. }
  334.  
  335. set_kvd(0, KV_KeyName, key);
  336. set_kvd(0, KV_Value, value);
  337. set_kvd(0, KV_fHandled, 0);
  338.  
  339. return dllfunc(DLLFunc_KeyValue, entity, 0);
  340. }
  341.