Advertisement
ElectricStalin

Untitled

Apr 26th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 18.77 KB | None | 0 0
  1. /*
  2. * Backpack  By: InstantDeath
  3. *
  4. * Allows a player to hold more than one primary weapon by storing one weapon in the "backpack"
  5. *
  6. * Currently this plugin is only available for CS:S. If there is enough demand for another mod, I will
  7. * add support for it, if possible.
  8. *
  9. * Command to swap/insert weapon into backpack: swap_primary
  10. *
  11. */
  12. #include <sourcemod>
  13. #include <cstrike>
  14. #include <sdktools>
  15.  
  16. #pragma semicolon 1
  17.  
  18. #define PLUGIN_VERSION "0.3"
  19. #define MAX_BUTTONS 25
  20.  
  21.  
  22. new g_LastButtons[MAXPLAYERS+1];
  23. new PlayerWeapon[MAXPLAYERS+1][35][3];
  24. new bool: PlayerisSwapping[MAXPLAYERS+1];
  25. new int swap_count=0;
  26.  
  27.  
  28. public Plugin:myinfo =
  29. {
  30.     name = "Backpack",
  31.     author = "InstantDeath",
  32.     description = "Allows the player to carry more than one primary weapon.",
  33.     version = PLUGIN_VERSION,
  34.     url = ""
  35. }
  36.  
  37. public OnClientDisconnect_Post(client)
  38. {
  39.     g_LastButtons[client] = 0;
  40. }
  41.  
  42. public OnPluginStart()
  43. {
  44.     CreateConVar("sm_backpack_version", PLUGIN_VERSION, "Backpack version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
  45.     RegConsoleCmd("swap_primary", Command_SwapPrimary);
  46.    
  47.     HookEvent("player_death", BeforePlayerDeath, EventHookMode_Pre);
  48.    
  49. }
  50.  
  51.  
  52. public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
  53. {
  54.     for (new i = 0; i < MAX_BUTTONS; i++)
  55.     {
  56.         new button = (1 << i);
  57.        
  58.         if ((buttons & button))
  59.         {
  60.             if (!(g_LastButtons[client] & button))
  61.             {
  62.                 OnButtonPress(client, button);
  63.             }
  64.         }
  65.         else if ((g_LastButtons[client] & button))
  66.         {
  67.             OnButtonRelease(client, button);
  68.         }
  69.     }
  70.    
  71.     g_LastButtons[client] = buttons;
  72.    
  73.     return Plugin_Continue;
  74. }
  75.  
  76.  
  77.  
  78. public Action:Displayinfo(Handle:timer, any:index)
  79. {
  80.     if(IsClientInGame(index))
  81.         PrintToChat(index, "[SM] Command to use backpack: swap_primary");
  82.     return Plugin_Stop;
  83. }
  84.  
  85. public OnClientPutInServer(client)
  86. {
  87.     for(new a = 0; a < 3; a++)
  88.     {
  89.         PlayerWeapon[client][0][a] = -1;
  90.         PlayerWeapon[client][1][a] = -1;
  91.     }
  92.     CreateTimer(60.0,Displayinfo,client,TIMER_FLAG_NO_MAPCHANGE);
  93. }
  94.  
  95. public Action:BeforePlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
  96. {
  97.     // get players entity ids
  98.     new victim = GetClientOfUserId(GetEventInt(event, "userid"));
  99.     new String:weaponname[32];
  100.    
  101.     if(IsClientInGame(victim))
  102.     {
  103.         if(PlayerWeapon[victim][0][0] != -1)
  104.         {
  105.             GetWeaponByID(PlayerWeapon[victim][0][0], weaponname, sizeof(weaponname));
  106.             GivePlayerItem(victim, weaponname);
  107.             PlayerWeapon[victim][0][0] = -1;
  108.             PlayerWeapon[victim][0][1] = -1;
  109.             PlayerWeapon[victim][0][2] = -1;
  110.            
  111.             //PrintToConsole(client, "Weapon: %s", weaponname);
  112.         }
  113.         if(PlayerWeapon[victim][1][0] != -1)
  114.         {
  115.             GetWeaponByID(PlayerWeapon[victim][1][0], weaponname, sizeof(weaponname));
  116.             GivePlayerItem(victim, weaponname);
  117.            
  118.             PlayerWeapon[victim][1][0] = -1;
  119.             PlayerWeapon[victim][1][1] = -1;
  120.             PlayerWeapon[victim][1][2] = -1;
  121.         }
  122.         PlayerisSwapping[victim] = false;
  123.     }
  124.     return Plugin_Continue;
  125. }
  126.  
  127. //transfers weapon to and from backpack
  128.  
  129. public Action:TimedWeaponSwap(Handle: timer, any:client)
  130. {
  131.  
  132.     new String:weaponname[32];
  133.     new weaponid;
  134.     //PrintToConsole(client, "[SM] Ran TimedWeaponSwap");
  135.     weaponid = GetPlayerWeaponSlot(client, 0);
  136.     if(PlayerWeapon[client][0][0] != -1)
  137.     {
  138.         //PrintToConsole(client, "[SM] backpack is not empty");
  139.         GetWeaponByID(PlayerWeapon[client][0][0], weaponname, sizeof(weaponname));
  140.         GivePlayerItem(client, weaponname);
  141.         //PrintToConsole(client, "Weapon: %s", weaponname);
  142.         weaponid = GetPlayerWeaponSlot(client, 0);
  143.         SetPrimaryAmmo(client, weaponid, PlayerWeapon[client][0][1]);
  144.         GetEdictClassname(weaponid, weaponname, sizeof(weaponname));
  145.         SetWeaponAmmo(client, GetWeaponAmmoOffset(weaponname), PlayerWeapon[client][0][2]);
  146.        
  147.         PlayerWeapon[client][0][0] = PlayerWeapon[client][1][0];
  148.         PlayerWeapon[client][0][1] = PlayerWeapon[client][1][1];
  149.         PlayerWeapon[client][0][2] = PlayerWeapon[client][1][2];
  150.         PlayerWeapon[client][1][0] = -1;
  151.         PlayerWeapon[client][1][1] = -1;
  152.         PlayerWeapon[client][1][2] = -1;
  153.        
  154.         PlayerisSwapping[client] = false;
  155.     }
  156.     else if(PlayerWeapon[client][0][0] == -1)
  157.     {
  158.         if(PlayerWeapon[client][1][0] != -1)
  159.         {
  160.             PlayerWeapon[client][0][0] = PlayerWeapon[client][1][0];
  161.             PlayerWeapon[client][0][1] = PlayerWeapon[client][1][1];
  162.             PlayerWeapon[client][0][2] = PlayerWeapon[client][1][2];
  163.             PlayerWeapon[client][1][0] = -1;
  164.             PlayerWeapon[client][1][1] = -1;
  165.             PlayerWeapon[client][1][2] = -1;
  166.             //PrintToConsole(client, "[SM] backpack is not empty");
  167.             GetWeaponByID(PlayerWeapon[client][0][0], weaponname, sizeof(weaponname));
  168.             GivePlayerItem(client, weaponname);
  169.             //PrintToConsole(client, "Weapon: %s", weaponname);
  170.             weaponid = GetPlayerWeaponSlot(client, 0);
  171.             SetPrimaryAmmo(client, weaponid, PlayerWeapon[client][0][1]);
  172.             GetEdictClassname(weaponid, weaponname, sizeof(weaponname));
  173.             SetWeaponAmmo(client, GetWeaponAmmoOffset(weaponname), PlayerWeapon[client][0][2]);
  174.             PlayerWeapon[client][0][0] = -1;
  175.             PlayerWeapon[client][0][1] = -1;
  176.             PlayerWeapon[client][0][2] = -1;
  177.         }
  178.     }
  179.            
  180.     return Plugin_Stop;
  181. }
  182.  
  183.  
  184. public Action:Command_SwapPrimary(client, args)
  185. {
  186.     new weaponid, clip1, clip2;
  187.     new String: weaponname[32];
  188.     new colors[3];
  189.     if(PlayerisSwapping[client])
  190.         return Plugin_Handled;
  191.    
  192.     weaponid = GetPlayerWeaponSlot(client, 0);
  193.     if(weaponid != -1)
  194.     {
  195.         colors[0] = 225;
  196.         colors[1] = 10;
  197.         colors[2] = 0;
  198.        
  199.         if(PlayerWeapon[client][0][0] != -1)
  200.         {
  201.             clip1 = GetPrimaryAmmo(client, weaponid);
  202.             GetEdictClassname(weaponid, weaponname, sizeof(weaponname));
  203.             clip2 = GetWeaponAmmo(client, GetWeaponAmmoOffset(weaponname));
  204.             //PrintToConsole(client, "Got Primary Ammo: %d", clip1);
  205.             //PrintToConsole(client, "Got Secondary Ammo: %d", clip2);
  206.            
  207.            
  208.             //PrintToConsole(client, "Weapon: %s", weaponname);
  209.             RemovePlayerItem(client, weaponid);
  210.             weaponid = GetWeaponidByName(weaponname);
  211.             PlayerWeapon[client][1][0] = weaponid;
  212.             PlayerWeapon[client][1][1] = clip1;
  213.             PlayerWeapon[client][1][2] = clip2;
  214.             SendDialogToOne(client, colors, "Swapping primary weapons, please wait.");
  215.             PlayerisSwapping[client] = true;
  216.             CreateTimer(1.1,TimedWeaponSwap, client,TIMER_FLAG_NO_MAPCHANGE);
  217.             weaponid = GetPlayerWeaponSlot(client, 1);
  218.             if(weaponid != -1)
  219.             {
  220.                 ClientCommand(client, "slot2");
  221.             }
  222.             else
  223.             {
  224.                 ClientCommand(client, "slot3");
  225.             }
  226.         }
  227.         //PrintToConsole(client, "weapon Entity index: %d", weaponid);
  228.         if(PlayerWeapon[client][0][0] == -1)
  229.         {  
  230.             if(PlayerWeapon[client][1][0] == -1)
  231.             {
  232.                 clip1 = GetPrimaryAmmo(client, weaponid);
  233.                 GetEdictClassname(weaponid, weaponname, sizeof(weaponname));
  234.                 clip2 = GetWeaponAmmo(client, GetWeaponAmmoOffset(weaponname));
  235.                 //PrintToConsole(client, "Got Primary Ammo: %d", clip1);
  236.                 //PrintToConsole(client, "Got Secondary Ammo: %d", clip2);
  237.                
  238.                
  239.                 //PrintToConsole(client, "Weapon: %s", weaponname);
  240.                 RemovePlayerItem(client, weaponid);
  241.                 weaponid = GetWeaponidByName(weaponname);
  242.                 PlayerWeapon[client][0][0] = weaponid;
  243.                 PlayerWeapon[client][0][1] = clip1;
  244.                 PlayerWeapon[client][0][2] = clip2;
  245.                 SendDialogToOne(client, colors, "Your primary weapon was placed in your backpack.");
  246.                 PlayerisSwapping[client] = false;
  247.                
  248.                 weaponid = GetPlayerWeaponSlot(client, 1);
  249.                 if(weaponid != -1)
  250.                 {
  251.                     ClientCommand(client, "slot2");
  252.                 }
  253.                 else
  254.                 {
  255.                     ClientCommand(client, "slot3");
  256.                 }
  257.             }  
  258.         }
  259.     }
  260.     else if(PlayerWeapon[client][0][0] != -1)
  261.     {
  262.         PlayerisSwapping[client] = false;
  263.         GetWeaponByID(PlayerWeapon[client][0][0], weaponname, sizeof(weaponname));
  264.         GivePlayerItem(client, weaponname);
  265.         //PrintToConsole(client, "Weapon: %s", weaponname);
  266.         weaponid = GetPlayerWeaponSlot(client, 0);
  267.         SetPrimaryAmmo(client, weaponid, PlayerWeapon[client][0][1]);
  268.         GetEdictClassname(weaponid, weaponname, sizeof(weaponname));
  269.         SetWeaponAmmo(client, GetWeaponAmmoOffset(weaponname), PlayerWeapon[client][0][2]);
  270.         PlayerWeapon[client][0][0] = -1;
  271.         PlayerWeapon[client][0][1] = -1;
  272.         PlayerWeapon[client][0][2] = -1;
  273.     }
  274.    
  275.     return Plugin_Handled;
  276. }
  277.  
  278. public GetWeaponidByName(String:Weapon[])
  279. {
  280.     if(StrEqual(Weapon, "weapon_ak47", false))
  281.     {
  282.         return 0;
  283.     }
  284.     else if(StrEqual(Weapon, "weapon_aug", false))
  285.     {
  286.         return 1;
  287.     }
  288.     else if(StrEqual(Weapon, "weapon_awp", false))
  289.     {
  290.         return 2;
  291.     }
  292.     else if(StrEqual(Weapon, "weapon_deagle", false))
  293.     {  
  294.         return 3;
  295.     }
  296.     else if(StrEqual(Weapon, "weapon_elite", false))
  297.     {
  298.         return 4;
  299.     }
  300.     else if(StrEqual(Weapon, "weapon_famas", false))
  301.     {
  302.         return 5;
  303.     }
  304.     else if(StrEqual(Weapon, "weapon_fiveseven", false))
  305.     {
  306.         return 6;
  307.     }
  308.     else if(StrEqual(Weapon, "weapon_flashbang", false))
  309.     {
  310.         return 7;
  311.     }
  312.     else if(StrEqual(Weapon, "weapon_g3sg1", false))
  313.     {
  314.         return 8;
  315.     }
  316.     else if(StrEqual(Weapon, "weapon_galil", false))
  317.     {
  318.         return 9;
  319.     }
  320.     else if(StrEqual(Weapon, "weapon_glock", false))
  321.     {
  322.         return 10;
  323.     }
  324.     else if(StrEqual(Weapon, "weapon_hegrenade", false))
  325.     {
  326.         return 11;
  327.     }
  328.     else if(StrEqual(Weapon, "weapon_knife", false))
  329.     {
  330.         return 12;
  331.     }
  332.     else if(StrEqual(Weapon, "weapon_m249", false))
  333.     {
  334.         return 13;
  335.     }
  336.     else if(StrEqual(Weapon, "weapon_m3", false))
  337.     {
  338.         return 14;
  339.     }
  340.     else if(StrEqual(Weapon, "weapon_m4a1", false))
  341.     {
  342.         return 15;
  343.     }
  344.     else if(StrEqual(Weapon, "weapon_mac10", false))
  345.     {
  346.         return 16;
  347.     }
  348.     else if(StrEqual(Weapon, "weapon_mp5navy", false))
  349.     {
  350.         return 17;
  351.     }
  352.     else if(StrEqual(Weapon, "weapon_p228", false))
  353.     {
  354.         return 18;
  355.     }
  356.     else if(StrEqual(Weapon, "weapon_p90", false))
  357.     {
  358.         return 19;
  359.     }
  360.     else if(StrEqual(Weapon, "weapon_scout", false))
  361.     {
  362.         return 20;
  363.     }
  364.     else if(StrEqual(Weapon, "weapon_sg550", false))
  365.     {
  366.         return 21;
  367.     }
  368.     else if(StrEqual(Weapon, "weapon_sg552", false))
  369.     {
  370.         return 22;
  371.     }
  372.     else if(StrEqual(Weapon, "weapon_smokegrenade_projectile", false))
  373.     {
  374.         return 23;
  375.     }
  376.     else if(StrEqual(Weapon, "weapon_tmp", false))
  377.     {
  378.         return 24;
  379.     }
  380.     else if(StrEqual(Weapon, "weapon_ump45", false))
  381.     {
  382.         return 25;
  383.     }
  384.     else if(StrEqual(Weapon, "weapon_usp", false))
  385.     {
  386.         return 26;
  387.     }
  388.     else if(StrEqual(Weapon, "weapon_xm1014", false))
  389.     {
  390.         return 27;
  391.     }
  392.     else if(StrEqual(Weapon, "weapon_c4", false))
  393.     {
  394.         return 28;
  395.     }
  396.     else
  397.         return -1;
  398. }
  399.  
  400. public GetWeaponByID(weaponid, String:WeaponName[], maxlen)
  401. {
  402.     if(weaponid == 0)
  403.     {
  404.         strcopy(WeaponName, maxlen, "weapon_ak47");
  405.     }
  406.     else if(weaponid == 1)
  407.     {
  408.         strcopy(WeaponName, maxlen, "weapon_aug");
  409.     }
  410.     else if(weaponid == 2)
  411.     {
  412.         strcopy(WeaponName, maxlen, "weapon_awp");
  413.     }
  414.     else if(weaponid == 3)
  415.     {
  416.         strcopy(WeaponName, maxlen, "weapon_deagle");
  417.     }
  418.     else if(weaponid == 4)
  419.     {
  420.         strcopy(WeaponName, maxlen, "weapon_elite");
  421.     }
  422.     else if(weaponid == 5)
  423.     {
  424.         strcopy(WeaponName, maxlen, "weapon_famas");
  425.     }
  426.     else if(weaponid == 6)
  427.     {
  428.         strcopy(WeaponName, maxlen, "weapon_fiveseven");
  429.     }
  430.    
  431.     else if(weaponid == 7)
  432.     {
  433.         strcopy(WeaponName, maxlen, "weapon_flashbang");
  434.     }
  435.     else if(weaponid == 8)
  436.     {
  437.         strcopy(WeaponName, maxlen, "weapon_g3sg1");
  438.     }
  439.     else if(weaponid == 9)
  440.     {
  441.         strcopy(WeaponName, maxlen, "weapon_galil");
  442.     }
  443.     else if(weaponid == 10)
  444.     {
  445.         strcopy(WeaponName, maxlen, "weapon_glock");
  446.     }
  447.     else if(weaponid == 11)
  448.     {
  449.         strcopy(WeaponName, maxlen, "weapon_hegrenade");
  450.     }
  451.     else if(weaponid == 12)
  452.     {
  453.         strcopy(WeaponName, maxlen, "weapon_knife");
  454.     }
  455.     else if(weaponid == 13)
  456.     {
  457.         strcopy(WeaponName, maxlen, "weapon_m249");
  458.     }
  459.     else if(weaponid == 14)
  460.     {
  461.         strcopy(WeaponName, maxlen, "weapon_m3");
  462.     }
  463.     else if(weaponid == 15)
  464.     {
  465.         strcopy(WeaponName, maxlen, "weapon_m4a1");
  466.     }
  467.     else if(weaponid == 16)
  468.     {
  469.         strcopy(WeaponName, maxlen, "weapon_mac10");
  470.     }
  471.     else if(weaponid == 17)
  472.     {
  473.         strcopy(WeaponName, maxlen, "weapon_mp5navy");
  474.     }
  475.     else if(weaponid == 18)
  476.     {
  477.         strcopy(WeaponName, maxlen, "weapon_p228");
  478.     }
  479.     else if(weaponid == 19)
  480.     {
  481.         strcopy(WeaponName, maxlen, "weapon_p90");
  482.     }
  483.     else if(weaponid == 20)
  484.     {
  485.         strcopy(WeaponName, maxlen, "weapon_scout");
  486.     }
  487.     else if(weaponid == 21)
  488.     {
  489.         strcopy(WeaponName, maxlen, "weapon_sg550");
  490.     }
  491.     else if(weaponid == 22)
  492.     {
  493.         strcopy(WeaponName, maxlen, "weapon_sg552");
  494.     }
  495.     else if(weaponid == 23)
  496.     {
  497.         strcopy(WeaponName, maxlen, "weapon_smokegrenade");
  498.     }
  499.     else if(weaponid == 24)
  500.     {
  501.         strcopy(WeaponName, maxlen, "weapon_tmp");
  502.     }
  503.     else if(weaponid == 25)
  504.     {
  505.         strcopy(WeaponName, maxlen, "weapon_ump45");
  506.     }
  507.     else if(weaponid == 26)
  508.     {
  509.         strcopy(WeaponName, maxlen, "weapon_usp");
  510.     }
  511.     else if(weaponid == 27)
  512.     {
  513.         strcopy(WeaponName, maxlen, "weapon_xm1014");
  514.     }
  515.     else if(weaponid == 28)
  516.     {
  517.         strcopy(WeaponName, maxlen, "weapon_c4");
  518.     }
  519. }
  520.  
  521. public GetWeaponAmmoOffset(String:Weapon[])
  522. {
  523.     if(StrEqual(Weapon, "weapon_deagle", false))
  524.     {
  525.         return 1;
  526.     }
  527.     else if(StrEqual(Weapon, "weapon_ak47", false) || StrEqual(Weapon, "weapon_aug", false) || StrEqual(Weapon, "weapon_g3sg1", false) || StrEqual(Weapon, "weapon_scout", false))
  528.     {
  529.         return 2;
  530.     }
  531.     else if(StrEqual(Weapon, "weapon_famas", false) || StrEqual(Weapon, "weapon_galil", false) || StrEqual(Weapon, "weapon_m4a1", false) || StrEqual(Weapon, "weapon_sg550", false) || StrEqual(Weapon, "weapon_sg552", false))
  532.     {
  533.         return 3;
  534.     }
  535.     else if(StrEqual(Weapon, "weapon_m249", false))
  536.     {
  537.         return 4;
  538.     }
  539.     else if(StrEqual(Weapon, "weapon_awp", false))
  540.     {
  541.         return 5;
  542.     }
  543.     else if(StrEqual(Weapon, "weapon_elite", false) || StrEqual(Weapon, "weapon_glock", false) || StrEqual(Weapon, "weapon_mp5navy", false) || StrEqual(Weapon, "weapon_tmp", false))
  544.     {
  545.         return 6;
  546.     }
  547.     else if(StrEqual(Weapon, "weapon_xm1014", false) || StrEqual(Weapon, "weapon_m3", false))
  548.     {
  549.         return 7;
  550.     }
  551.     else if(StrEqual(Weapon, "weapon_mac10", false) || StrEqual(Weapon, "weapon_ump45", false) || StrEqual(Weapon, "weapon_usp", false))
  552.     {
  553.         return 8;
  554.     }
  555.     else if(StrEqual(Weapon, "weapon_p228", false))
  556.     {
  557.         return 9;
  558.     }
  559.     else if(StrEqual(Weapon, "weapon_fiveseven", false) || StrEqual(Weapon, "weapon_p90", false))
  560.     {
  561.         return 10;
  562.     }
  563.     else if(StrEqual(Weapon, "weapon_hegrenade", false))
  564.     {
  565.         return 11;
  566.     }
  567.     else if(StrEqual(Weapon, "weapon_flashbang", false))
  568.     {
  569.         return 12;
  570.     }
  571.     else if(StrEqual(Weapon, "weapon_smokegrenade", false))
  572.     {
  573.         return 13;
  574.     }
  575.     return -1;
  576. }
  577.  
  578. SendDialogToOne(client, color[3], String:text[], any:...)
  579. {
  580.     new String:message[100];
  581.     VFormat(message, sizeof(message), text, 4);
  582.    
  583.     new Handle:kv = CreateKeyValues("Stuff", "title", message);
  584.     KvSetColor(kv, "color", color[0], color[1], color[2], 255);
  585.     KvSetNum(kv, "level", 2);
  586.     KvSetNum(kv, "time", 2);
  587.    
  588.     CreateDialog(client, kv, DialogType_Msg);
  589.    
  590.     CloseHandle(kv);   
  591. }
  592.  
  593. stock GetWeaponAmmo(client, slot)
  594. {
  595.     new ammoOffset = FindSendPropInfo("CCSPlayer", "m_iAmmo");
  596.     return GetEntData(client, ammoOffset+(slot*4));
  597. }  
  598.  
  599. stock SetWeaponAmmo(client, slot, ammo)
  600. {
  601.     new ammoOffset = FindSendPropInfo("CCSPlayer", "m_iAmmo");
  602.     return SetEntData(client, ammoOffset+(slot*4), ammo);
  603. }
  604.  
  605. stock GetPrimaryAmmo(client, weap)
  606. {  
  607.     //new myweapons = FindSendPropInfo("CCSPlayer", "m_hMyWeapons");  
  608.     //new weap = GetEntDataEnt2(client, myweapons+ (slot*4));
  609.     if(IsValidEntity(weap))
  610.         return GetEntData(weap, FindSendPropInfo("CBaseCombatWeapon", "m_iClip1"));
  611.     return 0;
  612. }
  613.  
  614. stock SetPrimaryAmmo(client, weap, ammo)
  615. {    
  616.     //new myweapons = FindSendPropInfo("CCSPlayer", "m_hMyWeapons");  
  617.     //new weap = GetEntDataEnt2(client, myweapons+ (slot*4));
  618.     if(IsValidEntity(weap))
  619.         return SetEntData(weap, FindSendPropInfo("CBaseCombatWeapon", "m_iClip1"), ammo);
  620.     return 0;
  621. }
  622.  
  623. OnButtonPress(client, button)
  624. {
  625.     switch(button)
  626.     {
  627.         case IN_USE:
  628.         {
  629.             new weaponid, clip1, clip2;
  630.     new String: weaponname[32];
  631.     new colors[3];
  632.     if(PlayerisSwapping[client])
  633.         return Plugin_Handled;
  634.    
  635.     weaponid = GetPlayerWeaponSlot(client, 0);
  636.     if(weaponid != -1)
  637.     {
  638.         colors[0] = 225;
  639.         colors[1] = 10;
  640.         colors[2] = 0;
  641.        
  642.         if(PlayerWeapon[client][0][0] != -1)
  643.         {
  644.             clip1 = GetPrimaryAmmo(client, weaponid);
  645.             GetEdictClassname(weaponid, weaponname, sizeof(weaponname));
  646.             clip2 = GetWeaponAmmo(client, GetWeaponAmmoOffset(weaponname));
  647.             //PrintToConsole(client, "Got Primary Ammo: %d", clip1);
  648.             //PrintToConsole(client, "Got Secondary Ammo: %d", clip2);
  649.            
  650.            
  651.             //PrintToConsole(client, "Weapon: %s", weaponname);
  652.             RemovePlayerItem(client, weaponid);
  653.             weaponid = GetWeaponidByName(weaponname);
  654.             PlayerWeapon[client][swap_count+1][0] = weaponid;
  655.             PlayerWeapon[client][swap_count+1][1] = clip1;
  656.             PlayerWeapon[client][swap_count+1][2] = clip2;
  657.             SendDialogToOne(client, colors, "Swapping primary weapons, please wait.");
  658.             PlayerisSwapping[client] = true;
  659.             CreateTimer(1.1,TimedWeaponSwap, client,TIMER_FLAG_NO_MAPCHANGE);
  660.             weaponid = GetPlayerWeaponSlot(client, 1);
  661.             if(weaponid != -1)
  662.             {
  663.                 ClientCommand(client, "slot2");
  664.             }
  665.             else
  666.             {
  667.                 ClientCommand(client, "slot3");
  668.             }
  669.         }
  670.         //PrintToConsole(client, "weapon Entity index: %d", weaponid);
  671.         if(PlayerWeapon[client][swap_count][0] == -1)
  672.         {  
  673.             if(PlayerWeapon[client][swap_count+1][0] == -1)
  674.             {
  675.                 clip1 = GetPrimaryAmmo(client, weaponid);
  676.                 GetEdictClassname(weaponid, weaponname, sizeof(weaponname));
  677.                 clip2 = GetWeaponAmmo(client, GetWeaponAmmoOffset(weaponname));
  678.                 //PrintToConsole(client, "Got Primary Ammo: %d", clip1);
  679.                 //PrintToConsole(client, "Got Secondary Ammo: %d", clip2);
  680.                
  681.                
  682.                 //PrintToConsole(client, "Weapon: %s", weaponname);
  683.                 RemovePlayerItem(client, weaponid);
  684.                 weaponid = GetWeaponidByName(weaponname);
  685.                 PlayerWeapon[client][swap_count][0] = weaponid;
  686.                 PlayerWeapon[client][swap_count][1] = clip1;
  687.                 PlayerWeapon[client][swap_count][2] = clip2;
  688.                 SendDialogToOne(client, colors, "Your primary weapon was placed in your backpack.");
  689.                 PlayerisSwapping[client] = false;
  690.                
  691.                 weaponid = GetPlayerWeaponSlot(client, 1);
  692.                 if(weaponid != -1)
  693.                 {
  694.                     ClientCommand(client, "slot2");
  695.                 }
  696.                 else
  697.                 {
  698.                     ClientCommand(client, "slot3");
  699.                 }
  700.             }  
  701.         }
  702.         swap_count++;
  703.     }
  704.     else if(PlayerWeapon[client][swap_count][0] != -1)
  705.     {
  706.         PlayerisSwapping[client] = false;
  707.         GetWeaponByID(PlayerWeapon[client][swap_count][0], weaponname, sizeof(weaponname));
  708.         GivePlayerItem(client, weaponname);
  709.         //PrintToConsole(client, "Weapon: %s", weaponname);
  710.         weaponid = GetPlayerWeaponSlot(client, 0);
  711.         SetPrimaryAmmo(client, weaponid, PlayerWeapon[client][swap_count][1]);
  712.         GetEdictClassname(weaponid, weaponname, sizeof(weaponname));
  713.         SetWeaponAmmo(client, GetWeaponAmmoOffset(weaponname), PlayerWeapon[client][swap_count][2]);
  714.         PlayerWeapon[client][swap_count][0] = -1;
  715.         PlayerWeapon[client][swap_count][1] = -1;
  716.         PlayerWeapon[client][swap_count][2] = -1;
  717.     }
  718.    
  719.         }
  720.     }
  721.     return Plugin_Handled;
  722. }
  723.  
  724. OnButtonRelease(client, button)
  725. {
  726.  
  727. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement