Guest User

Untitled

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