Advertisement
Guest User

Passenger Weapon Switching

a guest
Apr 10th, 2016
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.54 KB | None | 0 0
  1. #define     FILTERSCRIPT
  2. #include    <a_samp>
  3.  
  4. // taken from weapon-config (https://github.com/oscar-broman/samp-weapon-config/blob/master/weapon-config.inc)
  5. IsBulletWeapon(weaponid)
  6.     return (WEAPON_COLT45 <= weaponid <= WEAPON_SNIPER) || weaponid == WEAPON_MINIGUN;
  7.  
  8. GetWeaponSlot(weaponid)
  9. {
  10.     switch(weaponid)
  11.     {
  12.         case 1: return 0;
  13.         case 2..9: return 1;
  14.         case 22..24: return 2;
  15.         case 25..27: return 3;
  16.         case 28, 29, 32: return 4;
  17.         case 30, 31: return 5;
  18.         case 33, 34: return 6;
  19.         case 35..38: return 7;
  20.         case 16..18, 39: return 8;
  21.         case 41..43: return 9;
  22.         case 10..15: return 10;
  23.         case 44..46: return 11;
  24.         case 40: return 12;
  25.     }
  26.  
  27.     return -1;
  28. }
  29.  
  30. SetPlayerArmedWeaponEx(playerid, weaponid)
  31. {
  32.     SetPVarInt(playerid, "switch_WeaponID", weaponid);
  33.     PlayerPlaySound(playerid, 1138, 0.0, 0.0, 0.0);
  34.     return SetPlayerArmedWeapon(playerid, weaponid);
  35. }
  36.  
  37. public OnPlayerStateChange(playerid, newstate, oldstate)
  38. {
  39.     if(newstate == PLAYER_STATE_PASSENGER)
  40.     {
  41.         new weapID = GetPlayerWeapon(playerid);
  42.         SetPVarInt(playerid, "switch_WeaponID", weapID);
  43.         if(IsBulletWeapon(weapID)) SendClientMessage(playerid, 0x3F9DDDFF, "WEAPON SWITCHING: {FFFFFF}You can switch weapons using ~k~~CONVERSATION_YES~/~k~~CONVERSATION_NO~.");
  44.     }
  45.    
  46.     return 1;
  47. }
  48.  
  49. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  50. {
  51.     if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER && IsBulletWeapon(GetPVarInt(playerid, "switch_WeaponID")))
  52.     {
  53.         // Next Weapon
  54.         if(newkeys & KEY_YES)
  55.         {
  56.             new curWeap = GetPVarInt(playerid, "switch_WeaponID"), weapSlot = GetWeaponSlot(curWeap), weapID, weapAmmo;
  57.            
  58.             for(new i = weapSlot + 1; i <= 7; i++)
  59.             {
  60.                 GetPlayerWeaponData(playerid, i, weapID, weapAmmo);
  61.                 if(IsBulletWeapon(weapID) && weapID != curWeap)
  62.                 {
  63.                     SetPlayerArmedWeaponEx(playerid, weapID);
  64.                     GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~n~~y~~h~Next Weapon ~>~", 1000, 3);
  65.                     break;
  66.                 }
  67.             }
  68.         }
  69.  
  70.         // Previous Weapon
  71.         if(newkeys & KEY_NO)
  72.         {
  73.             new curWeap = GetPVarInt(playerid, "switch_WeaponID"), weapSlot = GetWeaponSlot(curWeap), weapID, weapAmmo;
  74.            
  75.             for(new i = weapSlot - 1; i >= 2; i--)
  76.             {
  77.                 GetPlayerWeaponData(playerid, i, weapID, weapAmmo);
  78.                 if(IsBulletWeapon(weapID) && weapID != curWeap)
  79.                 {
  80.                     SetPlayerArmedWeaponEx(playerid, weapID);
  81.                     GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~n~~y~~h~~<~ Previous Weapon", 1000, 3);
  82.                     break;
  83.                 }
  84.             }
  85.         }
  86.     }
  87.  
  88.     return 1;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement