Advertisement
Guest User

Untitled

a guest
Aug 30th, 2020 (edited)
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.47 KB | None | 0 0
  1. /*
  2. ================================================
  3. Counter-Strike Weapons System Mod v1.4.3 [CSWS1]
  4. ================================================
  5. 2017
  6.  
  7. This source code falls under the GNU General Public License.
  8. (https://www.gnu.org/licenses/gpl-3.0.en.html)
  9.  
  10. Additionally, you are allowed to modify, improve or build
  11. upon the code but under NO circumstances are you allowed to
  12. sell, trade, or receive any compensation for the source code
  13. whatsoever and should freely share said code to anyone,
  14. modified or otherwise.
  15.  
  16. Description:
  17. ============
  18. The CSWS script is built upon the endeavor
  19. of adding an extra weapon that behaves like
  20. a real CS 1.6 weapon in every way while
  21. providing optimum performance. If you want
  22. to improve the code feel free to do so and
  23. share it with everyone.
  24.  
  25. Credits:
  26. ========
  27. Sneaky.amxx - original weapons code
  28. dias - original weapons code
  29. MeRcyLeZZ - price mechanic
  30. Arkshine - HUD sprites replacement
  31. HamletEagle - optimization
  32. edon1337 - optimization
  33. */
  34.  
  35. #include <amxmodx>
  36. #include <cstrike>
  37. #include <engine>
  38. #include <fakemeta>
  39. #include <fun>
  40. #include <hamsandwich>
  41. #include <xs>
  42.  
  43. #define DAMAGE 13
  44. #define CLOSE_DAMAGE 150
  45. #define WEAPON_RANGE 600
  46. #define CLOSE_RANGE 250
  47. #define CLIP 7
  48. #define BPAMMO 32
  49. #define RATEOFIRE 0.96
  50. #define RECOIL 2.0
  51. #define WALKSPEED 210.0 // Devre disi
  52. #define PRICE 1200
  53. #define TEAM 1
  54. #define BASEWPN_PRICE 1700
  55. #define BOT_BUY_CHANCE 2
  56.  
  57. #define SHOOT_ANIM random_num(1, 2)
  58. #define RELOAD_START 5
  59. #define RELOAD_INSERT 3
  60. #define RELOAD_END 4
  61. #define DRAW_ANIM 6
  62. #define INSPECT_ANIM 7
  63. #define BODY_NUM 0
  64.  
  65. #define WEAPON_SECRETCODE 194156
  66.  
  67. // MACROS
  68. #define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
  69. #define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
  70. #define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))
  71.  
  72. new const PLUGIN[] = "CS:GO Sawed-Off Shotgun";
  73. new const VERSION[] = "1.6.1";
  74. new const CSWS_VER[] = "1.4.3";
  75. new const DATE[] = "1 December 2017";
  76.  
  77. new const P_MODEL[] = "models/csgo_ports/sawedoff/p_sawedoff.mdl";
  78. new const W_MODEL[] = "models/csgo_ports/sawedoff/w_sawedoff.mdl";
  79. new const V_MODEL[] = "models/csgo_ports/sawedoff/v_sawedoff.mdl";
  80. new const V_MODEL_ALT[] = "models/csgo_ports/sawedoff/v_sawedoff.mdl";
  81.  
  82. new const CSW_NEWPN = CSW_M3;
  83. new const weapon_newpn[] = "weapon_m3";
  84. new const WEAPON_EVENT[] = "events/m3.sc";
  85. new const BASE_W_MODEL[] = "models/w_m3.mdl";
  86. new const FIRE_SOUND[] = "weapons/csgo_ports/sawedoff/sawedoff-1.wav";
  87.  
  88. new const NEWPN_NAME[] = "weapon_sawedoff";
  89. new const PRI_AMMO_ID = 5;
  90. new const SLOT_ID = 0;
  91. new const NUM_IN_SLOT = 5;
  92. new const ITEM_FLAGS = 0;
  93.  
  94. new const newpn_shortname[] = "sawedoff";
  95. new const basewpn_shortname[] = "m3";
  96. new const basewpn_buynames[] = {"m3", "12gauge"}
  97.  
  98. new const weapon_classnames[][] =
  99. {
  100. "weapon_ak47",
  101. "weapon_m4a1",
  102. "weapon_awp",
  103. "weapon_mp5navy",
  104. "weapon_ump45",
  105. "weapon_galil",
  106. "weapon_famas",
  107. "weapon_sg552",
  108. "weapon_aug",
  109. "weapon_p90",
  110. "weapon_mac10",
  111. "weapon_tmp",
  112. "weapon_scout",
  113. "weapon_m3",
  114. "weapon_xm1014",
  115. "weapon_g3sg1",
  116. "weapon_sg550",
  117. "weapon_m249"
  118. }
  119.  
  120. new const weapon_sprites[][] =
  121. {
  122. "sprites/weapon_sawedoff.txt",
  123. "sprites/640csws01.spr",
  124. "sprites/640csws01_s.spr"
  125. }
  126.  
  127. new Float:g_idletime[] =
  128. {
  129. 0.8, // 0 draw
  130. 2.0, // 1 reload
  131. 0.6, // 2 shoot
  132. 5.6 // 3 inspect
  133. }
  134.  
  135. const m_pPlayer = 41;
  136. const m_flNextPrimaryAttack = 46;
  137. const m_flTimeWeaponIdle = 48;
  138. const m_iClip = 51;
  139. const m_fInSpecialReload = 55;
  140. const m_flNextAttack = 83;
  141. const m_pActiveItem = 373;
  142. const m_rgPlayerAmmoSlot = 376;
  143.  
  144.  
  145. // Weapon bitsums
  146. const PRIMARY_WEAPONS_BIT_SUM = (1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_MAC10)|(1<<CSW_AUG)|
  147. (1<<CSW_UMP45)|(1<<CSW_SG550)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_AWP)|(1<<CSW_MP5NAVY)|(1<<CSW_M249)|
  148. (1<<CSW_M3)|(1<<CSW_M4A1)|(1<<CSW_TMP)|(1<<CSW_G3SG1)|(1<<CSW_SG552)|(1<<CSW_AK47)|(1<<CSW_P90);
  149.  
  150. new g_hambot, g_has_weapon, g_weapon_event, g_buytime_expire, g_rebuy[32], g_restart_round;
  151. new Float:g_recoil[33][3], g_prev_weapon[33], smoke_sprite;
  152. new cvar_bot_allow_wpns, cvar_freezetime, cvar_buytime, cvar_decals, cvar_alteam;
  153. new msg_Money, msg_BlinkAcct, msg_WeaponList,sawedoffEnabled;
  154.  
  155. new TASKID_BUYTIME = 100000;
  156.  
  157. public plugin_init()
  158. {
  159. register_plugin(PLUGIN, VERSION, "Sneaky.amxx, dias, MeRcyLeZZ, Arkshine, hellmonja");
  160.  
  161. register_event("TextMsg", "Game_Commencing", "a", "2=#Game_Commencing", "2=#Game_will_restart_in");
  162. register_event("HLTV", "Event_New_Round", "a", "1=0", "2=0");
  163. register_event("CurWeapon", "Event_CurWeapon", "be", "1=1");
  164. register_message(get_user_msgid("DeathMsg"), "Message_DeathMsg");
  165.  
  166. register_forward(FM_UpdateClientData, "Fw_UpdateClientData_Post", 1);
  167. register_forward(FM_PlaybackEvent, "Fw_PlaybackEvent");
  168. register_forward(FM_SetModel, "Fw_SetModel");
  169.  
  170. RegisterHam(Ham_Item_Deploy, weapon_newpn, "Fw_ItemDeployPost", 1);
  171. RegisterHam(Ham_AddPlayerItem, "player", "Fw_AddItem");
  172. RegisterHam(Ham_RemovePlayerItem, "player", "Fw_RemoveItem");
  173. RegisterHam(Ham_TraceAttack, "worldspawn", "Fw_TraceAttack_World");
  174. RegisterHam(Ham_TraceAttack, "func_breakable", "Fw_TraceAttack_World");
  175. RegisterHam(Ham_TraceAttack, "func_wall", "Fw_TraceAttack_World");
  176. RegisterHam(Ham_TraceAttack, "func_door", "Fw_TraceAttack_World");
  177. RegisterHam(Ham_TraceAttack, "func_door_rotating", "Fw_TraceAttack_World");
  178. RegisterHam(Ham_TraceAttack, "func_plat", "Fw_TraceAttack_World");
  179. RegisterHam(Ham_TraceAttack, "func_rotating", "Fw_TraceAttack_World");
  180. RegisterHam(Ham_TraceAttack, "player", "Fw_TraceAttack_Player");
  181. RegisterHam(Ham_Weapon_PrimaryAttack, weapon_newpn, "Fw_Weapon_PrimaryAttack");
  182. RegisterHam(Ham_Weapon_PrimaryAttack, weapon_newpn, "Fw_Weapon_PrimaryAttack_Post", 1);
  183. RegisterHam(Ham_Item_AddToPlayer, weapon_newpn, "Fw_Item_AddToPlayer_Post", 1);
  184. RegisterHam(Ham_Weapon_Reload, weapon_newpn, "Fw_Weapon_Reload");
  185. RegisterHam(Ham_Weapon_WeaponIdle, weapon_newpn, "Fw_Weapon_Idle");
  186. //RegisterHam(Ham_CS_Item_GetMaxSpeed, weapon_newpn, "Player_Weapon_Walkspeed");
  187. RegisterHam(Ham_Killed, "player", "Fw_Player_Death");
  188.  
  189. bind_pcvar_num(create_cvar("csgo_sawedoff_enabled", "1"), sawedoffEnabled);
  190.  
  191. msg_WeaponList = get_user_msgid("WeaponList");
  192. msg_Money = get_user_msgid("Money");
  193. msg_BlinkAcct = get_user_msgid("BlinkAcct");
  194.  
  195. new clcmd[24]; formatex(clcmd, 25, "say %s", newpn_shortname);
  196. for(new i = 0; i < sizeof basewpn_buynames - 1; i++)
  197. register_clcmd(basewpn_buynames[i], "ClientCommand_BuyBaseWpn");
  198.  
  199. register_clcmd(clcmd, "Get_Weapon");
  200. register_clcmd(NEWPN_NAME, "ClientCommand_SelectWeapon");
  201. register_concmd("repurchase", "ClientCommand_RePurchase");
  202. register_concmd("inspect", "Inspect_Weapon");
  203. register_concmd(newpn_shortname, "Get_Weapon");
  204. register_concmd("ver_sawedoff", "Code_Version");
  205.  
  206. //CVARS
  207. cvar_freezetime = get_cvar_pointer("mp_freezetime");
  208. cvar_buytime = get_cvar_pointer("mp_buytime");
  209. cvar_bot_allow_wpns = get_cvar_pointer("bot_allow_shotguns");
  210. cvar_alteam = register_cvar("armsw_team", "1");
  211. cvar_decals = register_cvar("csws_decals", "0");
  212. }
  213.  
  214. public plugin_precache()
  215. {
  216. for(new i = 1; i < sizeof weapon_sprites; i++)
  217. precache_generic(weapon_sprites[i]);
  218.  
  219. precache_model(P_MODEL);
  220. precache_model(W_MODEL);
  221. precache_model(V_MODEL);
  222. precache_model(V_MODEL_ALT);
  223. precache_sound(FIRE_SOUND);
  224.  
  225. smoke_sprite = engfunc(EngFunc_PrecacheModel, "sprites/gunsmoke.spr");
  226.  
  227. register_forward(FM_PrecacheEvent, "Fw_PrecacheEvent_Post", 1);
  228. }
  229.  
  230. public Code_Version(id)
  231. {
  232. console_print(id, "==============================");
  233. console_print(id, "%s v%s", PLUGIN, VERSION);
  234. console_print(id, "Counter-Strike Weapons System v%s", CSWS_VER);
  235. console_print(id, "%s", DATE);
  236. console_print(id, "==============================");
  237. }
  238.  
  239. public Fw_PrecacheEvent_Post(type, const name[])
  240. {
  241. if(equal(WEAPON_EVENT, name))
  242. g_weapon_event = get_orig_retval();
  243. }
  244.  
  245. public client_putinserver(id)
  246. {
  247. if(!g_hambot && is_user_bot(id))
  248. {
  249. g_hambot = 1
  250. set_task(0.1, "Do_RegisterHam", id)
  251. }
  252. }
  253.  
  254. public Do_RegisterHam(id)
  255. {
  256. RegisterHamFromEntity(Ham_TraceAttack, id, "Fw_TraceAttack_Player");
  257. RegisterHamFromEntity(Ham_AddPlayerItem, id, "Fw_AddItem", 1);
  258. RegisterHamFromEntity(Ham_RemovePlayerItem, id, "Fw_RemoveItem", 1);
  259. RegisterHamFromEntity(Ham_Killed, id, "Fw_Player_Death");
  260. }
  261.  
  262. public Game_Commencing()
  263. {
  264. g_restart_round = 1;
  265. }
  266.  
  267. public Event_New_Round()
  268. {
  269. new freezetime = get_pcvar_num(cvar_freezetime);
  270. new buytime = floatround((get_pcvar_float(cvar_buytime) * 60));
  271. new Float:t;
  272.  
  273. g_buytime_expire = 0;
  274.  
  275. if(g_restart_round)
  276. {
  277. Remove_Weapon(0, 1);
  278. g_restart_round = 0;
  279. }
  280.  
  281. remove_task(TASKID_BUYTIME);
  282.  
  283. if(get_pcvar_num(cvar_bot_allow_wpns) && g_buytime_expire == 0)
  284. set_task(1.5, "Bot_Weapon");
  285.  
  286. if(buytime < freezetime) t = float(buytime);
  287. else t = float(buytime+freezetime);
  288.  
  289. set_task(t, "Buytime_Expired", TASKID_BUYTIME);
  290. }
  291.  
  292. public Buytime_Expired()
  293. {
  294. g_buytime_expire = 1;
  295. }
  296.  
  297. public Bot_Weapon()
  298. {
  299. new players[32], pnum, wpn_id;
  300.  
  301. switch(TEAM)
  302. {
  303. case 0: get_players(players, pnum, "ad");
  304. case 1: get_players(players, pnum, "ade", "TERRORIST");
  305. case 2: get_players(players, pnum, "ade", "CT");
  306. }
  307.  
  308. for(new i = 0; i < pnum; i++)
  309. if(random_num(1,100) <= BOT_BUY_CHANCE && get_user_armor(players[i]) != 99 && !is_weapon_slot_empty(players[i], 1, wpn_id) && !Get_BitVar(g_has_weapon, players[i]))
  310. {
  311. Get_Weapon(players[i]);
  312. cs_set_user_armor(players[i], 99, CS_ARMOR_VESTHELM);
  313. }
  314. }
  315.  
  316. public ClientCommand_BuyBaseWpn(id)
  317. {
  318. if(!sawedoffEnabled)
  319. return
  320.  
  321. if(purchase_check(id, BASEWPN_PRICE) && Get_BitVar(g_has_weapon, id))
  322. {
  323. drop_weapons(id);
  324. UnSet_BitVar(g_has_weapon,id);
  325. g_rebuy[id] = 0;
  326. }
  327. }
  328.  
  329. public ClientCommand_RePurchase(id)
  330. {
  331. if(is_plugin_loaded("Weapon Price Editor", false) <= 0)
  332. client_cmd(id, "rebuy");
  333.  
  334. if(g_rebuy[id] == 1 && !Get_BitVar(g_has_weapon, id))
  335. Get_Weapon(id);
  336. }
  337.  
  338. public Get_Weapon(id)
  339. {
  340. if(!is_user_alive(id) || !is_user_connected(id) || !sawedoffEnabled)
  341. return
  342.  
  343. if(TEAM > 0 && get_user_team(id) != TEAM)
  344. {
  345. client_print(id, print_center, "The Sawed-Off is not available for your team to buy.");
  346. return
  347. }
  348.  
  349. // Player tries to buy the same gun
  350. if(Get_BitVar(g_has_weapon, id))
  351. {
  352. client_print(id, print_center, "#Cstrike_Already_Own_Weapon");
  353. return
  354. }
  355.  
  356. if(purchase_check(id, PRICE))
  357. {
  358. if(cs_get_user_shield(id))
  359. {
  360. engclient_cmd(id, "slot1");
  361. engclient_cmd(id, "drop");
  362. }
  363. else
  364. drop_weapons(id);
  365.  
  366. Set_BitVar(g_has_weapon, id);
  367. g_rebuy[id] = 1;
  368. new weapon = give_item(id, weapon_newpn);
  369.  
  370. // Set Ammo
  371. cs_set_weapon_ammo(weapon, CLIP);
  372. cs_set_user_bpammo(id, CSW_NEWPN, BPAMMO);
  373.  
  374. // Calculate new money amount
  375. static newmoney;
  376. newmoney = cs_get_user_money(id) - PRICE;
  377.  
  378. // Update money offset
  379. cs_set_user_money(id, newmoney);
  380.  
  381. // Update money on HUD
  382. message_begin(MSG_ONE, msg_Money, _, id);
  383. write_long(newmoney); // amount
  384. write_byte(1); // flash
  385. message_end();
  386. }
  387. }
  388.  
  389. public ClientCommand_SelectWeapon(id)
  390. {
  391. engclient_cmd(id, weapon_newpn);
  392. return PLUGIN_HANDLED
  393. }
  394.  
  395. public Event_CurWeapon(id)
  396. {
  397. if(!is_user_alive(id))
  398. return
  399.  
  400. static CSW_ID; CSW_ID = read_data(2);
  401.  
  402. if((CSW_ID == CSW_NEWPN && g_prev_weapon[id] == CSW_NEWPN) && Get_BitVar(g_has_weapon, id))
  403. {
  404. static weapon;
  405. weapon= find_ent_by_owner(-1, weapon_newpn, id);
  406.  
  407. if(!pev_valid(weapon))
  408. {
  409. g_prev_weapon[id] = get_user_weapon(id)
  410. return
  411. }
  412. set_pdata_float(weapon, m_flNextPrimaryAttack, get_pdata_float(weapon, m_flNextPrimaryAttack, 4) * RATEOFIRE, 4)
  413. }
  414. else if((CSW_ID != CSW_NEWPN && g_prev_weapon[id] == CSW_NEWPN) && Get_BitVar(g_has_weapon, id))
  415. draw_new_weapon(id, get_user_weapon(id));
  416.  
  417. g_prev_weapon[id] = get_user_weapon(id);
  418. }
  419.  
  420. public Fw_ItemDeployPost(weapon)
  421. {
  422. static id;
  423. id = get_pdata_cbase(weapon, m_pPlayer, 4);
  424.  
  425. if(!is_user_alive(id))
  426. return
  427.  
  428. if(Get_BitVar(g_has_weapon, id))
  429. arm_switch(id);
  430. }
  431.  
  432. public Fw_AddItem(id, weapon)
  433. {
  434. static classname[24];
  435. pev(weapon, pev_classname, classname, charsmax(classname));
  436.  
  437. if(!Get_BitVar(g_has_weapon,id) && g_rebuy[id] == 1)
  438. {
  439. for(new i = 0; i < sizeof weapon_classnames; i++)
  440. if(equali(classname, weapon_classnames[i]))
  441. {
  442. g_rebuy[id] = 0;
  443. return
  444. }
  445. }
  446. else if(equali(classname, weapon_newpn) && Get_BitVar(g_has_weapon,id))
  447. g_rebuy[id] = 1;
  448. }
  449.  
  450. public Fw_RemoveItem(id)
  451. {
  452. set_task(0.01, "Fw_AddItem", id);
  453. }
  454.  
  455. public Fw_UpdateClientData_Post(id, sendweapons, cd_handle)
  456. {
  457. if(!is_user_alive(id))
  458. return FMRES_IGNORED
  459.  
  460. if(get_user_weapon(id) == CSW_NEWPN && Get_BitVar(g_has_weapon, id))
  461. set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001)
  462.  
  463. return FMRES_HANDLED
  464. }
  465.  
  466. public Fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
  467. {
  468. if (!is_user_connected(invoker))
  469. return FMRES_IGNORED
  470.  
  471. if(get_user_weapon(invoker) != CSW_NEWPN || !Get_BitVar(g_has_weapon, invoker))
  472. return FMRES_IGNORED
  473.  
  474. if(eventid != g_weapon_event)
  475. return FMRES_IGNORED
  476.  
  477. engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2);
  478. set_weapon_anim(invoker, SHOOT_ANIM);
  479. emit_sound(invoker, CHAN_WEAPON, FIRE_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
  480.  
  481. return FMRES_SUPERCEDE
  482. }
  483.  
  484. public Fw_SetModel(wpn_ent, model[])
  485. {
  486. if(!pev_valid(wpn_ent))
  487. return FMRES_IGNORED
  488.  
  489. static classname[32];
  490. pev(wpn_ent, pev_classname, classname, sizeof classname);
  491.  
  492. if(!equal(classname, "weaponbox"))
  493. return FMRES_IGNORED
  494.  
  495. static id;
  496. id= pev(wpn_ent, pev_owner);
  497.  
  498. if(equal(model, BASE_W_MODEL))
  499. {
  500. static weapon;
  501. weapon = find_ent_by_owner(-1, weapon_newpn, wpn_ent);
  502.  
  503. if(!pev_valid(weapon))
  504. return FMRES_IGNORED;
  505.  
  506. if(Get_BitVar(g_has_weapon, id))
  507. {
  508. UnSet_BitVar(g_has_weapon,id)
  509.  
  510. set_pev(weapon, pev_impulse, WEAPON_SECRETCODE)
  511. engfunc(EngFunc_SetModel, wpn_ent, W_MODEL)
  512. set_pev(wpn_ent, pev_body, BODY_NUM)
  513.  
  514. return FMRES_SUPERCEDE
  515. }
  516. }
  517.  
  518. return FMRES_IGNORED;
  519. }
  520.  
  521. public Fw_TraceAttack_World(victim, attacker, Float:damage, Float:direction[3], prt, damage_bits)
  522. {
  523. if(!is_user_connected(attacker))
  524. return HAM_IGNORED
  525.  
  526. if(get_user_weapon(attacker) != CSW_NEWPN || !Get_BitVar(g_has_weapon, attacker))
  527. return HAM_IGNORED
  528.  
  529. static Float:origin[3], Float:vecPlane[3];
  530.  
  531. get_tr2(prt, TR_vecEndPos, origin);
  532. get_tr2(prt, TR_vecPlaneNormal, vecPlane);
  533.  
  534. make_bullet_hole(victim, attacker, origin);
  535. make_bullet_smoke(attacker, prt);
  536.  
  537. SetHamParamFloat(3, float(DAMAGE));
  538.  
  539. return HAM_IGNORED
  540. }
  541.  
  542.  
  543. public Fw_TraceAttack_Player(victim, attacker, Float:damage, Float:direction[3], ptr, damage_bits)
  544. {
  545. if(!is_user_connected(attacker))
  546. return HAM_IGNORED
  547.  
  548. if(get_user_weapon(attacker) != CSW_NEWPN || !Get_BitVar(g_has_weapon, attacker))
  549. return HAM_IGNORED
  550.  
  551. new dist = floatround(entity_range(attacker, victim));
  552.  
  553. if(dist <= WEAPON_RANGE)
  554. {
  555. if(CLOSE_RANGE > dist)
  556. SetHamParamFloat(3, float(CLOSE_DAMAGE));
  557. else
  558. SetHamParamFloat (3, float(DAMAGE));
  559. }
  560.  
  561. return HAM_IGNORED
  562. }
  563.  
  564. public Fw_Weapon_PrimaryAttack(weapon)
  565. {
  566. static id;
  567. id = pev(weapon, pev_owner);
  568. pev(id, pev_punchangle, g_recoil[id]);
  569.  
  570. return HAM_IGNORED
  571. }
  572.  
  573. public Fw_Weapon_PrimaryAttack_Post(weapon)
  574. {
  575. static id;
  576. id = pev(weapon, pev_owner);
  577.  
  578. if(Get_BitVar(g_has_weapon, id))
  579. {
  580. static Float:Push[3]
  581. pev(id, pev_punchangle, Push);
  582. xs_vec_sub(Push, g_recoil[id], Push);
  583.  
  584. xs_vec_mul_scalar(Push, RECOIL, Push);
  585. xs_vec_add(Push, g_recoil[id], Push);
  586. set_pev(id, pev_punchangle, Push);
  587.  
  588. set_pdata_float(weapon, m_flTimeWeaponIdle, g_idletime[2], 4);
  589. }
  590. }
  591.  
  592. public Fw_Item_AddToPlayer_Post(weapon, id)
  593. {
  594. if(!pev_valid(weapon))
  595. return HAM_IGNORED
  596.  
  597. if(pev(weapon, pev_impulse) == WEAPON_SECRETCODE)
  598. {
  599. Set_BitVar(g_has_weapon, id);
  600. set_pev(weapon, pev_impulse, 0);
  601. g_rebuy[id] = 1;
  602. }
  603.  
  604. if(Get_BitVar(g_has_weapon,id))
  605. {
  606. message_begin(MSG_ONE, msg_WeaponList, .player = id);
  607. write_string(NEWPN_NAME); // WeaponName
  608. write_byte(PRI_AMMO_ID); // PrimaryAmmoID
  609. write_byte(BPAMMO); // PrimaryAmmoMaxAmount
  610. write_byte(-1); // SecondaryAmmoID
  611. write_byte(-1); // SecondaryAmmoMaxAmount
  612. write_byte(SLOT_ID); // SlotID (0...N)
  613. write_byte(NUM_IN_SLOT); // NumberInSlot (1...N)
  614. write_byte(CSW_NEWPN); // WeaponID
  615. write_byte(ITEM_FLAGS); // Flags
  616. message_end();
  617. } else {
  618. message_begin(MSG_ONE, msg_WeaponList, .player = id);
  619. write_string(weapon_newpn); // WeaponName
  620. write_byte(PRI_AMMO_ID); // PrimaryAmmoID
  621. write_byte(BPAMMO); // PrimaryAmmoMaxAmount
  622. write_byte(-1); // SecondaryAmmoID
  623. write_byte(-1); // SecondaryAmmoMaxAmount
  624. write_byte(SLOT_ID); // SlotID (0...N)
  625. write_byte(NUM_IN_SLOT); // NumberInSlot (1...N)
  626. write_byte(CSW_NEWPN); // WeaponID
  627. write_byte(ITEM_FLAGS); // Flags
  628. message_end();
  629. }
  630.  
  631. return HAM_HANDLED
  632. }
  633.  
  634. public Fw_Weapon_Reload(weapon)
  635. {
  636. new pPlayer = get_pdata_cbase(weapon, m_pPlayer, 4);
  637.  
  638. if (!Get_BitVar(g_has_weapon, pPlayer))
  639. return HAM_IGNORED;
  640.  
  641. new iClip = cs_get_weapon_ammo(weapon);
  642.  
  643. if (iClip >= CLIP)
  644. return HAM_SUPERCEDE;
  645.  
  646. new iAmmoIndex = ExecuteHamB(Ham_Item_PrimaryAmmoIndex, weapon);
  647. new rgAmmo = get_pdata_int(pPlayer, m_rgPlayerAmmoSlot + iAmmoIndex);
  648.  
  649. if (rgAmmo <= 0)
  650. return HAM_SUPERCEDE;
  651.  
  652. if (get_pdata_float(weapon, m_flNextPrimaryAttack, 4) > 0.0)
  653. return HAM_SUPERCEDE;
  654.  
  655. switch (get_pdata_int(weapon, m_fInSpecialReload, 4))
  656. {
  657. case 0:
  658. {
  659. set_weapon_anim(pPlayer, RELOAD_START);
  660. set_pdata_int(weapon, m_fInSpecialReload, 1, 4);
  661. set_pdata_float(pPlayer, m_flNextAttack, 0.3); //this control reload speed
  662. set_pdata_float(weapon, m_flTimeWeaponIdle, 0.3, 4); //this one too
  663. set_pdata_float(weapon, m_flNextPrimaryAttack, 0.5, 4);
  664.  
  665. return HAM_SUPERCEDE;
  666. }
  667. case 1:
  668. {
  669. if (get_pdata_float(weapon, m_flTimeWeaponIdle, 4) > 0.0)
  670. return HAM_SUPERCEDE;
  671.  
  672. set_pdata_int(weapon, m_fInSpecialReload, 2, 4);
  673. //Play "shell insert" sound here if you want
  674. set_weapon_anim(pPlayer, RELOAD_INSERT);
  675. set_pdata_float(weapon, m_flTimeWeaponIdle, 0.35, 4);
  676. }
  677. case 2:
  678. {
  679. cs_set_weapon_ammo(weapon, ++iClip);
  680. set_pdata_int(pPlayer, m_rgPlayerAmmoSlot + iAmmoIndex, --rgAmmo);
  681. set_pdata_int(weapon, m_fInSpecialReload, 1, 4);
  682. }
  683. }
  684.  
  685. return HAM_SUPERCEDE;
  686. }
  687.  
  688. public Fw_Weapon_Idle(weapon)
  689. {
  690. if (get_pdata_float(weapon, m_flTimeWeaponIdle, 4) > 0.0)
  691. return HAM_IGNORED;
  692.  
  693. new pPlayer = get_pdata_cbase(weapon, m_pPlayer, 4);
  694.  
  695. if (!Get_BitVar(g_has_weapon, pPlayer))
  696. return HAM_IGNORED;
  697.  
  698. new iClip = cs_get_weapon_ammo(weapon);
  699. new fInSpecialReload = get_pdata_int(weapon, m_fInSpecialReload, 4);
  700. new rgAmmo = get_pdata_int(pPlayer, m_rgPlayerAmmoSlot +
  701.  
  702. ExecuteHamB(Ham_Item_PrimaryAmmoIndex, weapon));
  703.  
  704. if (iClip == 0 && fInSpecialReload == 0 && rgAmmo > 0)
  705. {
  706. Fw_Weapon_Reload(weapon);
  707. return HAM_SUPERCEDE;
  708. }
  709. else if (fInSpecialReload != 0)
  710. {
  711. if (iClip != CLIP && rgAmmo > 0)
  712. {
  713. Fw_Weapon_Reload(weapon);
  714. }
  715. else
  716. {
  717. set_weapon_anim(pPlayer, RELOAD_END);
  718. //play reload end sound here if you need
  719. set_pdata_int(weapon, m_fInSpecialReload, 0, 4);
  720. set_pdata_float(weapon, m_flTimeWeaponIdle, 1.5, 4);
  721. }
  722.  
  723. return HAM_SUPERCEDE;
  724. }
  725.  
  726. return HAM_IGNORED;
  727. }
  728.  
  729. public Fw_Player_Death(id)
  730. {
  731. if(!is_user_connected(id))
  732. return HAM_IGNORED
  733.  
  734. if(Get_BitVar(g_has_weapon, id))
  735. {
  736. set_task(0.1, "Remove_Weapon", id);
  737. g_rebuy[id] = 1;
  738. }
  739.  
  740. return HAM_HANDLED
  741. }
  742.  
  743. public Message_DeathMsg(msg_id, msg_dest, id)
  744. {
  745. static attacker, weapon[33];
  746.  
  747. attacker = get_msg_arg_int(1);
  748. get_msg_arg_string(4, weapon, charsmax(weapon))
  749.  
  750. if(!is_user_connected(attacker))
  751. return PLUGIN_CONTINUE
  752.  
  753. if(equal(weapon, basewpn_shortname) && Get_BitVar(g_has_weapon, attacker))
  754. set_msg_arg_string(4, newpn_shortname);
  755.  
  756. return PLUGIN_CONTINUE
  757. }
  758.  
  759. public Player_Weapon_Walkspeed(weapon)
  760. {
  761. new id = get_pdata_cbase(weapon, m_pPlayer, 4);
  762.  
  763. if(!is_user_alive(id))
  764. return HAM_IGNORED
  765.  
  766. if(Get_BitVar(g_has_weapon,id))
  767. SetHamReturnFloat(WALKSPEED);
  768. else
  769. return HAM_IGNORED
  770.  
  771. return HAM_SUPERCEDE
  772. }
  773.  
  774. public Inspect_Weapon(id)
  775. {
  776. if(!is_user_alive(id))
  777. return
  778.  
  779. if(!Get_BitVar(g_has_weapon, id))
  780. return
  781.  
  782. if(get_user_weapon(id) != CSW_NEWPN)
  783. return
  784.  
  785. static weapon; weapon = get_pdata_cbase(id, m_pActiveItem);
  786. new fInSpecialReload = get_pdata_int(weapon, m_fInSpecialReload, 4);
  787.  
  788. if(fInSpecialReload)
  789. return
  790.  
  791. new current_anim = pev(get_pdata_cbase(weapon, m_pPlayer, 4), pev_weaponanim);
  792.  
  793. if(!current_anim)
  794. set_weapon_anim(id, INSPECT_ANIM);
  795. }
  796.  
  797. public Remove_Weapon(id, all)
  798. {
  799. switch(all)
  800. {
  801. case 1:
  802. {
  803. new players[32], pnum;
  804. get_players(players, pnum, "a");
  805.  
  806. for(new i = 0; i <= pnum; i++)
  807. UnSet_BitVar(g_has_weapon, players[i]);
  808. }
  809. default:
  810. UnSet_BitVar(g_has_weapon, id);
  811. }
  812. }
  813.  
  814. bool:purchase_check(id, cost)
  815. {
  816. if (!cs_get_user_buyzone(id))
  817. return false
  818.  
  819. // Check for buy time
  820. if(g_buytime_expire == 1)
  821. {
  822. client_print(id, print_center, "%d seconds have passed.^n You can't buy anything now!",floatround(get_cvar_float("mp_buytime") * 60));
  823. return false
  824. }
  825.  
  826. // Check if player has enough money
  827. if (cs_get_user_money(id) < cost)
  828. {
  829. client_print(id, print_center, "#Cstrike_TitlesTXT_Not_Enough_Money");
  830.  
  831. // Blink money
  832. message_begin(MSG_ONE_UNRELIABLE, msg_BlinkAcct, _, id);
  833. write_byte(2); // times
  834. message_end();
  835. return false
  836. }
  837. return true
  838. }
  839.  
  840. draw_new_weapon(id, CSW_ID)
  841. {
  842. static weapon;
  843. weapon = find_ent_by_owner(-1, weapon_newpn, id);
  844.  
  845. if(CSW_ID == CSW_NEWPN)
  846. {
  847. if(pev_valid(weapon) && Get_BitVar(g_has_weapon, id))
  848. {
  849. set_pev(weapon, pev_effects, pev(weapon, pev_effects) &~ EF_NODRAW);
  850. engfunc(EngFunc_SetModel, weapon, P_MODEL);
  851. set_pev(weapon, pev_body, BODY_NUM);
  852. }
  853. }
  854. else
  855. if(pev_valid(weapon))
  856. set_pev(weapon, pev_effects, pev(weapon, pev_effects) | EF_NODRAW);
  857. }
  858.  
  859. make_bullet_smoke(id, TrResult)
  860. {
  861. static Float:vecSrc[3], Float:vecEnd[3], TE_FLAG;
  862.  
  863. get_weapon_attachment(id, vecSrc);
  864. global_get(glb_v_forward, vecEnd);
  865.  
  866. xs_vec_mul_scalar(vecEnd, 8192.0, vecEnd);
  867. xs_vec_add(vecSrc, vecEnd, vecEnd);
  868.  
  869. get_tr2(TrResult, TR_vecEndPos, vecSrc);
  870. get_tr2(TrResult, TR_vecPlaneNormal, vecEnd);
  871.  
  872. xs_vec_mul_scalar(vecEnd, 2.5, vecEnd);
  873. xs_vec_add(vecSrc, vecEnd, vecEnd);
  874.  
  875. TE_FLAG |= TE_EXPLFLAG_NODLIGHTS;
  876. TE_FLAG |= TE_EXPLFLAG_NOSOUND;
  877. TE_FLAG |= TE_EXPLFLAG_NOPARTICLES;
  878.  
  879. engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEnd, 0);
  880. write_byte(TE_EXPLOSION);
  881. engfunc(EngFunc_WriteCoord, vecEnd[0]);
  882. engfunc(EngFunc_WriteCoord, vecEnd[1]);
  883. engfunc(EngFunc_WriteCoord, vecEnd[2] - 10.0);
  884. write_short(smoke_sprite);
  885. write_byte(5);
  886. write_byte(50);
  887. write_byte(TE_FLAG);
  888. message_end();
  889. }
  890.  
  891. make_bullet_hole(victim, attacker, Float:origin[3])
  892. {
  893. static decal;
  894.  
  895. if(!get_pcvar_num(cvar_decals))
  896. decal = random_num(41, 43);
  897. else
  898. decal = random_num(52, 55);
  899.  
  900. if(victim)
  901. {
  902. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  903. write_byte(TE_DECAL)
  904. engfunc(EngFunc_WriteCoord, origin[0])
  905. engfunc(EngFunc_WriteCoord, origin[1])
  906. engfunc(EngFunc_WriteCoord, origin[2])
  907. write_byte(decal)
  908. write_short(victim)
  909. message_end()
  910. }
  911. else
  912. {
  913. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  914. write_byte(TE_WORLDDECAL)
  915. engfunc(EngFunc_WriteCoord, origin[0])
  916. engfunc(EngFunc_WriteCoord, origin[1])
  917. engfunc(EngFunc_WriteCoord, origin[2])
  918. write_byte(decal)
  919. message_end()
  920. }
  921. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  922. write_byte(TE_GUNSHOTDECAL)
  923. engfunc(EngFunc_WriteCoord, origin[0])
  924. engfunc(EngFunc_WriteCoord, origin[1])
  925. engfunc(EngFunc_WriteCoord, origin[2])
  926. write_short(attacker)
  927. write_byte(decal)
  928. message_end()
  929. }
  930.  
  931. get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0)
  932. {
  933. static Float:vfEnd[3], viEnd[3] ;
  934. get_user_origin(id, viEnd, 3);
  935. IVecFVec(viEnd, vfEnd);
  936.  
  937. static Float:fOrigin[3], Float:fAngle[3];
  938.  
  939. pev(id, pev_origin, fOrigin);
  940. pev(id, pev_view_ofs, fAngle);
  941.  
  942. xs_vec_add(fOrigin, fAngle, fOrigin);
  943.  
  944. static Float:fAttack[3];
  945.  
  946. xs_vec_sub(vfEnd, fOrigin, fAttack);
  947. xs_vec_sub(vfEnd, fOrigin, fAttack);
  948.  
  949. static Float:fRate;
  950.  
  951. fRate = fDis / vector_length(fAttack);
  952. xs_vec_mul_scalar(fAttack, fRate, fAttack);
  953.  
  954. xs_vec_add(fOrigin, fAttack, output);
  955. }
  956.  
  957. set_weapon_anim(id, anim)
  958. {
  959. if(!is_user_alive(id))
  960. return
  961.  
  962. set_pev(id, pev_weaponanim, anim);
  963.  
  964. message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id);
  965. write_byte(anim);
  966. write_byte(pev(id, pev_body));
  967. message_end();
  968.  
  969. static weapon;
  970. weapon = find_ent_by_owner(-1, weapon_newpn, id);
  971.  
  972. if(!weapon)
  973. return
  974.  
  975. new Float:idle;
  976. switch(anim)
  977. {
  978. case DRAW_ANIM: idle = g_idletime[0];
  979. case INSPECT_ANIM: idle = g_idletime[3];
  980. }
  981.  
  982. set_pdata_float(weapon, m_flTimeWeaponIdle, idle, 4);
  983. }
  984.  
  985. // Drop primary/secondary weapons
  986. drop_weapons(id)
  987. {
  988. // Get user weapons
  989. static weapons[32], num, i, wpn_id;
  990. num = 0; // reset passed weapons count (bugfix)
  991. get_user_weapons(id, weapons, num);
  992.  
  993. // Loop through them and drop primaries or secondaries
  994. for (i = 0; i < num; i++)
  995. {
  996. // Prevent re-indexing the array
  997. wpn_id = weapons[i];
  998.  
  999. if(1<<wpn_id & PRIMARY_WEAPONS_BIT_SUM)
  1000. {
  1001. // Get weapon entity
  1002. static wname[32];
  1003. get_weaponname(wpn_id, wname, charsmax(wname));
  1004.  
  1005. // Player drops the weapon
  1006. engclient_cmd(id, "drop", wname);
  1007. }
  1008. }
  1009. }
  1010.  
  1011. arm_switch(id)
  1012. {
  1013. if(get_user_team(id) == get_pcvar_num(cvar_alteam))
  1014. set_pev(id, pev_viewmodel2, V_MODEL_ALT);
  1015. else
  1016. set_pev(id, pev_viewmodel2, V_MODEL);
  1017.  
  1018. set_pev(id, pev_weaponmodel2, P_MODEL)
  1019. set_weapon_anim(id, DRAW_ANIM)
  1020. draw_new_weapon(id, CSW_NEWPN)
  1021. }
  1022.  
  1023. is_weapon_slot_empty( id , iSlot , &iEntity )
  1024. {
  1025. if ( !( 1 <= iSlot <= 5 ) )
  1026. return 0;
  1027.  
  1028. iEntity = 0;
  1029. const m_rgpPlayerItems_Slot0 = 367;
  1030. const m_iId = 43;
  1031. const EXTRAOFFSET_WEAPONS = 4;
  1032.  
  1033. iEntity = get_pdata_cbase( id , m_rgpPlayerItems_Slot0 + iSlot , EXTRAOFFSET_WEAPONS );
  1034.  
  1035. return ( iEntity > 0 ) ? get_pdata_int( iEntity , m_iId , EXTRAOFFSET_WEAPONS ) : 0;
  1036. }
  1037.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement