Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.15 KB | None | 0 0
  1. /* Formatleft © 2012, ConnorMcLeod
  2.  
  3. Drop All Weapons On Death is free software;
  4. you can redistribute it and/or modify it under the terms of the
  5. GNU General Public License as published by the Free Software Foundation.
  6.  
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11.  
  12. You should have received a copy of the GNU General Public License
  13. along with Drop All Weapons On Death; if not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17.  
  18. /*
  19. a p228
  20. b scout
  21. c hegrenade
  22. d xm1014
  23. e mac10
  24. f aug
  25. g smokegrenade
  26. h elite
  27. i fiveseven
  28. j ump45
  29. k sg550
  30. l galil
  31. m famas
  32. n usp
  33. o glock18
  34. p awp
  35. q mp5navy
  36. r m249
  37. s m3
  38. t m4a1
  39. u tmp
  40. v g3sg1
  41. w flashbang
  42. x deagle
  43. x sg552
  44. z ak47
  45. { p90
  46. | defuser
  47. */
  48.  
  49. #include < amxmodx >
  50. #include < amxmisc >
  51. #include < fakemeta >
  52. #include < hamsandwich >
  53.  
  54. #pragma semicolon 1
  55.  
  56. #define VERSION "0.4.0"
  57.  
  58. const MAX_ITEM_TYPES = 6; // hud item selection slots
  59. const MAX_AMMO_SLOTS = 15; // not really slots // MAX_AMMO_SLOTS // don't need to set a 32 array since max ammo index is 14
  60.  
  61. const INT_BYTES = 4;
  62. const BYTE_BITS = 8;
  63.  
  64. // "weapon_..." offsets
  65. const XO_CBASEPLAYERITEM = 4;
  66. // CBasePlayerItem
  67. const m_pPlayer = 41;
  68. const m_pNext = 42;
  69. const m_iId = 43;
  70.  
  71. // "player" offsets
  72. // Store only slots 1,2 and 4 values cause we won't drop knife and let the game drop c4
  73. // new const m_rgpPlayerItems_plr[] = {368, 369, 371}
  74. new const m_rgpPlayerItems_CBasePlayer[6] = { 367 , 368 , ... };
  75. const m_pActiveItem = 373;
  76. new const m_rgAmmo_CBasePlayer[MAX_AMMO_SLOTS] = {376,377,...};
  77.  
  78. const m_bHasDefuser = 774;
  79.  
  80. // "weaponbox" offsets
  81. const XO_CWEAPONBOX = 4;
  82. new const m_rgpPlayerItems_CWeaponBox[MAX_ITEM_TYPES] = { 34 , 35 , ... };
  83. new const m_rgiszAmmo[32] = { 40 , 41 , ... };
  84. new const m_rgAmmo_CWeaponBox[32] = { 72 , 73 , ... };
  85. const m_cAmmoTypes = 104;
  86.  
  87. new const g_iMaxAmmo[] = {
  88. 0, 30, 90, 200, 90,
  89. 32, 100, 100, 35, 52,
  90. 120, 2, 1, 1, 1
  91. };
  92.  
  93. new const g_szOnCBasePlayer_Killed[] = "OnCBasePlayer_Killed";
  94. new const weaponbox[] = "weaponbox";
  95. new iszWeaponBox;
  96.  
  97. const NADES_BS = (1<<CSW_HEGRENADE)|(1<<CSW_FLASHBANG)|(1<<CSW_SMOKEGRENADE);
  98.  
  99. new g_iszAmmoNames[sizeof(g_iMaxAmmo)];
  100.  
  101. new g_iNoSilPluginId, g_iNoSilSetModel;
  102.  
  103. new m_usResetDecals, g_iFhPlaybackEventPost;
  104.  
  105. new g_iFhSetClientKeyValueP;
  106.  
  107. new g_iFlags;
  108.  
  109. new gmsgStatusIcon;
  110.  
  111. public plugin_init()
  112. {
  113. register_plugin("Drop All Weapons On Death", VERSION, "ConnorMcLeod");
  114.  
  115. register_event("HLTV", "Event_HLTV_New_Round", "a", "1=0", "2=0");
  116.  
  117. RegisterHam(Ham_Killed, "player", g_szOnCBasePlayer_Killed);
  118. new modname[7];
  119. get_modname(modname, charsmax(modname));
  120. if( equal(modname, "czero") )
  121. {
  122. g_iFhSetClientKeyValueP = register_forward(FM_SetClientKeyValue, "OnSetClientKeyValue_P", true);
  123. }
  124.  
  125. new const szAmmoNames[][] = {
  126. "", "338Magnum", "762Nato", "556NatoBox", "556Nato",
  127. "buckshot", "45ACP", "57mm", "50AE", "357SIG",
  128. "9mm", "Flashbang", "HEGrenade", "SmokeGrenade", "C4"
  129. };
  130.  
  131. for(new i=1; i<sizeof(szAmmoNames); i++)
  132. {
  133. g_iszAmmoNames[i] = engfunc(EngFunc_AllocString, szAmmoNames[i]);
  134. }
  135.  
  136. iszWeaponBox = engfunc(EngFunc_AllocString, weaponbox);
  137.  
  138. m_usResetDecals = engfunc(EngFunc_PrecacheEvent, 1, "events/decal_reset.sc");
  139.  
  140. gmsgStatusIcon = get_user_msgid("StatusIcon");
  141.  
  142. register_concmd("death_drop_rules", "ConCmd_Rules", ADMIN_CFG, " - <flags>");
  143. }
  144.  
  145. public plugin_cfg()
  146. {
  147. g_iNoSilPluginId = is_plugin_loaded("NoSil");
  148. if( g_iNoSilPluginId > 0 )
  149. {
  150. g_iNoSilSetModel = get_func_id("fw_setmodel", g_iNoSilPluginId);
  151. }
  152. }
  153.  
  154. public ConCmd_Rules(id, level, cid)
  155. {
  156. if( cmd_access(id, level, cid, 2) )
  157. {
  158. static const iWeaponsIds[] = {CSW_P228, CSW_SCOUT, CSW_HEGRENADE, CSW_XM1014, CSW_MAC10, CSW_AUG, CSW_SMOKEGRENADE,
  159. CSW_ELITE, CSW_FIVESEVEN, CSW_UMP45, CSW_SG550, CSW_GALIL, CSW_FAMAS, CSW_USP, CSW_GLOCK18, CSW_AWP,
  160. CSW_MP5NAVY, CSW_M249, CSW_M3, CSW_M4A1, CSW_TMP, CSW_G3SG1, CSW_FLASHBANG, CSW_DEAGLE, CSW_SG552,
  161. CSW_AK47, CSW_P90, 0};
  162.  
  163. new szFlags[sizeof(iWeaponsIds)+1];
  164. read_argv(1, szFlags, charsmax(szFlags));
  165.  
  166. new i, cLetter, iVal;
  167. g_iFlags = 0;
  168.  
  169. while( (cLetter = szFlags[i++]) )
  170. {
  171. iVal = cLetter - 'a';
  172. if( 0 <= iVal < sizeof(iWeaponsIds) )
  173. {
  174. g_iFlags |= 1 << iWeaponsIds[iVal];
  175. }
  176. }
  177. }
  178. return PLUGIN_HANDLED;
  179. }
  180.  
  181. public OnSetClientKeyValue_P(id, const key[])
  182. {
  183. if( equal(key, "*bot") )
  184. {
  185. RegisterHamFromEntity(Ham_Killed, id, g_szOnCBasePlayer_Killed);
  186. unregister_forward(FM_SetClientKeyValue, g_iFhSetClientKeyValueP, true);
  187. }
  188. }
  189.  
  190. public Event_HLTV_New_Round()
  191. {
  192. if( !g_iFhPlaybackEventPost )
  193. {
  194. g_iFhPlaybackEventPost = register_forward(FM_PlaybackEvent, "OnPlaybackEvent_Post", true);
  195. }
  196. }
  197.  
  198. // proceed here at the end of CHalfLifeMultiplay::RestartRound so other weaponbox has already been removed
  199. public OnPlaybackEvent_Post(flags, pInvoker, eventindex)
  200. {
  201. if( g_iFhPlaybackEventPost && eventindex == m_usResetDecals )
  202. {
  203. unregister_forward(FM_PlaybackEvent, g_iFhPlaybackEventPost, true);
  204. g_iFhPlaybackEventPost = 0;
  205.  
  206. new iWpnBx = FM_NULLENT;
  207.  
  208. while( (iWpnBx = engfunc(EngFunc_FindEntityByString, iWpnBx, "classname", weaponbox)) > 0 )
  209. {
  210. WeaponBox_Killed(iWpnBx);
  211. }
  212. }
  213. }
  214.  
  215. public OnCBasePlayer_Killed( id )
  216. {
  217. new iActiveItem = get_pdata_cbase(id, m_pActiveItem);
  218. if( iActiveItem > 0 && pev_valid( iActiveItem ) )
  219. {
  220. if( ~NADES_BS & (1<<get_pdata_int(iActiveItem, m_iId, XO_CBASEPLAYERITEM))
  221. || ~pev(id, pev_button) & IN_ATTACK )
  222. {
  223. ExecuteHam(Ham_Item_Holster, iActiveItem, 1);
  224. iActiveItem = 0;
  225. }
  226. }
  227. else
  228. {
  229. iActiveItem = 0; // depending on windows/linux it can be -1
  230. }
  231.  
  232. if( g_iFlags & 1<<0 && get_pdata_bool(id, m_bHasDefuser) ) // defuser
  233. {
  234. set_pdata_bool(id, m_bHasDefuser, false);
  235. set_pev(id, pev_body, 0);
  236. message_begin(MSG_ONE, gmsgStatusIcon, _, id);
  237. write_byte(0);
  238. write_string("defuser");
  239. message_end();
  240. }
  241.  
  242. new iWeapon, iWeaponBox, iAmmoId, iBpAmmo, iNextWeapon;
  243. new szWeapon[20], szModel[26];
  244. new Float:flOrigin[3], Float:flAngles[3], Float:flWpnBxVelocity[3];
  245.  
  246. pev(id, pev_origin, flOrigin);
  247. pev(id, pev_angles, flAngles);
  248.  
  249. flAngles[0] = 0.0;
  250. flAngles[2] = 0.0;
  251.  
  252. new iId;
  253. for(new i=1; i<sizeof(m_rgpPlayerItems_CBasePlayer); i++)
  254. {
  255. if( i != 1 && i != 2 && i!= 4 ) // primary, secondary, nades
  256. {
  257. continue;
  258. }
  259. iWeapon = get_pdata_cbase(id, m_rgpPlayerItems_CBasePlayer[i]);
  260. while( iWeapon > 0 && pev_valid( iWeapon ) == 2 )
  261. {
  262. iNextWeapon = get_pdata_cbase(iWeapon, m_pNext, XO_CBASEPLAYERITEM);
  263. if( i == 4
  264. && iWeapon == iActiveItem // ready to launch nade
  265. && get_pdata_int(id, m_rgAmmo_CBasePlayer[ ExecuteHam(Ham_Item_PrimaryAmmoIndex, iWeapon) ]) <= 1 )
  266. {
  267. iActiveItem = 0;
  268. iWeapon = iNextWeapon;
  269. continue;
  270. }
  271.  
  272. iWeaponBox = engfunc(EngFunc_CreateNamedEntity, iszWeaponBox);
  273.  
  274. if( pev_valid(iWeaponBox) )
  275. {
  276. set_pev(iWeaponBox, pev_owner, id);
  277.  
  278. engfunc(EngFunc_SetOrigin, iWeaponBox, flOrigin);
  279.  
  280. set_pev(iWeaponBox, pev_angles, flAngles);
  281. ExecuteHamB(Ham_Spawn, iWeaponBox);
  282.  
  283. flWpnBxVelocity[0] = random_float(-250.0,250.0);
  284. flWpnBxVelocity[1] = random_float(-250.0,250.0);
  285. set_pev(iWeaponBox, pev_velocity, flWpnBxVelocity);
  286.  
  287. iId = get_pdata_int(iWeapon, m_iId, XO_CBASEPLAYERITEM);
  288. if( !WeaponBox_PackWeapon(iWeaponBox, iWeapon, id, iId) )
  289. {
  290. set_pev(iWeaponBox, pev_flags, FL_KILLME);
  291. }
  292. else
  293. {
  294. if( !iActiveItem || iWeapon != iActiveItem )
  295. {
  296. iAmmoId = ExecuteHam(Ham_Item_PrimaryAmmoIndex, iWeapon);
  297.  
  298. iBpAmmo = get_pdata_int(id, m_rgAmmo_CBasePlayer[iAmmoId]);
  299. }
  300.  
  301. set_pdata_int(id, m_rgAmmo_CBasePlayer[iAmmoId], 0);
  302.  
  303. WeaponBox_PackAmmo(iWeaponBox, iAmmoId, i == 4 ? iBpAmmo - 1 : iBpAmmo);
  304.  
  305. pev(iWeapon, pev_classname, szWeapon, charsmax(szWeapon));
  306.  
  307. if( szWeapon[10] == 'n' ) // weapon_mp5navy
  308. {
  309. // replace(szWeapon, charsmax(szWeapon), "navy", "")
  310. szWeapon[10] = EOS;
  311. }
  312. formatex(szModel, charsmax(szModel), "models/w_%s.mdl", szWeapon[7]);
  313.  
  314. engfunc(EngFunc_SetModel, iWeaponBox, szModel);
  315.  
  316. const SILENT_WPN_BS = (1<<CSW_USP)|(1<<CSW_M4A1);
  317.  
  318. if( g_iNoSilPluginId > 0
  319. && g_iNoSilSetModel > 0
  320. && (1<<iId) & SILENT_WPN_BS )
  321. {
  322. callfunc_begin_i(g_iNoSilSetModel, g_iNoSilPluginId);
  323. callfunc_push_int(iWeaponBox);
  324. callfunc_push_str(szModel);
  325. callfunc_end();
  326. }
  327.  
  328. }
  329. }
  330.  
  331. iWeapon = iNextWeapon;
  332. }
  333. }
  334. return HAM_HANDLED;
  335. }
  336.  
  337. WeaponBox_PackWeapon(iWeaponBox, iWeapon, id, iId)
  338. {
  339. if( !ExecuteHam(Ham_RemovePlayerItem, id, iWeapon) )
  340. {
  341. return 0;
  342. }
  343.  
  344. if( g_iFlags & 1 << iId )
  345. {
  346. ExecuteHam(Ham_Item_Kill, iWeapon);
  347. user_has_weapon(id, iId, 0);
  348. return 0;
  349. }
  350.  
  351. new iWeaponSlot = ExecuteHam(Ham_Item_ItemSlot, iWeapon);
  352.  
  353. set_pdata_cbase(iWeaponBox, m_rgpPlayerItems_CWeaponBox[ iWeaponSlot ], iWeapon, XO_CWEAPONBOX);
  354. set_pdata_cbase(iWeapon, m_pNext, -1, XO_CBASEPLAYERITEM);
  355.  
  356. set_pev(iWeapon, pev_spawnflags, pev(iWeapon, pev_spawnflags) | SF_NORESPAWN);
  357. set_pev(iWeapon, pev_movetype, MOVETYPE_NONE);
  358. set_pev(iWeapon, pev_solid, SOLID_NOT);
  359. set_pev(iWeapon, pev_effects, EF_NODRAW);
  360. set_pev(iWeapon, pev_modelindex, 0);
  361. set_pev(iWeapon, pev_model, 0);
  362. set_pev(iWeapon, pev_owner, iWeaponBox);
  363. set_pdata_cbase(iWeapon, m_pPlayer, -1, XO_CBASEPLAYERITEM);
  364.  
  365. return 1;
  366. }
  367.  
  368. WeaponBox_Killed(iWpnBx)
  369. {
  370. new iWeapon;
  371. for(new i=0; i<MAX_ITEM_TYPES; i++)
  372. {
  373. iWeapon = get_pdata_cbase(iWpnBx, m_rgpPlayerItems_CWeaponBox[ i ], XO_CWEAPONBOX);
  374. if( pev_valid(iWeapon) )
  375. {
  376. set_pev(iWeapon, pev_flags, FL_KILLME);
  377. }
  378. // don't implement pNext system as it's a custom weaponbox that doesn't use it
  379. }
  380. set_pev(iWpnBx, pev_flags, FL_KILLME);
  381. }
  382.  
  383. WeaponBox_PackAmmo(iWeaponBox, iAmmoId, iCount)
  384. {
  385. if( !iCount )
  386. {
  387. return;
  388. }
  389.  
  390. new iMaxCarry = g_iMaxAmmo[iAmmoId];
  391.  
  392. if( iCount > iMaxCarry )
  393. {
  394. iCount = iMaxCarry;
  395. }
  396.  
  397. set_pdata_int(iWeaponBox, m_rgiszAmmo[0], g_iszAmmoNames[iAmmoId], XO_CWEAPONBOX);
  398. set_pdata_int(iWeaponBox, m_rgAmmo_CWeaponBox[0], iCount, XO_CWEAPONBOX);
  399. }
  400.  
  401. bool:get_pdata_bool(ent, charbased_offset, intbase_linuxdiff = 5)
  402. {
  403. return !!( get_pdata_int(ent, charbased_offset / INT_BYTES, intbase_linuxdiff) & (0xFF<<((charbased_offset % INT_BYTES) * BYTE_BITS)) );
  404. }
  405.  
  406. set_pdata_char(ent, charbased_offset, value, intbase_linuxdiff = 5)
  407. {
  408. value &= 0xFF;
  409. new int_offset_value = get_pdata_int(ent, charbased_offset / INT_BYTES, intbase_linuxdiff);
  410. new bit_decal = (charbased_offset % INT_BYTES) * BYTE_BITS;
  411. int_offset_value &= ~(0xFF<<bit_decal); // clear byte
  412. int_offset_value |= value<<bit_decal;
  413. set_pdata_int(ent, charbased_offset / INT_BYTES, int_offset_value, intbase_linuxdiff);
  414. return 1;
  415. }
  416.  
  417. set_pdata_bool(ent, charbased_offset, bool:value, intbase_linuxdiff = 5)
  418. {
  419. set_pdata_char(ent, charbased_offset, _:value, intbase_linuxdiff);
  420. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement