HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1.  
  2. #include <amxmodx>
  3. #include <fakemeta>
  4. #include <cstrike>
  5.  
  6. new cv_awp_clip, gmsgCurWeapon, weapon[33], awp_clip[33], awp_bpammo[33];
  7.  
  8. public plugin_init()
  9. {
  10. register_plugin("AWP One Shot","0.11","Avalanche");
  11.  
  12. register_event("CurWeapon","event_curweapon","b");
  13. register_event("AmmoX","event_ammox","b");
  14.  
  15. gmsgCurWeapon = get_user_msgid("CurWeapon");
  16. cv_awp_clip = register_cvar("awp_clip","1");
  17.  
  18. register_forward(FM_CmdStart,"fw_cmdstart",1);
  19. }
  20.  
  21. // reset values
  22. public client_putinserver(id)
  23. {
  24. weapon[id] = 0;
  25. awp_clip[id] = 0;
  26. awp_bpammo[id] = 0;
  27. }
  28.  
  29. // restrict clip ammo
  30. public event_curweapon(id)
  31. {
  32. new status = read_data(1);
  33.  
  34. if(status) weapon[id] = read_data(2);
  35.  
  36. // using AWP
  37. if(read_data(2) == CSW_AWP)
  38. {
  39. // current weapon
  40. if(status)
  41. {
  42. // save clip information
  43. new old_awp_clip = awp_clip[id];
  44. awp_clip[id] = read_data(3);
  45.  
  46. new max_clip = get_pcvar_num(cv_awp_clip);
  47.  
  48. // plugin enabled and must restrict ammo
  49. if(max_clip && awp_clip[id] > max_clip)
  50. {
  51. new wEnt = get_weapon_ent(id,CSW_AWP);
  52. if(pev_valid(wEnt)) cs_set_weapon_ammo(wEnt,max_clip);
  53.  
  54. // update HUD
  55. message_begin(MSG_ONE,gmsgCurWeapon,_,id);
  56. write_byte(1);
  57. write_byte(CSW_AWP);
  58. write_byte(max_clip);
  59. message_end();
  60.  
  61. // don't steal ammo from the player
  62. if(awp_bpammo[id] && awp_clip[id] > old_awp_clip)
  63. cs_set_user_bpammo(id,CSW_AWP,awp_bpammo[id]-max_clip+old_awp_clip);
  64.  
  65. awp_clip[id] = max_clip;
  66. }
  67. }
  68. else awp_clip[id] = 999;
  69. }
  70. else if(status) awp_clip[id] = 999;
  71. }
  72.  
  73. // delayed record bpammo information
  74. public event_ammox(id)
  75. {
  76. // awp ammo type is 1
  77. if(read_data(1) == 1)
  78. {
  79. static parms[2];
  80. parms[0] = id;
  81. parms[1] = read_data(2);
  82.  
  83. set_task(0.1,"record_ammo",id,parms,2);
  84. }
  85. }
  86.  
  87. // delay, because ammox is called right before curweapon
  88. public record_ammo(parms[])
  89. {
  90. awp_bpammo[parms[0]] = parms[1];
  91. }
  92.  
  93. // block reload based on new clip size
  94. public fw_cmdstart(player,uc_handle,random_seed)
  95. {
  96. new max_clip = get_pcvar_num(cv_awp_clip);
  97.  
  98. if(weapon[player] == CSW_AWP && max_clip && awp_clip[player] >= max_clip)
  99. {
  100. set_uc(uc_handle,UC_Buttons,get_uc(uc_handle,UC_Buttons) & ~IN_RELOAD);
  101. return FMRES_HANDLED;
  102. }
  103.  
  104. return FMRES_IGNORED;
  105. }
  106.  
  107. // find a player's weapon entity
  108. stock get_weapon_ent(id,wpnid=0,wpnName[]="")
  109. {
  110. // who knows what wpnName will be
  111. static newName[32];
  112.  
  113. // need to find the name
  114. if(wpnid) get_weaponname(wpnid,newName,31);
  115.  
  116. // go with what we were told
  117. else formatex(newName,31,"%s",wpnName);
  118.  
  119. // prefix it if we need to
  120. if(!equal(newName,"weapon_",7))
  121. format(newName,31,"weapon_%s",newName);
  122.  
  123. new ent;
  124. while((ent = engfunc(EngFunc_FindEntityByString,ent,"classname",newName)) && pev(ent,pev_owner) != id) {}
  125.  
  126. return ent;
  127. }
  128.