HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /**
  2.  *
  3.  * Quake Style Switch
  4.  * by Numb
  5.  *
  6.  *
  7.  * Description:
  8.  * This plugins brings back the old feature from CS1.5 times. When you
  9.  * switch between your weapons really fast - you don't see the switch animation.
  10.  *
  11.  *
  12.  * Requires:
  13.  * FakeMeta
  14.  * HamSandWich
  15.  *
  16.  *
  17.  * Additional Info:
  18.  * + Tested in Counter-Strike 1.6 with amxmodx 1.8.2 (dev build hg21).
  19.  *
  20.  *
  21.  * Notes:
  22.  * I couldn't repeat the 'random' fast-switch glitch, cause I honestly just
  23.  * don't know how it works. So instead I made it so it would work when you
  24.  * switch fast enough (by default 750ms and that is 0.75sec)
  25.  *
  26.  *
  27.  * ChangeLog:
  28.  *
  29.  * + 1.3
  30.  * - Changed: Plugin uses less resources.
  31.  * - Fixed: Plugin wont crash the server if you use custom weapons. However their animations may not match.
  32.  *
  33.  * + 1.2
  34.  * - Fixed: Error when SWITCH_DELAY is set to 0 (when quake-style-switch is valid always).
  35.  * - Fixed: Plugin not working when picking up weapons.
  36.  *
  37.  * + 1.1
  38.  * - Fixed: Usp had wrong fast-switch (idle) animation glitches while shield was in place.
  39.  *
  40.  * + 1.0
  41.  * - First release.
  42.  *
  43.  *
  44.  * Downloads:
  45.  * Amx Mod X forums: http://forums.alliedmods.net/showthread.php?p=1193942#post1193942
  46.  *
  47. **/
  48.  
  49. // ----------------------------------------- CONFIG START -----------------------------------------
  50.  
  51. // How fast in ms you have to switch between weapons for fast-switch to work (set to 0 for "always")
  52. #define SWITCH_DELAY 750 // default: 750
  53. /*
  54. BBk
  55. www.facebook.com/groups/deathoflegend
  56. */
  57. // ------------------------------------------ CONFIG END ------------------------------------------
  58.  
  59.  
  60. #include <amxmodx>
  61. #include <fakemeta>
  62. #include <hamsandwich>
  63.  
  64. #define PLUGIN_NAME "Fegyvervaltas animacio nelkul"
  65. #define PLUGIN_VERSION "1.3"
  66. #define PLUGIN_AUTHOR "Numb"
  67.  
  68. #define m_pPlayer 41 // (weapon_*) owner entity
  69. #define m_iId 43 // (weapon_*) type of weapon CSW_
  70. #define m_bSilencerOn 74 // (weapon_*) in what state weapon is on
  71. #define m_flDecreaseShotsFired 76 // (weapon_*) ??? right after Deploy has same value as get_gametime()
  72. #define WPN_STATE_USP_SILEN (1<<0)
  73. #define WPN_STATE_M4A1_SILEN (1<<2)
  74.  
  75. #define m_pActiveItem 373 // (player) active weapon
  76. #define PDShieldState 510 // (player) some extra information about the player
  77. #define SHIELD_STATE_EXISTS (1<<24)
  78.  
  79.  
  80. #if SWITCH_DELAY > 0
  81. new Float:g_fLastSwitched[33];
  82. new Float:g_fSwitchDelay;
  83. #endif
  84.  
  85. public plugin_init()
  86. {
  87. register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
  88.  
  89. RegisterHam(Ham_Item_Deploy, "weapon_knife", "Ham_Item_Deploy_Post", 1); // I know, using event CurWeapon looks better,
  90. RegisterHam(Ham_Item_Deploy, "weapon_glock18", "Ham_Item_Deploy_Post", 1); // but this one doesn't loop. Plus in CurWeapon
  91. RegisterHam(Ham_Item_Deploy, "weapon_usp", "Ham_Item_Deploy_Post", 1); // event last send info may be not "active",
  92. RegisterHam(Ham_Item_Deploy, "weapon_deagle", "Ham_Item_Deploy_Post", 1); // so animation won't work in that case.
  93. RegisterHam(Ham_Item_Deploy, "weapon_p228", "Ham_Item_Deploy_Post", 1);
  94. RegisterHam(Ham_Item_Deploy, "weapon_elite", "Ham_Item_Deploy_Post", 1);
  95. RegisterHam(Ham_Item_Deploy, "weapon_fiveseven", "Ham_Item_Deploy_Post", 1);
  96. RegisterHam(Ham_Item_Deploy, "weapon_m3", "Ham_Item_Deploy_Post", 1);
  97. RegisterHam(Ham_Item_Deploy, "weapon_xm1014", "Ham_Item_Deploy_Post", 1);
  98. RegisterHam(Ham_Item_Deploy, "weapon_mp5navy", "Ham_Item_Deploy_Post", 1);
  99. RegisterHam(Ham_Item_Deploy, "weapon_mac10", "Ham_Item_Deploy_Post", 1);
  100. RegisterHam(Ham_Item_Deploy, "weapon_tmp", "Ham_Item_Deploy_Post", 1);
  101. RegisterHam(Ham_Item_Deploy, "weapon_p90", "Ham_Item_Deploy_Post", 1);
  102. RegisterHam(Ham_Item_Deploy, "weapon_ump45", "Ham_Item_Deploy_Post", 1);
  103. RegisterHam(Ham_Item_Deploy, "weapon_galil", "Ham_Item_Deploy_Post", 1);
  104. RegisterHam(Ham_Item_Deploy, "weapon_famas", "Ham_Item_Deploy_Post", 1);
  105. RegisterHam(Ham_Item_Deploy, "weapon_ak47", "Ham_Item_Deploy_Post", 1);
  106. RegisterHam(Ham_Item_Deploy, "weapon_m4a1", "Ham_Item_Deploy_Post", 1);
  107. RegisterHam(Ham_Item_Deploy, "weapon_sg552", "Ham_Item_Deploy_Post", 1);
  108. RegisterHam(Ham_Item_Deploy, "weapon_aug", "Ham_Item_Deploy_Post", 1);
  109. RegisterHam(Ham_Item_Deploy, "weapon_g3sg1", "Ham_Item_Deploy_Post", 1);
  110. RegisterHam(Ham_Item_Deploy, "weapon_sg550", "Ham_Item_Deploy_Post", 1);
  111. RegisterHam(Ham_Item_Deploy, "weapon_scout", "Ham_Item_Deploy_Post", 1);
  112. RegisterHam(Ham_Item_Deploy, "weapon_awp", "Ham_Item_Deploy_Post", 1);
  113. RegisterHam(Ham_Item_Deploy, "weapon_m249", "Ham_Item_Deploy_Post", 1);
  114. RegisterHam(Ham_Item_Deploy, "weapon_hegrenade", "Ham_Item_Deploy_Post", 1);
  115. RegisterHam(Ham_Item_Deploy, "weapon_flashbang", "Ham_Item_Deploy_Post", 1);
  116. RegisterHam(Ham_Item_Deploy, "weapon_smokegrenade", "Ham_Item_Deploy_Post", 1);
  117. RegisterHam(Ham_Item_Deploy, "weapon_c4", "Ham_Item_Deploy_Post", 1);
  118.  
  119. #if SWITCH_DELAY > 0
  120. g_fSwitchDelay = (float(SWITCH_DELAY)*0.001); // I don't want to do this function each time someone switches weapons (saving CPU)
  121. #endif
  122. }
  123.  
  124. #if SWITCH_DELAY > 0
  125. public client_connect(iPlrId)
  126. g_fLastSwitched[iPlrId] = 0.0; // reset time of last switch
  127. #endif
  128.  
  129. public Ham_Item_Deploy_Post(iEnt)
  130. {
  131. if( !pev_valid(iEnt) ) // it is possible honestly (I had errors cause of ignoring it - other plugins and/or engine...)
  132. return HAM_IGNORED;
  133.  
  134. new iPlrId = get_pdata_cbase(iEnt, m_pPlayer, 4); // same here
  135. if( !is_user_alive(iPlrId) )
  136. return HAM_IGNORED;
  137.  
  138. if( iEnt!=get_pdata_cbase(iPlrId, m_pActiveItem, 5) ) // some other plugin can silently change weapons
  139. return HAM_IGNORED;
  140.  
  141. weapon_switched(iPlrId, iEnt, get_pdata_int(iEnt, m_iId, 4)); // we are now sure that weapons are switched
  142.  
  143. return HAM_IGNORED;
  144. }
  145.  
  146. public weapon_switched(iPlrId, iEnt, iWpnType)
  147. {
  148. #if SWITCH_DELAY > 0
  149. new Float:fGameTime = get_gametime();
  150. if( get_pdata_float(iEnt, m_flDecreaseShotsFired, 4)==fGameTime ) // did player really switched weapons _NOW_?
  151. {
  152. if( g_fLastSwitched[iPlrId]>fGameTime ) // check time - should this switch be quake-style-switch ?
  153. configurate_switch(iPlrId, iWpnType, iEnt);
  154. g_fLastSwitched[iPlrId] = (fGameTime+g_fSwitchDelay);
  155. }
  156. #else
  157. if( get_pdata_float(iEnt, m_flDecreaseShotsFired, 4)==get_gametime() ) // did player really switched weapons _NOW_?
  158. configurate_switch(iPlrId, iWpnType, iEnt);
  159. #endif
  160. }
  161.  
  162. configurate_switch(iPlrId, iWpnType, iEnt) // and here is the part where we change the animation
  163. {
  164. message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, iPlrId); // I also use msg cause of ping reasons
  165. switch( iWpnType ) // I need this for usp and m4a1 silencer support
  166. {
  167. case CSW_USP: write_byte_and_set_anim(iPlrId, iEnt, true);
  168. case CSW_M4A1: write_byte_and_set_anim(iPlrId, iEnt);
  169. default: write_byte_and_set_anim(iPlrId); // all other weapons (don't blame me if custom weapon animations wont match)
  170. }
  171. write_byte(pev(iPlrId, pev_body));
  172. message_end();
  173. }
  174.  
  175. write_byte_and_set_anim(iPlrId, iEnt=0, bool:bIsWeaponUsp=false) // so lets find out what animation id we need
  176. {
  177. if( iEnt ) // player switched to usp or m4a1
  178. {
  179. if( bIsWeaponUsp ) // player switched to usp
  180. {
  181. if( iEnt && (get_pdata_int(iEnt, m_bSilencerOn, 4)&WPN_STATE_USP_SILEN || get_pdata_int(iPlrId, PDShieldState, 5)&SHIELD_STATE_EXISTS) )
  182. {
  183. write_byte(0);
  184. set_pev(iPlrId, pev_weaponanim, 0); // so it silenced and there is no shield
  185. }
  186. else
  187. {
  188. write_byte(8);
  189. set_pev(iPlrId, pev_weaponanim, 8); // there's a shield or it's not silenced
  190. }
  191. }
  192. else // player switched to m4a1
  193. {
  194. if( iEnt && get_pdata_int(iEnt, m_bSilencerOn, 4)&WPN_STATE_M4A1_SILEN ) // so is it silenced
  195. {
  196. write_byte(0);
  197. set_pev(iPlrId, pev_weaponanim, 0);
  198. }
  199. else // or is it...
  200. {
  201. write_byte(7);
  202. set_pev(iPlrId, pev_weaponanim, 7);
  203. }
  204. }
  205. }
  206. else // just pass the idle animation and leave me alone about the "ow, but my custom pink bazooka has a wrong animation (cry)..." - I must say, I really don't care.
  207. {
  208. write_byte(0);
  209. set_pev(iPlrId, pev_weaponanim, 0)
  210. }
  211. }
  212.