Advertisement
milutinke

[CoD] ZOOM - Radi na ReHLDS

Feb 4th, 2017
1,047
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.92 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <fakemeta_util>
  4. #include <hamsandwich>
  5. #include <engine>
  6.  
  7. #define weapon(%1) get_user_weapon(%1, clip, ammo)
  8. #define id2 get_pdata_cbase(ent, m_pPlayer, 4)
  9. #define MAX 40
  10.  
  11. #define GLOCK18_SEMIAUTOMATIC       0
  12. #define GLOCK18_BURST           2
  13.  
  14. #define FAMAS_AUTOMATIC         0
  15. #define FAMAS_BURST         16
  16.  
  17. #define M4A1_SILENCED           (1<<2)
  18. #define USP_SILENCED            (1<<0)
  19.  
  20. new const NO_RELOAD = (1<<2) | (1<<CSW_KNIFE) | (1<<CSW_C4) | (1<<CSW_M3) | (1<<CSW_XM1014) | (1<<CSW_HEGRENADE) | (1<<CSW_FLASHBANG) | (1<<CSW_SMOKEGRENADE);
  21.  
  22. const m_pPlayer = 41;
  23. const m_fInReload = 54;
  24. const m_bSilencerOn = 74;
  25.  
  26. new V_MODEL[MAX][64];
  27. new SIGHT[MAX][64];
  28. new cvar_recoil_name[MAX][64];
  29.  
  30. new c_wpnchange[MAX];
  31. new cvar_recoil[MAX];
  32.  
  33. new Float:cl_pushangle[33][3];
  34. new Zoom[33], Reloading[33], WeaponName[24];
  35. new ma_tumik[33], ma_brust[33], ma_tumik_usp[33], ma_brust_glock[33];
  36. new clip, ammo, idwpn;
  37.  
  38. public plugin_init(){
  39.     register_plugin("COD Zoom", "1.0", "CeLeS & Cypis & N3u[T]r4L & Milutinke (ByM)");
  40.      
  41.     register_forward(FM_CmdStart, "CmdStart");
  42.     register_forward(FM_PlayerPreThink,"PreThink");
  43.  
  44.     register_event("CurWeapon","CurWeapon","be","1=1");
  45.      
  46.     for(new i = CSW_P228; i <= CSW_P90; i++){
  47.         if(NO_RELOAD & (1<<i))
  48.             continue;
  49.    
  50.         get_weaponname(i, WeaponName, 23);
  51.  
  52.         RegisterHam(Ham_Weapon_Reload, WeaponName, "ReloadWeapon", 1);
  53.         RegisterHam(Ham_Weapon_PrimaryAttack, WeaponName, "primary_attack");
  54.         RegisterHam(Ham_Weapon_PrimaryAttack, WeaponName, "primary_attack_post", 1);
  55.         RegisterHam(Ham_Item_Holster, WeaponName, "Item_Holster");
  56.     }
  57. }
  58.  
  59. public plugin_precache(){
  60.     new configfile[200];
  61.     get_configsdir(configfile,199);
  62.     format(configfile,199,"%s/zoom_weapon.ini",configfile);
  63.     if(file_exists(configfile)){
  64.         new row[200], left[64], trash, right[64];
  65.         new size=file_size(configfile,1);
  66.         for(new i=0;i<size;i++){
  67.                  
  68.             new model[64], wchange, recoil[32], sight_model[64];
  69.             read_file(configfile,i,row,200,trash);
  70.             if((contain(row,";")!=0) && strlen(row) && idwpn<MAX){
  71.                 replace(row, 199, " ", "_");
  72.                 replace(row, 199, "[model]", " ");
  73.                 replace(row, 199, "[wchange]", " ");
  74.                 replace(row, 199, "[recoil]", " ");
  75.                 replace(row, 199, "[sight_model]", " ");
  76.                
  77.                 strbreak(row,left,63,right,63);
  78.                 format(row, 199, "%s", right);
  79.                 format(model, 63, "%s", left);
  80.      
  81.                 strbreak(row,left,63,right,63);
  82.                 format(row, 199, "%s", right);
  83.                 wchange = str_to_num(left);
  84.      
  85.                 strbreak(row,left,63,right,63);
  86.                 format(row, 199, "%s", right);
  87.                 format(recoil, 31, "%s", left);
  88.      
  89.                 strbreak(row,left,63,right,63);
  90.                 format(row, 199, "%s", right);
  91.                 format(sight_model, 63, "%s", left);
  92.                
  93.                 c_wpnchange[idwpn] = wchange;
  94.                      
  95.                 format(cvar_recoil_name[idwpn], 63, "cwz_%s_recoil", model);
  96.                 cvar_recoil[idwpn] = register_cvar(cvar_recoil_name[idwpn], recoil);
  97.      
  98.                 format(V_MODEL[idwpn], 63, "models/%s.mdl", model);
  99.                 format(SIGHT[idwpn], 63, "models/%s.mdl", sight_model);
  100.                 precache_model(V_MODEL[idwpn]);
  101.                 precache_model(SIGHT[idwpn]);
  102.                 idwpn++;
  103.             }
  104.         }
  105.     }
  106. }
  107.  
  108. public client_putinserver(id){
  109.     Zoom[id] = false;
  110.     ma_tumik[id] = false;
  111.     ma_brust[id] = false;
  112.     ma_tumik_usp[id] = false;
  113.     ma_brust_glock[id] = false;
  114. }
  115.  
  116. public CurWeapon(id){
  117.     if(!is_user_alive(id))
  118.         return PLUGIN_CONTINUE;
  119.            
  120.     for(new i=0;i<idwpn;i++){
  121.         if(weapon(id) == c_wpnchange[i]){
  122.             get_weaponname(read_data(2), WeaponName, 23);
  123.             new ent = fm_find_ent_by_owner(-1, WeaponName, id);
  124.            
  125.             set_pdata_float(ent, 47, 9999.0, 4);
  126.             if(!Zoom[id])
  127.                 set_pev(id, pev_viewmodel2, V_MODEL[i]);
  128.             else
  129.                 set_pev(id, pev_viewmodel2, SIGHT[i]);
  130.         }
  131.     }
  132.     return PLUGIN_CONTINUE;
  133. }
  134.  
  135. public CmdStart(id, iUcHandle){
  136.     if(!is_user_alive(id))
  137.         return FMRES_IGNORED;
  138.        
  139.     new iButton = get_uc( iUcHandle, UC_Buttons );
  140.         new iOldButton = entity_get_int( id, EV_INT_oldbuttons );
  141.    
  142.     for(new i=0;i<idwpn;i++){
  143.         if(weapon(id) == c_wpnchange[i]){
  144.             if((iButton & IN_ATTACK2) && !(iOldButton & IN_ATTACK2) ){
  145.                 if(!Zoom[id] && !Reloading[id]){
  146.                     set_pdata_int(id, 363, 55, 5);
  147.                     client_cmd(id,"spk weapons/zoom");
  148.                     client_cmd(id, "+speed");
  149.                     Zoom[id] = true;
  150.                 }
  151.                 else
  152.                     ZoomFalse(id);
  153.             }
  154.         }
  155.     }
  156.     return FMRES_IGNORED;
  157. }
  158.      
  159. public Item_Holster(ent){
  160.     if(ExecuteHamB(Ham_Item_CanHolster, ent)){
  161.         ZoomFalse(id2);
  162.         remove_task(id2);
  163.         Reloading[id2] = false;
  164.     }
  165. }
  166.  
  167. public ReloadWeapon(ent){
  168.     if(get_pdata_int(ent, m_fInReload, 4)){
  169.         new Float:NextAttack = get_pdata_float(id2, 83, 5);
  170.            
  171.         if(Zoom[id2]){
  172.             if(weapon(id2) == 15){
  173.                 if(ma_brust[id2])
  174.                     cs_set_weapon_burst(ent, 1);
  175.                 else
  176.                     cs_set_weapon_burst(ent, 0);
  177.             }
  178.         }
  179.         ZoomFalse(id2);
  180.         Reloading[id2] = true;
  181.         set_task(NextAttack, "taskWeaponReloaded", id2);
  182.     }
  183. }
  184.  
  185. public taskWeaponReloaded(id)
  186.     Reloading[id] = false;      
  187.  
  188. public ZoomFalse(id){
  189.     set_pdata_int(id, 363, 90, 5);
  190.     client_cmd(id, "-speed");
  191.     Zoom[id] = false;
  192. }
  193.  
  194. public PreThink(id){
  195.     if(!is_user_alive(id))
  196.         return FMRES_IGNORED
  197.    
  198.     new ent = fm_find_ent_by_owner(-1, "weapon_m4a1", id);
  199.     new ent1 = fm_find_ent_by_owner(-1, "weapon_famas", id);
  200.     new ent2 = fm_find_ent_by_owner(-1, "weapon_usp", id);
  201.     new ent3 = fm_find_ent_by_owner(-1, "weapon_glock18", id);
  202.    
  203.     for(new i=0;i<idwpn;i++){
  204.         if(weapon(id) == c_wpnchange[i]){
  205.             new iButton = get_user_button(id);
  206.            
  207.             if(weapon(id) == 22){
  208.                 if( iButton & IN_USE ) {
  209.                     if(ma_tumik[id]){
  210.                         cs_set_weapon_silen(ent, 0);
  211.                         ma_tumik[id] = false;
  212.                     }
  213.                     else{
  214.                         cs_set_weapon_silen(ent, 1);
  215.                         ma_tumik[id] = true;
  216.                     }
  217.                 }
  218.             }
  219.             if(weapon(id) == 16){
  220.                 if( iButton & IN_USE ) {
  221.                     if(ma_tumik_usp[id]){
  222.                         cs_set_weapon_silen(ent2, 0);
  223.                         ma_tumik_usp[id] = false;
  224.                     }
  225.                     else{
  226.                         cs_set_weapon_silen(ent2, 1);
  227.                         ma_tumik_usp[id] = true;
  228.                     }
  229.                 }
  230.             }
  231.             if(weapon(id) == 15){
  232.                 if( iButton & IN_USE ) {
  233.                     if(ma_brust[id]){
  234.                         cs_set_weapon_burst(ent1, 0);
  235.                         ma_brust[id] = false;
  236.                     }
  237.                     else{
  238.                         cs_set_weapon_burst(ent1, 1);
  239.                         ma_brust[id] = true;
  240.                     }
  241.                 }
  242.             }
  243.             if(weapon(id) == 17){
  244.                 if( iButton & IN_USE ) {
  245.                     if(ma_brust_glock[id]){
  246.                         cs_set_weapon_burst(ent3, 0);
  247.                         ma_brust_glock[id] = false;
  248.                     }
  249.                     else{
  250.                         cs_set_weapon_burst(ent3, 1);
  251.                         ma_brust_glock[id] = true;
  252.                     }
  253.                 }
  254.             }
  255.         }
  256.     }
  257.     return FMRES_IGNORED;
  258. }
  259.  
  260. public primary_attack(ent){
  261.     pev(id2,pev_punchangle,cl_pushangle[id2]);
  262.     return HAM_IGNORED;
  263. }
  264.  
  265. public primary_attack_post(ent){
  266.     for(new i=0;i<idwpn;i++){
  267.         if(weapon(id2) == c_wpnchange[i] && Zoom[id2]){
  268.             new Float:push[3];
  269.             pev(id2,pev_punchangle,push);
  270.             xs_vec_sub(push,cl_pushangle[id2],push);
  271.                  
  272.             xs_vec_mul_scalar(push, get_pcvar_float(cvar_recoil[i]),push);
  273.             xs_vec_add(push,cl_pushangle[id2],push);
  274.             set_pev(id2,pev_punchangle,push);
  275.         }
  276.     }
  277.     return HAM_IGNORED;
  278. }
  279.  
  280. stock cs_set_weapon_burst(entity, burstmode){
  281.     new weapon = get_pdata_int(entity, 43, 4);
  282.     if(weapon != CSW_GLOCK18 && weapon != CSW_FAMAS)
  283.         return;
  284.    
  285.     static TextMsg;
  286.     static const messages[3][] = {"#Switch_To_BurstFire", "#Switch_To_SemiAuto", "#Switch_To_FullAuto"};
  287.    
  288.     static type;
  289.     new firemode = get_pdata_int(entity, m_bSilencerOn, 4);
  290.    
  291.     switch(weapon){
  292.         case CSW_GLOCK18:{
  293.             if(burstmode && firemode == GLOCK18_SEMIAUTOMATIC){
  294.                 type = 0;
  295.                 firemode = GLOCK18_BURST;
  296.             }
  297.             else if(!burstmode && firemode == GLOCK18_BURST){
  298.                 type = 1;
  299.                 firemode = GLOCK18_SEMIAUTOMATIC;
  300.             }
  301.             else return;
  302.         }
  303.         case CSW_FAMAS:{
  304.             if(burstmode && firemode == FAMAS_AUTOMATIC){
  305.                 type = 0;
  306.                 firemode = FAMAS_BURST;
  307.             }
  308.             else if(!burstmode && firemode == FAMAS_BURST){
  309.                 type = 2;
  310.                 firemode = FAMAS_AUTOMATIC;
  311.             }
  312.             else return;
  313.         }
  314.     }
  315.     set_pdata_int(entity, m_bSilencerOn, firemode, 4);
  316.    
  317.     new client = pev(entity, pev_owner);
  318.     if(is_user_alive(client)){
  319.         if(TextMsg || (TextMsg = get_user_msgid("TextMsg"))){
  320.             emessage_begin(MSG_ONE_UNRELIABLE, TextMsg, _, client);
  321.             ewrite_byte(4);
  322.             ewrite_string(messages[type]);
  323.             emessage_end();
  324.         }
  325.     }
  326. }
  327.  
  328. stock cs_set_weapon_silen(entity, silence){
  329.     new weapon = get_pdata_int(entity, 43, 4);
  330.     if(weapon != CSW_M4A1 && weapon != CSW_USP)
  331.         return;
  332.    
  333.     new silencemode = get_pdata_int(entity, m_bSilencerOn, 4);
  334.    
  335.     switch(weapon){
  336.         case CSW_M4A1:{
  337.             if(silence && !(silencemode & M4A1_SILENCED)){
  338.                 silencemode |= M4A1_SILENCED;
  339.             }
  340.             else if(!silence && (silencemode & M4A1_SILENCED)){
  341.                 silencemode &= ~M4A1_SILENCED;
  342.             }
  343.             else return;
  344.         }
  345.         case CSW_USP:{
  346.             if(silence && !(silencemode & USP_SILENCED)){
  347.                 silencemode |= USP_SILENCED;
  348.             }
  349.             else if(!silence && (silencemode & USP_SILENCED)){
  350.                 silencemode &= ~USP_SILENCED;
  351.             }
  352.             else return;
  353.         }
  354.     }
  355.     set_pdata_int(entity, m_bSilencerOn, silencemode, 4);
  356. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement