Guest User

Untitled

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