Guest User

Untitled

a guest
Aug 30th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.07 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 27
  44. #define LONG_DAMAGE 19
  45. #define CLIP 24
  46. #define BPAMMO 120
  47. #define RATEOFIRE 0.6
  48. #define RECOIL 1.35
  49. #define RELOAD_TIME 3.3
  50. #define RELOAD_POINT 1.34
  51. #define WALKSPEED 240.0 // Devre disi
  52. #define PRICE 500
  53. #define TEAM CS_TEAM_T
  54. #define ORIG_WPN_PRICE 800
  55. #define BOT_BUY_CHANCE 2
  56.  
  57. #define BASEWPN_CLIP 20
  58. #define BASEWPN_AMMO 100
  59. #define AMMOID 7
  60. #define ACOST 50
  61. #define AUNITS 30
  62.  
  63. #define SHOOT_ANIM 3
  64. #define DRAW_ANIM 2
  65. #define RELOAD_ANIM 1
  66. #define INSPECT_ANIM 6
  67. #define BODY_NUM 0
  68.  
  69. #define WEAPON_SECRETCODE 205309
  70.  
  71. // MACROS
  72. #define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
  73. #define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
  74. #define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))
  75.  
  76. new const PLUGIN[] = "CS:GO Tec-9";
  77. new const VERSION[] = "2.6.1";
  78. new const CSWS_VER[] = "1.4.3";
  79. new const DATE[] = "8 July 2017";
  80.  
  81. new const P_MODEL[] = "models/csgo_ports/tec9/p_tec9.mdl";
  82. new const W_MODEL[] = "models/csgo_ports/tec9/w_tec9.mdl";
  83. new const V_MODEL[] = "models/csgo_ports/tec9/v_tec9.mdl";
  84. new const V_MODEL_ALT[] = "models/csgo_ports/tec9/v_tec9.mdl";
  85.  
  86. new const CSW_NEWPN = CSW_FIVESEVEN;
  87. new const weapon_newpn[] = "weapon_fiveseven";
  88. new const WEAPON_EVENT[] = "events/fiveseven.sc";
  89. new const BASE_W_MODEL[] = "models/w_fiveseven.mdl";
  90. new const FIRE_SOUND[] = "weapons/csgo_ports/tec9/tec9-1.wav";
  91.  
  92. new const NEWPN_NAME[] = "weapon_tec9";
  93. new const PRI_AMMO_ID = 7;
  94. new const SLOT_ID = 1;
  95. new const NUM_IN_SLOT = 6;
  96. new const ITEM_FLAGS = 0;
  97.  
  98. new const newpn_shortname[] = "tec9";
  99. new const basewpn_shortname[] = "fiveseven";
  100. new const basewpn_buynames[][] = {"fiveseven", "fn57"}
  101.  
  102. new const weapon_classnames[][] =
  103. {
  104. "weapon_usp",
  105. "weapon_glock18",
  106. "weapon_deagle",
  107. "weapon_p228",
  108. "weapon_fiveseven",
  109. "weapon_elite"
  110. }
  111.  
  112. new const weapon_sprites[][] =
  113. {
  114. "sprites/weapon_tec9.txt",
  115. "sprites/640csws02.spr",
  116. "sprites/640csws02_s.spr"
  117. }
  118.  
  119. new Float:g_idletime[] =
  120. {
  121. 1.0, // 0 draw
  122. 2.5, // 1 reload
  123. 0.5, // 2 shoot
  124. 4.0 // 3 inspect
  125. }
  126.  
  127. const m_pPlayer = 41;
  128. const m_flNextPrimaryAttack = 46;
  129. const m_flTimeWeaponIdle = 48;
  130. const m_iClip = 51;
  131. const m_fInReload = 54;
  132. const m_flNextAttack = 83;
  133. const m_pActiveItem = 373;
  134.  
  135. // Weapon bitsums
  136. const WEAPONS_BIT_SUM = (1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE);
  137.  
  138. new g_hambot, g_has_weapon, g_weapon_event, g_buytime_expire, g_rebuy[32], g_newrnd_bypass;
  139. new Float:g_recoil[33][3], g_clip[33], g_prev_weapon[33], g_restart_round, shell_model, smoke_sprite;
  140. new cvar_bot_allow_wpns, cvar_freezetime, cvar_buytime, cvar_decals, cvar_alteam;
  141. new msg_Money, msg_BlinkAcct, msg_WeaponList,tec9Enabled;
  142.  
  143. new pcvar_bot_allow_weaps, freezetime, buytime;
  144. new TASKID_BUYTIME = 100000;
  145.  
  146. public plugin_init()
  147. {
  148. register_plugin(PLUGIN, VERSION, "Sneaky.amxx, dias, MeRcyLeZZ, Arkshine, hellmonja");
  149.  
  150. register_event("TextMsg", "Game_Commencing", "a", "2=#Game_Commencing", "2=#Game_will_restart_in");
  151. register_event("HLTV", "Event_New_Round", "a", "1=0", "2=0");
  152. register_event("CurWeapon", "Event_CurWeapon", "be", "1=1");
  153. register_message(get_user_msgid("DeathMsg"), "Message_DeathMsg");
  154.  
  155. register_forward(FM_UpdateClientData, "Fw_UpdateClientData_Post", 1);
  156. register_forward(FM_PlaybackEvent, "Fw_PlaybackEvent");
  157. register_forward(FM_SetModel, "Fw_SetModel");
  158.  
  159. RegisterHam(Ham_Item_Deploy, weapon_newpn, "Fw_ItemDeployPost", 1);
  160. RegisterHam(Ham_AddPlayerItem, "player", "Fw_AddItem");
  161. RegisterHam(Ham_RemovePlayerItem, "player", "Fw_RemoveItem");
  162. RegisterHam(Ham_TraceAttack, "worldspawn", "Fw_TraceAttack_World");
  163. RegisterHam(Ham_TraceAttack, "func_breakable", "Fw_TraceAttack_World");
  164. RegisterHam(Ham_TraceAttack, "func_wall", "Fw_TraceAttack_World");
  165. RegisterHam(Ham_TraceAttack, "func_door", "Fw_TraceAttack_World");
  166. RegisterHam(Ham_TraceAttack, "func_door_rotating", "Fw_TraceAttack_World");
  167. RegisterHam(Ham_TraceAttack, "func_plat", "Fw_TraceAttack_World");
  168. RegisterHam(Ham_TraceAttack, "func_rotating", "Fw_TraceAttack_World");
  169. RegisterHam(Ham_TraceAttack, "player", "Fw_TraceAttack_Player");
  170. RegisterHam(Ham_Weapon_PrimaryAttack, weapon_newpn, "Fw_Weapon_PrimaryAttack");
  171. RegisterHam(Ham_Weapon_PrimaryAttack, weapon_newpn, "Fw_Weapon_PrimaryAttack_Post", 1);
  172. RegisterHam(Ham_Item_AddToPlayer, weapon_newpn, "Fw_Item_AddToPlayer_Post", 1);
  173. RegisterHam(Ham_Item_PostFrame, weapon_newpn, "Fw_Item_PostFrame");
  174. RegisterHam(Ham_Weapon_Reload, weapon_newpn, "Fw_Weapon_Reload");
  175. RegisterHam(Ham_Weapon_Reload, weapon_newpn, "Fw_Weapon_Reload_Post", 1);
  176. //RegisterHam(Ham_CS_Item_GetMaxSpeed, weapon_newpn, "Player_Weapon_Walkspeed");
  177. RegisterHam(Ham_Touch, "weapon_shield", "Ham_Block_Sheild_Pickup");
  178. RegisterHam(Ham_Killed, "player", "Fw_Player_Death");
  179.  
  180. bind_pcvar_num(create_cvar("csgo_tec9_enabled", "1"), tec9Enabled);
  181.  
  182. msg_WeaponList = get_user_msgid("WeaponList");
  183. msg_Money = get_user_msgid("Money");
  184. msg_BlinkAcct = get_user_msgid("BlinkAcct");
  185.  
  186. new clcmd[24]; formatex(clcmd, 25, "say %s", newpn_shortname);
  187. for(new i = 0; i < sizeof basewpn_buynames - 1; i++)
  188. register_clcmd(basewpn_buynames[i], "ClientCommand_BuyBaseWpn");
  189.  
  190. register_clcmd(clcmd, "Get_Weapon");
  191. register_clcmd(NEWPN_NAME, "ClientCommand_SelectWeapon");
  192. register_clcmd("buyammo2", "ClientCommand_BuyAmmo");
  193. register_clcmd("secammo", "ClientCommand_BuySecAmmo");
  194. register_clcmd("shield", "ClientCommand_BuyShield");
  195. register_concmd("repurchase", "ClientCommand_RePurchase");
  196. register_concmd("inspect", "Inspect_Weapon");
  197. register_concmd(newpn_shortname, "Get_Weapon");
  198. register_concmd("ver_tec9", "Code_Version");
  199.  
  200. //CVARS
  201. cvar_freezetime = get_cvar_pointer("mp_freezetime");
  202. cvar_buytime = get_cvar_pointer("mp_buytime");
  203. cvar_bot_allow_wpns = get_cvar_pointer("bot_allow_pistols");
  204. cvar_alteam = register_cvar("armsw_team", "1");
  205. cvar_decals = register_cvar("csws_decals", "0");
  206.  
  207. pcvar_bot_allow_weaps = get_pcvar_num(cvar_bot_allow_wpns);
  208. freezetime = get_pcvar_num(cvar_freezetime);
  209. buytime = floatround((get_pcvar_float(cvar_buytime) * 60))
  210. }
  211.  
  212. public plugin_precache()
  213. {
  214. for(new i = 1; i < sizeof weapon_sprites; i++)
  215. precache_generic(weapon_sprites[i]);
  216.  
  217. precache_model(P_MODEL);
  218. precache_model(W_MODEL);
  219. precache_model(V_MODEL);
  220. precache_model(V_MODEL_ALT);
  221. precache_sound(FIRE_SOUND);
  222.  
  223. smoke_sprite = engfunc(EngFunc_PrecacheModel, "sprites/gunsmoke.spr");
  224. shell_model = engfunc(EngFunc_PrecacheModel, "models/pshell.mdl")
  225.  
  226. register_forward(FM_PrecacheEvent, "Fw_PrecacheEvent_Post", 1);
  227. }
  228.  
  229. public Code_Version(id)
  230. {
  231. console_print(id, "==============================");
  232. console_print(id, "%s v%s", PLUGIN, VERSION);
  233. console_print(id, "Counter-Strike Weapons System v%s", CSWS_VER);
  234. console_print(id, "%s", DATE);
  235. console_print(id, "==============================");
  236. }
  237.  
  238. public Fw_PrecacheEvent_Post(type, const name[])
  239. {
  240. if(equal(WEAPON_EVENT, name))
  241. g_weapon_event = get_orig_retval();
  242. }
  243.  
  244. public client_putinserver(id)
  245. {
  246. if(!g_hambot && is_user_bot(id))
  247. {
  248. g_hambot = 1
  249. set_task(0.1, "Do_RegisterHam", id)
  250. }
  251. }
  252.  
  253. public Do_RegisterHam(id)
  254. {
  255. RegisterHamFromEntity(Ham_TraceAttack, id, "Fw_TraceAttack_Player");
  256. RegisterHamFromEntity(Ham_AddPlayerItem, id, "Fw_AddItem", 1);
  257. RegisterHamFromEntity(Ham_RemovePlayerItem, id, "Fw_RemoveItem", 1);
  258. RegisterHamFromEntity(Ham_Killed, id, "Fw_Player_Death");
  259. }
  260.  
  261. public Game_Commencing()
  262. {
  263. g_restart_round = 1;
  264. }
  265.  
  266. public Event_New_Round()
  267. {
  268. new Float:t;
  269.  
  270. g_buytime_expire = 0;
  271. g_newrnd_bypass = 0;
  272.  
  273. if(g_restart_round)
  274. {
  275. Remove_Weapon(0, 1);
  276. g_restart_round = 0;
  277. }
  278.  
  279. set_task(0.1, "Bypass_NewRound_Items");
  280. remove_task(TASKID_BUYTIME);
  281.  
  282. if(pcvar_bot_allow_weaps && g_buytime_expire == 0)
  283. set_task(1.5, "Bot_Weapon");
  284.  
  285. if(buytime < freezetime)
  286. t = float(buytime);
  287. else
  288. t = float(buytime+freezetime);
  289.  
  290. set_task(t, "Buytime_Expired", TASKID_BUYTIME);
  291. }
  292.  
  293. public Buytime_Expired()
  294. {
  295. g_buytime_expire = 1;
  296. }
  297.  
  298. public Bot_Weapon()
  299. {
  300. new players[32], pnum;
  301. get_players(players, pnum, "ade", "TERRORIST");
  302.  
  303. for(new i = 0; i < pnum; i++)
  304. if(random_num(0,100) <= BOT_BUY_CHANCE && get_user_armor(players[i]) != 99)
  305. {
  306. Get_Weapon(players[i]);
  307. cs_set_user_armor(players[i], 99, CS_ARMOR_VESTHELM);
  308. }
  309. }
  310.  
  311. public ClientCommand_BuyBaseWpn(id)
  312. {
  313. if(!tec9Enabled)
  314. return
  315.  
  316. if(purchase_check(id, ORIG_WPN_PRICE) && Get_BitVar(g_has_weapon, id))
  317. {
  318. drop_weapons(id);
  319. UnSet_BitVar(g_has_weapon,id);
  320. g_rebuy[id] = 0;
  321. }
  322. }
  323.  
  324. public ClientCommand_RePurchase(id)
  325. {
  326. if(is_plugin_loaded("Weapon Price Editor", false) <= 0)
  327. client_cmd(id, "rebuy");
  328.  
  329. if(g_rebuy[id] == 1 && !Get_BitVar(g_has_weapon, id))
  330. Get_Weapon(id);
  331. }
  332.  
  333. public ClientCommand_BuyAmmo(id)
  334. {
  335. if(!is_user_alive(id))
  336. return PLUGIN_HANDLED
  337.  
  338. if(!cs_get_user_buyzone(id))
  339. return PLUGIN_HANDLED
  340.  
  341. if(!Get_BitVar(g_has_weapon, id))
  342. return PLUGIN_CONTINUE
  343.  
  344. new wpns[32], wnum;
  345. get_user_weapons(id, wpns, wnum);
  346.  
  347. for (new i; i < wnum; i++)
  348. if(wpns[i] == CSW_NEWPN)
  349. {
  350. new i_bpammo = cs_get_user_bpammo(id, CSW_NEWPN);
  351.  
  352. if(i_bpammo >= BPAMMO)
  353. return PLUGIN_HANDLED
  354.  
  355. if(i_bpammo < BPAMMO)
  356. if(i_bpammo > BPAMMO-AUNITS)
  357. {
  358. new i_ammo = BPAMMO - i_bpammo;
  359. give_ammo(id, i_ammo, AMMOID, ACOST);
  360. }
  361. else
  362. give_ammo(id, AUNITS, AMMOID, ACOST);
  363.  
  364. return PLUGIN_HANDLED
  365. }
  366.  
  367. return PLUGIN_CONTINUE
  368. }
  369.  
  370. public ClientCommand_BuySecAmmo(id)
  371. {
  372. if(!is_user_alive(id))
  373. return PLUGIN_HANDLED
  374.  
  375. if(!cs_get_user_buyzone(id))
  376. return PLUGIN_HANDLED
  377.  
  378. if(!Get_BitVar(g_has_weapon, id))
  379. return PLUGIN_CONTINUE
  380.  
  381. new i_bpammo = cs_get_user_bpammo(id, CSW_NEWPN);
  382.  
  383. if(i_bpammo < BPAMMO)
  384. {
  385. new i_ammo = BPAMMO - i_bpammo;
  386. give_ammo(id, i_ammo, AMMOID, ACOST);
  387. }
  388.  
  389. return PLUGIN_HANDLED
  390. }
  391.  
  392. public ClientCommand_BuyShield(id)
  393. {
  394. if(!tec9Enabled)
  395. return PLUGIN_HANDLED
  396.  
  397. if(!is_user_alive(id))
  398. return PLUGIN_HANDLED
  399.  
  400. if(!cs_get_user_buyzone(id))
  401. return PLUGIN_HANDLED
  402.  
  403. if(!purchase_check(id, 2200))
  404. return PLUGIN_HANDLED
  405.  
  406. if(Get_BitVar(g_has_weapon, id))
  407. drop_weapons(id);
  408.  
  409. return PLUGIN_CONTINUE
  410. }
  411.  
  412. public Get_Weapon(id)
  413. {
  414. if(!is_user_alive(id) || !is_user_connected(id) || !tec9Enabled)
  415. return
  416.  
  417. // Player tries to buy the same gun
  418. if(Get_BitVar(g_has_weapon, id))
  419. {
  420. client_print(id, print_center, "#Cstrike_Already_Own_Weapon");
  421. return
  422. }
  423.  
  424. if(TEAM > CS_TEAM_UNASSIGNED && cs_get_user_team(id) != TEAM)
  425. {
  426. client_print(id, print_center, "The Tec-9 is not available for your team to buy.");
  427. return
  428. }
  429.  
  430. if(purchase_check(id, PRICE))
  431. {
  432. if(cs_get_user_shield(id))
  433. {
  434. engclient_cmd(id, "slot1");
  435. engclient_cmd(id, "drop");
  436. }
  437.  
  438. drop_weapons(id);
  439. Set_BitVar(g_has_weapon, id);
  440. g_rebuy[id] = 1;
  441. new weapon = give_item(id, weapon_newpn);
  442.  
  443. // Set Ammo
  444. cs_set_weapon_ammo(weapon, CLIP);
  445. cs_set_user_bpammo(id, CSW_NEWPN, BPAMMO);
  446.  
  447. // Calculate new money amount
  448. static newmoney;
  449. newmoney = cs_get_user_money(id) - PRICE;
  450.  
  451. // Update money offset
  452. cs_set_user_money(id, newmoney);
  453.  
  454. // Update money on HUD
  455. message_begin(MSG_ONE, msg_Money, _, id);
  456. write_long(newmoney); // amount
  457. write_byte(1); // flash
  458. message_end();
  459. }
  460. }
  461.  
  462. public ClientCommand_SelectWeapon(id)
  463. {
  464. engclient_cmd(id, weapon_newpn);
  465. return PLUGIN_HANDLED
  466. }
  467.  
  468. public Event_CurWeapon(id)
  469. {
  470. if(!is_user_alive(id))
  471. return
  472.  
  473. static CSW_ID; CSW_ID = read_data(2);
  474.  
  475. if((CSW_ID == CSW_NEWPN && g_prev_weapon[id] == CSW_NEWPN) && Get_BitVar(g_has_weapon, id))
  476. {
  477. static weapon;
  478. weapon= find_ent_by_owner(-1, weapon_newpn, id);
  479.  
  480. if(!pev_valid(weapon))
  481. {
  482. g_prev_weapon[id] = get_user_weapon(id)
  483. return
  484. }
  485. set_pdata_float(weapon, m_flNextPrimaryAttack, get_pdata_float(weapon, m_flNextPrimaryAttack, 4) * RATEOFIRE, 4)
  486. }
  487. else if((CSW_ID != CSW_NEWPN && g_prev_weapon[id] == CSW_NEWPN) && Get_BitVar(g_has_weapon, id))
  488. draw_new_weapon(id, get_user_weapon(id));
  489.  
  490. g_prev_weapon[id] = get_user_weapon(id);
  491. }
  492.  
  493. public Fw_ItemDeployPost(weapon)
  494. {
  495. static id;
  496. id = get_pdata_cbase(weapon, m_pPlayer, 4);
  497.  
  498. if(!is_user_alive(id))
  499. return
  500.  
  501. if(Get_BitVar(g_has_weapon, id))
  502. {
  503. arm_switch(id);
  504.  
  505. if(cs_get_user_shield(id))
  506. {
  507. engclient_cmd(id, "slot1");
  508. engclient_cmd(id, "drop");
  509. }
  510. }
  511.  
  512. }
  513.  
  514. public Fw_AddItem(id, weapon)
  515. {
  516. static classname[24];
  517. pev(weapon, pev_classname, classname, charsmax(classname));
  518.  
  519. if(!Get_BitVar(g_has_weapon,id) && g_rebuy[id] == 1)
  520. {
  521. for(new i = 0; i < sizeof weapon_classnames; i++)
  522. if(equali(classname, weapon_classnames[i]) && g_newrnd_bypass == 1)
  523. {
  524. g_rebuy[id] = 0;
  525. return
  526. }
  527. }
  528. else if(equali(classname, weapon_newpn) && Get_BitVar(g_has_weapon,id))
  529. g_rebuy[id] = 1;
  530. }
  531.  
  532. public Fw_RemoveItem(id)
  533. {
  534. set_task(0.01, "Fw_AddItem", id);
  535. }
  536.  
  537. public Ham_Block_Sheild_Pickup(ent, id)
  538. {
  539. if(!is_user_connected(id) || !is_user_alive(id))
  540. return HAM_IGNORED
  541.  
  542. if(Get_BitVar(g_has_weapon, id))
  543. return HAM_SUPERCEDE
  544.  
  545. return HAM_IGNORED
  546. }
  547.  
  548. public Fw_UpdateClientData_Post(id, sendweapons, cd_handle)
  549. {
  550. if(!is_user_alive(id))
  551. return FMRES_IGNORED
  552.  
  553. if(get_user_weapon(id) == CSW_NEWPN && Get_BitVar(g_has_weapon, id))
  554. set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001)
  555.  
  556. return FMRES_HANDLED
  557. }
  558.  
  559. public Fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
  560. {
  561. if (!is_user_connected(invoker))
  562. return FMRES_IGNORED
  563.  
  564. if(get_user_weapon(invoker) != CSW_NEWPN || !Get_BitVar(g_has_weapon, invoker))
  565. return FMRES_IGNORED
  566.  
  567. if(eventid != g_weapon_event)
  568. return FMRES_IGNORED
  569.  
  570. engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2);
  571. set_weapon_anim(invoker, SHOOT_ANIM);
  572. emit_sound(invoker, CHAN_WEAPON, FIRE_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
  573. make_shell(invoker);
  574.  
  575. return FMRES_SUPERCEDE
  576. }
  577.  
  578. public Fw_SetModel(wpn_ent, model[])
  579. {
  580. if(!pev_valid(wpn_ent))
  581. return FMRES_IGNORED
  582.  
  583. static classname[32];
  584. pev(wpn_ent, pev_classname, classname, sizeof classname);
  585.  
  586. if(!equal(classname, "weaponbox"))
  587. return FMRES_IGNORED
  588.  
  589. static id;
  590. id= pev(wpn_ent, pev_owner);
  591.  
  592. if(equal(model, BASE_W_MODEL))
  593. {
  594. static weapon;
  595. weapon = find_ent_by_owner(-1, weapon_newpn, wpn_ent);
  596.  
  597. if(!pev_valid(weapon))
  598. return FMRES_IGNORED;
  599.  
  600. if(Get_BitVar(g_has_weapon, id))
  601. {
  602. UnSet_BitVar(g_has_weapon,id)
  603.  
  604. set_pev(weapon, pev_impulse, WEAPON_SECRETCODE)
  605. engfunc(EngFunc_SetModel, wpn_ent, W_MODEL)
  606. set_pev(wpn_ent, pev_body, BODY_NUM)
  607.  
  608. return FMRES_SUPERCEDE
  609. }
  610. }
  611.  
  612. return FMRES_IGNORED;
  613. }
  614.  
  615. public Fw_TraceAttack_World(victim, attacker, Float:damage, Float:direction[3], prt, damage_bits)
  616. {
  617. if(!is_user_connected(attacker))
  618. return HAM_IGNORED
  619.  
  620. if(get_user_weapon(attacker) != CSW_NEWPN || !Get_BitVar(g_has_weapon, attacker))
  621. return HAM_IGNORED
  622.  
  623. static Float:origin[3], Float:vecPlane[3];
  624.  
  625. get_tr2(prt, TR_vecEndPos, origin);
  626. get_tr2(prt, TR_vecPlaneNormal, vecPlane);
  627.  
  628. make_bullet_hole(victim, attacker, origin);
  629. make_bullet_smoke(attacker, prt);
  630.  
  631. SetHamParamFloat(3, float(DAMAGE));
  632.  
  633. return HAM_IGNORED
  634. }
  635. public Fw_TraceAttack_Player(victim, attacker, Float:damage, Float:direction[3], ptr, damage_bits)
  636. {
  637. if(!is_user_connected(attacker))
  638. return HAM_IGNORED
  639.  
  640. if(get_user_weapon(attacker) != CSW_NEWPN || !Get_BitVar(g_has_weapon, attacker))
  641. return HAM_IGNORED
  642.  
  643. new dist = floatround(entity_range(attacker, victim));
  644.  
  645. if(dist >= 900)
  646. SetHamParamFloat(3, float(LONG_DAMAGE));
  647. else
  648. SetHamParamFloat (3, float(DAMAGE));
  649.  
  650. return HAM_IGNORED
  651. }
  652.  
  653. public Fw_Weapon_PrimaryAttack(weapon)
  654. {
  655. static id;
  656. id = pev(weapon, pev_owner);
  657. pev(id, pev_punchangle, g_recoil[id]);
  658.  
  659. return HAM_IGNORED
  660. }
  661.  
  662. public Fw_Weapon_PrimaryAttack_Post(weapon)
  663. {
  664. static id;
  665. id = pev(weapon, pev_owner);
  666.  
  667. if(Get_BitVar(g_has_weapon, id))
  668. {
  669. static Float:Push[3]
  670. pev(id, pev_punchangle, Push);
  671. xs_vec_sub(Push, g_recoil[id], Push);
  672.  
  673. xs_vec_mul_scalar(Push, RECOIL, Push);
  674. xs_vec_add(Push, g_recoil[id], Push);
  675. set_pev(id, pev_punchangle, Push);
  676.  
  677. set_pdata_float(weapon, m_flTimeWeaponIdle, g_idletime[2], 4);
  678. }
  679. }
  680.  
  681. public Fw_Item_AddToPlayer_Post(weapon, id)
  682. {
  683. if(!pev_valid(weapon))
  684. return HAM_IGNORED
  685.  
  686. if(pev(weapon, pev_impulse) == WEAPON_SECRETCODE)
  687. {
  688. Set_BitVar(g_has_weapon, id);
  689. set_pev(weapon, pev_impulse, 0);
  690. g_rebuy[id] = 1;
  691. }
  692.  
  693. if(Get_BitVar(g_has_weapon,id))
  694. {
  695. message_begin(MSG_ONE, msg_WeaponList, .player = id);
  696. write_string(NEWPN_NAME); // WeaponName
  697. write_byte(PRI_AMMO_ID); // PrimaryAmmoID
  698. write_byte(BPAMMO); // PrimaryAmmoMaxAmount
  699. write_byte(-1); // SecondaryAmmoID
  700. write_byte(-1); // SecondaryAmmoMaxAmount
  701. write_byte(SLOT_ID); // SlotID (0...N)
  702. write_byte(NUM_IN_SLOT); // NumberInSlot (1...N)
  703. write_byte(CSW_NEWPN); // WeaponID
  704. write_byte(ITEM_FLAGS); // Flags
  705. message_end();
  706. } else {
  707. message_begin(MSG_ONE, msg_WeaponList, .player = id);
  708. write_string(weapon_newpn); // WeaponName
  709. write_byte(PRI_AMMO_ID); // PrimaryAmmoID
  710. write_byte(BPAMMO); // PrimaryAmmoMaxAmount
  711. write_byte(-1); // SecondaryAmmoID
  712. write_byte(-1); // SecondaryAmmoMaxAmount
  713. write_byte(SLOT_ID); // SlotID (0...N)
  714. write_byte(NUM_IN_SLOT); // NumberInSlot (1...N)
  715. write_byte(CSW_NEWPN); // WeaponID
  716. write_byte(ITEM_FLAGS); // Flags
  717. message_end();
  718. }
  719.  
  720. return HAM_HANDLED
  721. }
  722.  
  723. public Fw_Item_PostFrame(weapon)
  724. {
  725. if(!pev_valid(weapon))
  726. return HAM_IGNORED
  727.  
  728. static id
  729. id = pev(weapon, pev_owner)
  730.  
  731. if(is_user_alive(id) && Get_BitVar(g_has_weapon, id))
  732. {
  733. static Float:flNextAttack; flNextAttack = get_pdata_float(id, m_flNextAttack, 5);
  734. static bpammo; bpammo = cs_get_user_bpammo(id, CSW_NEWPN);
  735. static i_clip; i_clip = get_pdata_int(weapon, m_iClip, 4);
  736. static fInReload; fInReload = get_pdata_int(weapon, m_fInReload, 4);
  737.  
  738. if(fInReload && flNextAttack <= 0.0)
  739. {
  740. static temp1; temp1 = min(CLIP - i_clip, bpammo);
  741.  
  742. set_pdata_int(weapon, m_iClip, i_clip + temp1, 4);
  743. cs_set_user_bpammo(id, CSW_NEWPN, bpammo - temp1);
  744.  
  745. set_pdata_int(weapon, m_fInReload, 0, 4);
  746.  
  747. fInReload = 0;
  748.  
  749. set_pdata_float(weapon, m_flNextPrimaryAttack, RELOAD_TIME - RELOAD_POINT, 4);
  750. }
  751. }
  752.  
  753. return HAM_IGNORED
  754. }
  755.  
  756. public Fw_Weapon_Reload(weapon)
  757. {
  758. static id; id = pev(weapon, pev_owner);
  759.  
  760. if(!is_user_alive(id))
  761. return HAM_IGNORED
  762.  
  763. if(!Get_BitVar(g_has_weapon, id))
  764. return HAM_IGNORED
  765.  
  766. g_clip[id] = -1;
  767.  
  768. static bpammo; bpammo = cs_get_user_bpammo(id, CSW_NEWPN);
  769. static i_clip; i_clip = get_pdata_int(weapon, m_iClip, 4);
  770.  
  771. if(bpammo <= 0)
  772. return HAM_SUPERCEDE
  773.  
  774. if(i_clip >= CLIP)
  775. return HAM_SUPERCEDE
  776.  
  777. g_clip[id] = i_clip;
  778.  
  779. return HAM_HANDLED
  780. }
  781.  
  782. public Fw_Weapon_Reload_Post(weapon)
  783. {
  784. static id;
  785. id = pev(weapon, pev_owner);
  786.  
  787. if(!is_user_alive(id))
  788. return HAM_IGNORED
  789.  
  790. if(!Get_BitVar(g_has_weapon, id))
  791. return HAM_IGNORED
  792.  
  793. if (g_clip[id] == -1)
  794. return HAM_IGNORED
  795.  
  796. set_pdata_int(weapon, m_iClip, g_clip[id], 4);
  797. set_pdata_int(weapon, m_fInReload, 1, 4);
  798.  
  799. set_weapon_anim(id, RELOAD_ANIM);
  800. set_pdata_float(id, m_flNextAttack, RELOAD_POINT, 5);
  801.  
  802. return HAM_HANDLED
  803. }
  804.  
  805. public Fw_Player_Death(id)
  806. {
  807. if(!is_user_connected(id))
  808. return HAM_IGNORED
  809.  
  810. if(Get_BitVar(g_has_weapon, id))
  811. {
  812. set_task(0.1, "Remove_Weapon", id);
  813. g_rebuy[id] = 1;
  814. }
  815.  
  816. return HAM_HANDLED
  817. }
  818.  
  819. public Message_DeathMsg(msg_id, msg_dest, id)
  820. {
  821. static attacker, weapon[33];
  822.  
  823. attacker = get_msg_arg_int(1);
  824. get_msg_arg_string(4, weapon, charsmax(weapon))
  825.  
  826. if(!is_user_connected(attacker))
  827. return PLUGIN_CONTINUE
  828.  
  829. if(equal(weapon, basewpn_shortname) && Get_BitVar(g_has_weapon, attacker))
  830. set_msg_arg_string(4, newpn_shortname);
  831.  
  832. return PLUGIN_CONTINUE
  833. }
  834.  
  835. public Player_Weapon_Walkspeed(weapon)
  836. {
  837. new id = get_pdata_cbase(weapon, m_pPlayer, 4);
  838.  
  839. if(!is_user_alive(id))
  840. return HAM_IGNORED
  841.  
  842. if(Get_BitVar(g_has_weapon,id))
  843. SetHamReturnFloat(WALKSPEED);
  844. else
  845. return HAM_IGNORED
  846.  
  847. return HAM_SUPERCEDE
  848. }
  849.  
  850. public Inspect_Weapon(id)
  851. {
  852. if(!is_user_alive(id))
  853. return
  854.  
  855. if(!Get_BitVar(g_has_weapon, id))
  856. return
  857.  
  858. if(get_user_weapon(id) != CSW_NEWPN)
  859. return
  860.  
  861. static weapon; weapon = get_pdata_cbase(id, m_pActiveItem);
  862. new current_anim = pev(get_pdata_cbase(weapon, m_pPlayer, 4), pev_weaponanim);
  863.  
  864. if(!current_anim)
  865. set_weapon_anim(id, INSPECT_ANIM);
  866. }
  867.  
  868. public Remove_Weapon(id, all)
  869. {
  870. switch(all)
  871. {
  872. case 1:
  873. {
  874. new players[32], pnum;
  875. get_players(players, pnum, "a");
  876.  
  877. for(new i = 0; i <= pnum; i++)
  878. UnSet_BitVar(g_has_weapon, players[i]);
  879. }
  880. default:
  881. UnSet_BitVar(g_has_weapon, id);
  882. }
  883. }
  884.  
  885. public Bypass_NewRound_Items()
  886. {
  887. g_newrnd_bypass = 1;
  888. }
  889.  
  890. bool:purchase_check(id, cost)
  891. {
  892. if (!cs_get_user_buyzone(id))
  893. return false
  894.  
  895. // Check for buy time
  896. if(g_buytime_expire == 1)
  897. {
  898. client_print(id, print_center, "%d seconds have passed.^n You can't buy anything now!",floatround(get_cvar_float("mp_buytime") * 60));
  899. return false
  900. }
  901.  
  902. // Check if player has enough money
  903. if (cs_get_user_money(id) < cost)
  904. {
  905. client_print(id, print_center, "#Cstrike_TitlesTXT_Not_Enough_Money");
  906.  
  907. // Blink money
  908. message_begin(MSG_ONE_UNRELIABLE, msg_BlinkAcct, _, id);
  909. write_byte(2); // times
  910. message_end();
  911. return false
  912. }
  913. return true
  914. }
  915.  
  916. draw_new_weapon(id, CSW_ID)
  917. {
  918. static weapon;
  919. weapon = find_ent_by_owner(-1, weapon_newpn, id);
  920.  
  921. if(CSW_ID == CSW_NEWPN)
  922. {
  923. if(pev_valid(weapon) && Get_BitVar(g_has_weapon, id))
  924. {
  925. set_pev(weapon, pev_effects, pev(weapon, pev_effects) &~ EF_NODRAW);
  926. engfunc(EngFunc_SetModel, weapon, P_MODEL);
  927. set_pev(weapon, pev_body, BODY_NUM);
  928. }
  929. }
  930. else
  931. if(pev_valid(weapon))
  932. set_pev(weapon, pev_effects, pev(weapon, pev_effects) | EF_NODRAW);
  933. }
  934.  
  935. make_shell(id)
  936. {
  937. static Float:player_origin[3], Float:origin[3], Float:origin2[3], Float:gunorigin[3], Float:oldangles[3], Float:v_forward[3], Float:v_forward2[3], Float:v_up[3], Float:v_up2[3], Float:v_right[3], Float:v_right2[3], Float:viewoffsets[3];
  938.  
  939. pev(id,pev_v_angle, oldangles); pev(id,pev_origin,player_origin); pev(id, pev_view_ofs, viewoffsets);
  940.  
  941. engfunc(EngFunc_MakeVectors, oldangles)
  942.  
  943. global_get(glb_v_forward, v_forward); global_get(glb_v_up, v_up); global_get(glb_v_right, v_right);
  944. global_get(glb_v_forward, v_forward2); global_get(glb_v_up, v_up2); global_get(glb_v_right, v_right2);
  945.  
  946. xs_vec_add(player_origin, viewoffsets, gunorigin);
  947.  
  948. xs_vec_mul_scalar(v_forward, 10.3, v_forward); xs_vec_mul_scalar(v_right, 2.9, v_right);
  949. xs_vec_mul_scalar(v_up, -3.7, v_up);
  950. xs_vec_mul_scalar(v_forward2, 10.0, v_forward2); xs_vec_mul_scalar(v_right2, 3.0, v_right2);
  951. xs_vec_mul_scalar(v_up2, -4.0, v_up2);
  952.  
  953. xs_vec_add(gunorigin, v_forward, origin);
  954. xs_vec_add(gunorigin, v_forward2, origin2);
  955. xs_vec_add(origin, v_right, origin);
  956. xs_vec_add(origin2, v_right2, origin2);
  957. xs_vec_add(origin, v_up, origin);
  958. xs_vec_add(origin2, v_up2, origin2);
  959.  
  960. static Float:velocity[3]
  961. get_speed_vector(origin2, origin, random_float(140.0, 160.0), velocity)
  962.  
  963. static angle; angle = random_num(0, 360)
  964.  
  965. message_begin(MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, _, id)
  966. write_byte(TE_MODEL)
  967. engfunc(EngFunc_WriteCoord, origin[0])
  968. engfunc(EngFunc_WriteCoord,origin[1])
  969. engfunc(EngFunc_WriteCoord,origin[2])
  970. engfunc(EngFunc_WriteCoord,velocity[0])
  971. engfunc(EngFunc_WriteCoord,velocity[1])
  972. engfunc(EngFunc_WriteCoord,velocity[2])
  973. write_angle(angle)
  974. write_short(shell_model)
  975. write_byte(1)
  976. write_byte(20)
  977. message_end()
  978. }
  979.  
  980. make_bullet_smoke(id, TrResult)
  981. {
  982. static Float:vecSrc[3], Float:vecEnd[3], TE_FLAG;
  983.  
  984. get_weapon_attachment(id, vecSrc);
  985. global_get(glb_v_forward, vecEnd);
  986.  
  987. xs_vec_mul_scalar(vecEnd, 8192.0, vecEnd);
  988. xs_vec_add(vecSrc, vecEnd, vecEnd);
  989.  
  990. get_tr2(TrResult, TR_vecEndPos, vecSrc);
  991. get_tr2(TrResult, TR_vecPlaneNormal, vecEnd);
  992.  
  993. xs_vec_mul_scalar(vecEnd, 2.5, vecEnd);
  994. xs_vec_add(vecSrc, vecEnd, vecEnd);
  995.  
  996. TE_FLAG |= TE_EXPLFLAG_NODLIGHTS;
  997. TE_FLAG |= TE_EXPLFLAG_NOSOUND;
  998. TE_FLAG |= TE_EXPLFLAG_NOPARTICLES;
  999.  
  1000. engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEnd, 0);
  1001. write_byte(TE_EXPLOSION);
  1002. engfunc(EngFunc_WriteCoord, vecEnd[0]);
  1003. engfunc(EngFunc_WriteCoord, vecEnd[1]);
  1004. engfunc(EngFunc_WriteCoord, vecEnd[2] - 10.0);
  1005. write_short(smoke_sprite);
  1006. write_byte(5);
  1007. write_byte(50);
  1008. write_byte(TE_FLAG);
  1009. message_end();
  1010. }
  1011.  
  1012. make_bullet_hole(victim, attacker, Float:origin[3])
  1013. {
  1014. static decal;
  1015.  
  1016. if(!get_pcvar_num(cvar_decals))
  1017. decal = random_num(41, 43);
  1018. else
  1019. decal = random_num(52, 55);
  1020.  
  1021. if(victim)
  1022. {
  1023. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  1024. write_byte(TE_DECAL)
  1025. engfunc(EngFunc_WriteCoord, origin[0])
  1026. engfunc(EngFunc_WriteCoord, origin[1])
  1027. engfunc(EngFunc_WriteCoord, origin[2])
  1028. write_byte(decal)
  1029. write_short(victim)
  1030. message_end()
  1031. }
  1032. else
  1033. {
  1034. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  1035. write_byte(TE_WORLDDECAL)
  1036. engfunc(EngFunc_WriteCoord, origin[0])
  1037. engfunc(EngFunc_WriteCoord, origin[1])
  1038. engfunc(EngFunc_WriteCoord, origin[2])
  1039. write_byte(decal)
  1040. message_end()
  1041. }
  1042. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  1043. write_byte(TE_GUNSHOTDECAL)
  1044. engfunc(EngFunc_WriteCoord, origin[0])
  1045. engfunc(EngFunc_WriteCoord, origin[1])
  1046. engfunc(EngFunc_WriteCoord, origin[2])
  1047. write_short(attacker)
  1048. write_byte(decal)
  1049. message_end()
  1050. }
  1051.  
  1052. get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0)
  1053. {
  1054. static Float:vfEnd[3], viEnd[3] ;
  1055. get_user_origin(id, viEnd, 3);
  1056. IVecFVec(viEnd, vfEnd);
  1057.  
  1058. static Float:fOrigin[3], Float:fAngle[3];
  1059.  
  1060. pev(id, pev_origin, fOrigin);
  1061. pev(id, pev_view_ofs, fAngle);
  1062.  
  1063. xs_vec_add(fOrigin, fAngle, fOrigin);
  1064.  
  1065. static Float:fAttack[3];
  1066.  
  1067. xs_vec_sub(vfEnd, fOrigin, fAttack);
  1068. xs_vec_sub(vfEnd, fOrigin, fAttack);
  1069.  
  1070. static Float:fRate;
  1071.  
  1072. fRate = fDis / vector_length(fAttack);
  1073. xs_vec_mul_scalar(fAttack, fRate, fAttack);
  1074.  
  1075. xs_vec_add(fOrigin, fAttack, output);
  1076. }
  1077.  
  1078. set_weapon_anim(id, anim)
  1079. {
  1080. if(!is_user_alive(id))
  1081. return
  1082.  
  1083. set_pev(id, pev_weaponanim, anim);
  1084.  
  1085. message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id);
  1086. write_byte(anim);
  1087. write_byte(pev(id, pev_body));
  1088. message_end();
  1089.  
  1090. static weapon;
  1091. weapon = find_ent_by_owner(-1, weapon_newpn, id);
  1092.  
  1093. if(!weapon)
  1094. return
  1095.  
  1096. new Float:idle;
  1097. switch(anim)
  1098. {
  1099. case DRAW_ANIM: idle = g_idletime[0];
  1100. case RELOAD_ANIM: idle = g_idletime[1];
  1101. case INSPECT_ANIM: idle = g_idletime[3];
  1102. }
  1103.  
  1104. set_pdata_float(weapon, m_flTimeWeaponIdle, idle, 4);
  1105. }
  1106.  
  1107. // Drop primary/secondary weapons
  1108. drop_weapons(id)
  1109. {
  1110. // Get user weapons
  1111. static weapons[32], num, i, wpn_id;
  1112. num = 0; // reset passed weapons count (bugfix)
  1113. get_user_weapons(id, weapons, num);
  1114.  
  1115. // Loop through them and drop primaries or secondaries
  1116. for (i = 0; i < num; i++)
  1117. {
  1118. // Prevent re-indexing the array
  1119. wpn_id = weapons[i];
  1120.  
  1121. if(1<<wpn_id & WEAPONS_BIT_SUM)
  1122. {
  1123. // Get weapon entity
  1124. static wname[32];
  1125. get_weaponname(wpn_id, wname, charsmax(wname));
  1126.  
  1127. // Player drops the weapon
  1128. engclient_cmd(id, "drop", wname);
  1129. }
  1130. }
  1131. }
  1132.  
  1133. arm_switch(id)
  1134. {
  1135. if(get_user_team(id) == get_pcvar_num(cvar_alteam))
  1136. set_pev(id, pev_viewmodel2, V_MODEL_ALT);
  1137. else
  1138. set_pev(id, pev_viewmodel2, V_MODEL);
  1139.  
  1140. set_pev(id, pev_weaponmodel2, P_MODEL)
  1141. set_weapon_anim(id, DRAW_ANIM)
  1142. draw_new_weapon(id, CSW_NEWPN)
  1143. }
  1144.  
  1145. get_speed_vector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3])
  1146. {
  1147. new_velocity[0] = origin2[0] - origin1[0]
  1148. new_velocity[1] = origin2[1] - origin1[1]
  1149. new_velocity[2] = origin2[2] - origin1[2]
  1150. new Float:num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
  1151. new_velocity[0] *= num
  1152. new_velocity[1] *= num
  1153. new_velocity[2] *= num
  1154.  
  1155. return 1;
  1156. }
  1157.  
  1158. give_ammo(id, ammo, ammo_id, cost)
  1159. {
  1160. if (cs_get_user_money(id) < cost)
  1161. {
  1162. client_print(id, print_center, "#Cstrike_TitlesTXT_Not_Enough_Money");
  1163.  
  1164. // Blink money
  1165. message_begin(MSG_ONE_UNRELIABLE, msg_BlinkAcct, _, id);
  1166. write_byte(2); // times
  1167. message_end();
  1168. return PLUGIN_HANDLED
  1169. }
  1170.  
  1171. new newammo = cs_get_user_bpammo(id, CSW_NEWPN) + ammo;
  1172. cs_set_user_bpammo(id, CSW_NEWPN, newammo);
  1173.  
  1174. message_begin(MSG_ONE,get_user_msgid("AmmoPickup"),_, id );
  1175. write_byte(ammo_id);
  1176. write_byte(ammo);
  1177. message_end();
  1178.  
  1179. emit_sound(id, CHAN_ITEM, "items/9mmclip1.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
  1180.  
  1181. // Calculate new money amount
  1182. static newmoney;
  1183. newmoney = cs_get_user_money(id) - cost;
  1184.  
  1185. // Update money offset
  1186. cs_set_user_money(id, newmoney, 1);
  1187.  
  1188. return PLUGIN_CONTINUE
  1189. }
Add Comment
Please, Sign In to add comment