SHARE
TWEET

[FS]Holding Weapons

yugecin Mar 28th, 2012 2,766 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*************************************************************
  2.  Holding Weapons Filterscript
  3.  -» Author             : Claerhout Robin (yugecin)
  4.  -» Release Date       : 28th March 2012
  5.  -» Description        : You hold weapons when you are not using them.
  6.  -» Video              : http://www.youtube.com/watch?v=Z4DDxK1vwQ8
  7.  -» forum post         : http://forum.sa-mp.com/showthread.php?t=329467
  8.  -» NOTE               : USES PlayerAttachedObjectSlots 0-8
  9. **************************************************************/
  10. #include <a_samp>
  11. #define TIME 250 //Timer for check if player is cycling through weapons or received another weapon (in ms)
  12. #define playercommand //comment this line to disable the /holdingweapon command for players
  13. forward Enable(playerid);
  14. forward Disable(playerid);
  15. forward AttachWeapon();
  16. forward HoldingWeaponsForAll(boolean);
  17. new wep[MAX_PLAYERS] = -1, timer, weps[12], d[MAX_PLAYERS] = 1, d1 = 1, camera[MAX_PLAYERS];
  18. public OnFilterScriptInit() {
  19.         timer = SetTimer("AttachWeapon", TIME, 1);
  20.         return print("[FS]HoldingWeapons Loaded!");
  21. }
  22.  
  23. public OnFilterScriptExit() {
  24.         for(new i = 0; i < MAX_PLAYERS+1; i++) if(IsPlayerConnected(i)) if(!IsPlayerNPC(i))     for(new a = 0; a < 10; a++)     if(IsPlayerAttachedObjectSlotUsed(i, a)) RemovePlayerAttachedObject(i, a);
  25.         return print("[FS]HoldingWeapons Unloaded!");
  26. }
  27.  
  28. public AttachWeapon(){
  29.         for(new i = 0; i < MAX_PLAYERS+1; i++){
  30.             if(IsPlayerNPC(i)) return 1;
  31.             if(IsPlayerInAnyVehicle(i)) {
  32.                         for(new a = 0; a < 9; a++) if(IsPlayerAttachedObjectSlotUsed(i, a)) RemovePlayerAttachedObject(i, a);
  33.                         wep[i] = -1;
  34.                         return 1;
  35.                 }
  36.                 if(!d[i]) return 1;
  37.                 if(camera[i]) return 1;
  38.            
  39.             if(wep[i] != GetPlayerWeapon(i)) for(new a = 0; a < 12; a++){
  40.                 GetPlayerWeaponData(i, a, weps[a], weps[6]);
  41.                         switch(a){
  42.                             case 0: {
  43.                                 if(IsPlayerAttachedObjectSlotUsed(i, 0)) RemovePlayerAttachedObject(i, 0);
  44.                                 if(weps[a] == 1 && GetPlayerWeapon(i) != 1) SetPlayerAttachedObject( i, 0, 331, 6, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 1.000000, 1.000000 );
  45.                             }
  46.                             case 1: {
  47.                                 if(IsPlayerAttachedObjectSlotUsed(i, 1)) RemovePlayerAttachedObject(i, 1);
  48.                                 switch(weps[a]){
  49.                                                 case 4: if(GetPlayerWeapon(i) != 4) SetPlayerAttachedObject( i, 0, 335, 11, 0.142010, -0.100988, 0.055910, 76.125000, 75.876144, 1.143326, 1.000000, 1.000000, 1.000000 );
  50.                                                 case 8: if(GetPlayerWeapon(i) != 8) SetPlayerAttachedObject( i, 1, 339, 15, 0.088326, 0.066626, 0.148351, 191.990447, 341.412963, 0.000000, 1.000000, 1.000000, 1.000000 );
  51.                                         }
  52.                             }
  53.                             case 2: {
  54.                                 if(IsPlayerAttachedObjectSlotUsed(i, 2)) RemovePlayerAttachedObject(i, 2);
  55.                                 switch(weps[a]){
  56.                                                 case 22: if(GetPlayerWeapon(i) != 22) SetPlayerAttachedObject( i, 2, 346, 8, -0.028010, -0.033822, 0.097883, 270.000000, 15.999426, 354.161499, 1.000000, 1.000000, 1.000000 );
  57.                                                 case 23: if(GetPlayerWeapon(i) != 23) SetPlayerAttachedObject( i, 2, 346, 8, -0.028010, -0.033822, 0.097883, 270.000000, 15.999426, 354.161499, 1.000000, 1.000000, 1.000000 );
  58.                                                 case 24: if(GetPlayerWeapon(i) != 24) SetPlayerAttachedObject( i, 2, 348, 8, -0.040643, -0.048525, 0.085376, 270.000000, 8.253683, 0.000000, 1.000000, 1.000000, 1.000000 );
  59.                                         }
  60.                             }
  61.                             case 3: {
  62.                                 if(IsPlayerAttachedObjectSlotUsed(i, 3)) RemovePlayerAttachedObject(i, 3);
  63.                                 switch(weps[a]){
  64.                                                 case 25: if(GetPlayerWeapon(i) != 25) SetPlayerAttachedObject( i, 3, 349, 16, 0.084126, 0.131737, 0.197423, 176.984542, 92.569320, 14.483574, 1.000000, 1.000000, 1.000000 );
  65.                                                 case 26: if(GetPlayerWeapon(i) != 26) SetPlayerAttachedObject( i, 3, 350, 16, 0.090676, 0.085271, -0.075131, 0.000000, 289.166870, 355.209869, 1.000000, 1.000000, 1.000000 );
  66.                                                 case 27: if(GetPlayerWeapon(i) != 27) SetPlayerAttachedObject( i, 3, 351, 16, 0.100795, 0.057224, -0.082939, 180.000000, 243.483581, 180.000000, 1.000000, 1.000000, 1.000000 );
  67.                                         }
  68.                             }
  69.                             case 4: {
  70.                                 if(IsPlayerAttachedObjectSlotUsed(i, 4)) RemovePlayerAttachedObject(i, 4);
  71.                                 switch(weps[a]){
  72.                                                 case 28: if(GetPlayerWeapon(i) != 28) SetPlayerAttachedObject( i, 4, 352, 7, 0.138560, -0.033982, -0.047630, 281.671447, 276.618591, 4.068862, 1.000000, 1.000000, 1.000000 );
  73.                                                 case 29: if(GetPlayerWeapon(i) != 29) SetPlayerAttachedObject( i, 4, 353, 7, 0.008329, -0.067031, -0.060214, 289.865051, 17.391622, 7.667663, 1.000000, 1.000000, 1.000000 );
  74.                                                 case 32: if(GetPlayerWeapon(i) != 32) SetPlayerAttachedObject( i, 4, 372, 7, 0.056180, -0.008887, -0.007959, 270.000000, 13.921591, 5.905599, 1.000000, 1.000000, 1.000000 );
  75.                                         }
  76.                             }
  77.                             case 5: {
  78.                                 if(IsPlayerAttachedObjectSlotUsed(i, 5)) RemovePlayerAttachedObject(i, 5);
  79.                                 switch(weps[a]){
  80.                                                 case 30: if(GetPlayerWeapon(i) != 30) SetPlayerAttachedObject( i, 5, 355, 1, -0.130044, -0.127836, 0.025491, 2.044970, 6.239807, 6.833646, 1.000000, 1.000000, 1.000000 );
  81.                                                 case 31: if(GetPlayerWeapon(i) != 31) SetPlayerAttachedObject( i, 5, 356, 16, 0.019280, 0.118553, 0.396286, 70.920410, 274.673919, 253.978057, 1.000000, 1.000000, 1.000000 );
  82.                                         }
  83.                             }
  84.                             case 8: {
  85.                                 if(IsPlayerAttachedObjectSlotUsed(i, 6)) RemovePlayerAttachedObject(i, 6);
  86.                                 switch(weps[a]){
  87.                                                 case 16: if(GetPlayerWeapon(i) != 16) SetPlayerAttachedObject( i, 6, 342, 16, -0.110845, -0.041751, 0.087840, 55.051963, 84.884071, 247.221984, 1.000000, 1.000000, 1.000000 );
  88.                                                 case 17: if(GetPlayerWeapon(i) != 17) SetPlayerAttachedObject( i, 6, 1672, 16, -0.110606, -0.054021, 0.036716, 215.687911, 354.659393, 90.000000, 1.000000, 1.000000, 1.000000 );
  89.                                                 case 18: if(GetPlayerWeapon(i) != 18) SetPlayerAttachedObject( i, 6, 344, 15, 0.029351, -0.208807, -0.164047, 0.000000, 359.932037, 0.000000, 1.000000, 1.000000, 1.000000 );
  90.                                         }
  91.                             }
  92.                             case 9: {
  93.                                 if(IsPlayerAttachedObjectSlotUsed(i, 7)) RemovePlayerAttachedObject(i, 7);
  94.                                 switch(weps[a]){
  95.                                                 case 43: if(GetPlayerWeapon(i) != 43) SetPlayerAttachedObject( i, 7, 367, 1, 0.227036, 0.171111, -0.085516, 270.000000, 0.000000, 180.000000, 1.000000, 1.000000, 1.000000 );
  96.                                                 case 41: if(GetPlayerWeapon(i) != 41) SetPlayerAttachedObject( i, 7, 365, 12, 0.174919, -0.004211, -0.142508, 0.000000, 270.000000, 0.000000, 1.000000, 1.000000, 1.000000 );
  97.                                         }
  98.                             }
  99.                             case 11: {
  100.                                 if(IsPlayerAttachedObjectSlotUsed(i, 8)) RemovePlayerAttachedObject(i, 8);
  101.                                 if(weps[a] == 44 || weps[a] == 45) if(GetPlayerWeapon(i) != 44 && GetPlayerWeapon(i) != 45) SetPlayerAttachedObject( i, 8, 369, 2, 0.000000, 0.078037, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 1.000000, 1.000000 );
  102.                             }
  103.                         }
  104.             }
  105.             wep[i] = GetPlayerWeapon(i);
  106.         }
  107.         return 1;
  108. }
  109.  
  110. public OnPlayerCommandText(playerid, cmdtext[]){
  111.     if(!strcmp(cmdtext, "/holdingweapons", true)){
  112.                 #if defined playercommand
  113.                 if(d1){
  114.                         if(d[playerid]){
  115.                                         SendClientMessage(playerid, 0x0000FFAA, "[HWEAPONS] {FFFFFF}Disabled.");
  116.                                         Disable(playerid);
  117.                         } else {
  118.                                         SendClientMessage(playerid, 0x0000FFAA, "[HWEAPONS] {FFFFFF}Enabled.");
  119.                             Enable(playerid);
  120.                         }
  121.                         } else SendClientMessage(playerid, 0x0000FFAA, "[HWEAPONS] {FFFFFF}This function is disabled.");
  122.                 return 1;
  123.                 #else
  124.                         return SendClientMessage(playerid, 0x0000FFAA, "[HWEAPONS] {FFFFFF}This function is disabled.");
  125.                 #endif
  126.     }
  127.     return 0;
  128. }
  129.  
  130. public Disable(playerid) {
  131.     d[playerid] = 0;
  132.     wep[playerid] = -1;
  133.     for(new a = 0; a < 9; a++) if(IsPlayerAttachedObjectSlotUsed(playerid, a)) RemovePlayerAttachedObject(playerid, a);
  134.         return 1;
  135. }
  136.  
  137. public Enable(playerid) {
  138.     d[playerid] = 1;
  139.         return 1;
  140. }
  141.  
  142. public HoldingWeaponsForAll(boolean) {
  143.         if(boolean == 0){
  144.                 if(!d1) return 1;
  145.                 for(new i = 0; i < MAX_PLAYERS+1; i++) for(new a = 0; a < 9; a++) if(IsPlayerAttachedObjectSlotUsed(i, a)) RemovePlayerAttachedObject(i, a);
  146.                 KillTimer(timer);
  147.                 d1 = 0;
  148.             return 1;
  149.         }
  150.         if(boolean == 1){
  151.                 if(d1) return 1;
  152.                 timer = SetTimer("AttachWeapon", TIME, 1);
  153.                 d1 = 1;
  154.                 return 1;
  155.         }
  156.         return 0;
  157. }
  158.  
  159. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys){
  160.     if(newkeys == 128 && oldkeys != 128 && GetPlayerWeapon(playerid) == 43) {
  161.         camera[playerid] = 1;
  162.         for(new a = 0; a < 9; a++) if(IsPlayerAttachedObjectSlotUsed(playerid, a)) RemovePlayerAttachedObject(playerid, a);
  163.     }
  164.         if(newkeys != 128 && oldkeys == 128 && GetPlayerWeapon(playerid) == 43) camera[playerid] = 0;
  165.         return 1;
  166. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top