Advertisement
JeffryUGP

[FS] WeaponDrop v1.1

Jun 30th, 2013
1,568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.51 KB | None | 0 0
  1. /*======================================================================================================*
  2. * This Weapon-Drop Filterscript is made by Jeffry!                                                      *
  3. *                                                                                                       *
  4. *                                                                                                       *
  5. * Made in April 2011. Updated in June 2013                                                              *
  6. *                                                                                                       *
  7. * Your Rights:                                                                                          *
  8. *                                                                                                       *
  9. * -You are allowed to modify this Filterscript, aslong as you DO NOT remove credits or re-upload it.    *
  10. *                                                                                                       *
  11. * -You are NOT allowed to re-upload this Filterscript.                                                  *
  12. * -You are NOT allowed to claim this as your own.                                                       *
  13. * -You are NOT allowed to remove any credits.                                                           *
  14. *                                                                                                       *
  15. * Thank you.                                                                                            *
  16. * Have fun. I would be happy if you give me /credits.  :D                                               *
  17. *                                                                                                       *
  18. *=======================================================================================================*/
  19. #include <a_samp>
  20. //===============================================================================================================================================
  21. //-------------------------Definitions that you may change---------------------------------------------------------------------------------------
  22. //-----------------------------------------------------------------------------------------------------------------------------------------------
  23. #define WEAPON_RESPAWN_TIME 30                // After this time the pickups get destroyed if not picked up.
  24. #define MONEY_BAG_MONEY      0               // -1 = Money bag ON with all player-money   0 = Money bag OFF   1+ = Money bag ON with given amount
  25. #define MONEY_BAG_MODE       0              // 1 = Money comes from the killed player     0 = Money comes from the server
  26. new ForbiddenWeapons[]= { 38, 44, 45 };    // Here you add the weapon IDs that you do not want to be created.
  27. //-----------------------------------------------------------------------------------------------------------------------------------------------
  28. //-------------------------End of the Definitions------------------------------------------------------------------------------------------------
  29. //===============================================================================================================================================
  30.  
  31. //=============The Variables====================================================
  32. new WeaponDrop[MAX_PLAYERS][14];
  33. new WeaponData[MAX_PLAYERS][14][3];
  34. new WeaponTimer[MAX_PLAYERS];
  35. new BagMoney = MONEY_BAG_MONEY;
  36. new BagMode = MONEY_BAG_MODE;
  37.  
  38. //=============The Callbacks====================================================
  39. public OnFilterScriptInit()
  40. {
  41.     OnWeaponDropInit();
  42.     return 1;
  43. }
  44.  
  45. public OnPlayerPickUpPickup(playerid, pickupid)
  46. {
  47.     OnWeaponDropPickup(playerid, pickupid);
  48.     return 1;
  49. }
  50.  
  51. public OnPlayerDeath(playerid, killerid, reason)
  52. {
  53.     OnWeaponDrop(playerid);
  54.     return 1;
  55. }
  56.  
  57. public OnPlayerCommandText(playerid, cmdtext[])
  58. {
  59.     if(OnWeaponDropCommand(playerid, cmdtext) == 1) return 1;
  60.     return 0;
  61. }
  62.  
  63. public OnFilterScriptExit()
  64. {
  65.     OnWeaponDropExit();
  66.     return 1;
  67. }
  68.  
  69. //=============The Functions====================================================
  70. stock OnWeaponDropInit()
  71. {
  72.     for(new i=0; i<MAX_PLAYERS; i++)
  73.     {
  74.         for(new a=0; a<14; a++)
  75.         {
  76.             WeaponDrop[i][a] = -1;
  77.             WeaponData[i][a][0] = -1;
  78.             WeaponData[i][a][1] = -1;
  79.             WeaponData[i][a][2] = -1;
  80.         }
  81.         WeaponTimer[i] = -1;
  82.     }
  83.     print("\n--------------------------------------");
  84.     print("[FS] WeaponDrop v1.1 by Jeffry loaded!");
  85.     print("--------------------------------------\n");
  86.     return 1;
  87. }
  88.  
  89. stock OnWeaponDropPickup(playerid, pickupid)
  90. {
  91.     new world = GetPlayerVirtualWorld(playerid);
  92.     for(new i=0; i<MAX_PLAYERS; i++)
  93.     {
  94.         for(new a=0; a<13; a++)
  95.         {
  96.             if(WeaponDrop[i][a] == pickupid && WeaponData[i][a][2] == world)
  97.             {
  98.                 WeaponDrop[i][a] = -1;
  99.                 DestroyPickup(pickupid);
  100.                 GivePlayerWeapon(playerid, WeaponData[i][a][0], WeaponData[i][a][1]);
  101.                 WeaponData[i][a][0] = -1;
  102.                 WeaponData[i][a][1] = -1;
  103.             }
  104.         }
  105.         if(WeaponDrop[i][13] == pickupid)
  106.         {
  107.             WeaponDrop[i][13] = -1;
  108.             DestroyPickup(pickupid);
  109.             GivePlayerMoney(playerid, WeaponData[i][13][0]);
  110.             WeaponData[i][13][0] = -1;
  111.             WeaponData[i][13][1] = -1;
  112.         }
  113.     }
  114.  
  115.     return 1;
  116. }
  117.  
  118. stock OnWeaponDrop(playerid)
  119. {
  120.     RemovePickups(playerid);
  121.     new Float:x, Float:y, Float:z, dropped;
  122.     GetPlayerPos(playerid,x,y,z);
  123.     new world = GetPlayerVirtualWorld(playerid);
  124.     for(new i=0; i<13; i++)
  125.     {
  126.         new weapon, ammo;
  127.         GetPlayerWeaponData(playerid, i, weapon, ammo);
  128.         if((ammo > 0 || weapon == 1) && weapon != 0)
  129.         {
  130.             new model = GetModel(weapon);
  131.             if(model != -1)
  132.             {
  133.                 WeaponData[playerid][i][0] = weapon;
  134.                 WeaponData[playerid][i][1] = ammo;
  135.                 WeaponData[playerid][i][2] = world;
  136.                 dropped++;
  137.             }
  138.         }
  139.     }
  140.     if(BagMoney != 0)
  141.     {
  142.         if(BagMoney == -1 && GetPlayerMoney(playerid) > 0)
  143.         {
  144.             WeaponData[playerid][13][0] = GetPlayerMoney(playerid);
  145.             if(BagMode) GivePlayerMoney(playerid, -WeaponData[playerid][13][0]);
  146.             WeaponDrop[playerid][13] = CreatePickup(1550, 1, x, y, z);
  147.             if(dropped <= 0) dropped=1;
  148.         }
  149.         if(BagMoney > 0)
  150.         {
  151.             WeaponData[playerid][13][0] = BagMoney;
  152.             if(BagMode) GivePlayerMoney(playerid, -WeaponData[playerid][13][0]);
  153.             WeaponDrop[playerid][13] = CreatePickup(1550, 1, x, y, z);
  154.             if(dropped <= 0) dropped=1;
  155.         }
  156.     }
  157.     if(dropped > 0)
  158.     {
  159.         new radius;
  160.         if(dropped < 3) radius = 1;
  161.         if(dropped < 6) radius = 2;             /*If you want another radius, change it here.*/
  162.         if(dropped < 9) radius = 3;
  163.         if(dropped > 8) radius = 4;
  164.         new Float:degree, Float:tmp;
  165.         degree = 360.0 / (float(dropped));
  166.         tmp = degree;
  167.         if(WeaponTimer[playerid] != -1) KillTimer(WeaponTimer[playerid]);
  168.         WeaponTimer[playerid] = SetTimerEx("RemovePickups", WEAPON_RESPAWN_TIME*1000, 0, "d", playerid);
  169.         for(new i=0; i<13; i++)
  170.         {
  171.             if((WeaponData[playerid][i][1] > 0 || WeaponData[playerid][i][0] == 1) && WeaponData[playerid][i][0] > 0)
  172.             {
  173.                 new model = GetModel(WeaponData[playerid][i][0]);
  174.                 if(model != -1)
  175.                 {
  176.                     WeaponDrop[playerid][i] = CreatePickup(model, 1, x+(floatsin(degree, degrees)*radius), y+(floatcos(degree, degrees)*radius), z, world);
  177.                     degree = degree + tmp;
  178.                 }
  179.             }
  180.         }
  181.     }
  182.     return 1;
  183. }
  184.  
  185. stock OnWeaponDropCommand(playerid, cmdtext[])
  186. {
  187.     if(!strcmp(cmdtext, "/dropweapon", true, 11))
  188.     {
  189.         if((strlen(cmdtext[11]) && cmdtext[11] == ' ') || !strlen(cmdtext[11]))
  190.         {
  191.             if(strlen(cmdtext[11]) && cmdtext[11] == ' ' && !strlen(cmdtext[12])) return SendClientMessage(playerid,0xFF0000FF,"Usage: /dropweapon [ammo]");
  192.             new Float:x, Float:y, Float:z;
  193.             GetPlayerPos(playerid,x,y,z);
  194.             if(x > 4095.0 || x < -4095.0 || y > 4095.0 || y < -4095.0 || z > 4095.0 || z < -4095.0) return SendClientMessage(playerid,0xFF0000FF,"ERROR: You can not drop any weapons here, because pickups do not show here anymore (SA-MP issue).");
  195.             new world = GetPlayerVirtualWorld(playerid);
  196.             new weapon, ammo, dropped, i = GetWeaponSlot(GetPlayerWeapon(playerid));
  197.             GetPlayerWeaponData(playerid, i, weapon, ammo);
  198.             if(weapon == 0) return SendClientMessage(playerid,0xFF0000FF,"ERROR: You are not holding any weapon.");
  199.             new dammo;
  200.             if(strval(cmdtext[11]) == 0) dammo = 0;
  201.             else dammo = strval(cmdtext[12]);
  202.             if(strlen(cmdtext[12])) if(dammo < 1) return SendClientMessage(playerid,0xFF0000FF,"ERROR: Invalid ammo.");
  203.             if(dammo > ammo) return SendClientMessage(playerid,0xFF0000FF,"ERROR: You don't have that much ammo.");
  204.             if(dammo == 0) dammo = ammo;
  205.             if((ammo > 0 || weapon == 1) && weapon != 0)
  206.             {
  207.                 new model = GetModel(weapon);
  208.                 if(model != -1)
  209.                 {
  210.                     WeaponData[playerid][i][0] = weapon;
  211.                     WeaponData[playerid][i][1] = dammo;
  212.                     WeaponData[playerid][i][2] = world;
  213.                     dropped++;
  214.                 }
  215.             }
  216.             if(dropped > 0)
  217.             {
  218.                 if(WeaponDrop[playerid][i] != -1)
  219.                 {
  220.                     DestroyPickup(WeaponDrop[playerid][i]);
  221.                     WeaponDrop[playerid][i] = -1;
  222.                 }
  223.                 if(WeaponTimer[playerid] != -1) KillTimer(WeaponTimer[playerid]);
  224.                 WeaponTimer[playerid] = SetTimerEx("RemovePickups", WEAPON_RESPAWN_TIME*1000, 0, "d", playerid);
  225.                 if((WeaponData[playerid][i][1] > 0 || WeaponData[playerid][i][0] == 1) && WeaponData[playerid][i][0] > 0)
  226.                 {
  227.                     new model = GetModel(WeaponData[playerid][i][0]);
  228.                     if(model != -1)
  229.                     {
  230.                         new Float:a;
  231.                         GetPlayerFacingAngle(playerid, a);
  232.                         WeaponDrop[playerid][i] = CreatePickup(model, 1, x+(floatsin(-a, degrees)*2), y+(floatcos(-a, degrees)*2), z, world);
  233.                     }
  234.                 }
  235.             }
  236.             else return SendClientMessage(playerid,0xFF00FFFF,"ERROR: You can not drop this weapon.");
  237.             new u_savedweapon[13], u_savedammo[13];
  238.             for(new a=0; a<13; a++) GetPlayerWeaponData(playerid, a, u_savedweapon[a], u_savedammo[a]);
  239.             u_savedammo[i] -= dammo;
  240.             ResetPlayerWeapons(playerid);
  241.             new string[128];
  242.             format(string, 128, "[Weapon] You have successfully dropped your %s with %d bullet(s).", GetJ_WeaponName(weapon), dammo);
  243.             SendClientMessage(playerid, 0x00FF00FF, string);
  244.             for(new a=0; a<13; a++) if(u_savedammo[a]!=0) GivePlayerWeapon(playerid, u_savedweapon[a], u_savedammo[a]);
  245.             if(dammo == ammo) SetPlayerArmedWeapon(playerid,0);
  246.             else SetPlayerArmedWeapon(playerid,weapon);
  247.             return 1;
  248.         }
  249.     }
  250.     return 0;
  251. }
  252.  
  253. stock OnWeaponDropExit()
  254. {
  255.     for(new i=0; i<MAX_PLAYERS; i++)
  256.     {
  257.         RemovePickups(i);
  258.         WeaponTimer[i] = -1;
  259.     }
  260.     print("\n----------------------------------------");
  261.     print("[FS] WeaponDrop v1.1 by Jeffry unloaded!");
  262.     print("----------------------------------------\n");
  263.     return 1;
  264. }
  265.  
  266. stock GetModel(weaponid)
  267. {
  268.     for(new i=0; i<sizeof(ForbiddenWeapons); i++)
  269.     {
  270.         if(weaponid == ForbiddenWeapons[i])
  271.         {
  272.             return -1;
  273.         }
  274.     }
  275.     switch(weaponid)
  276.     {
  277.         case 1: return 331;
  278.         case 2: return 333;
  279.         case 3: return 334;
  280.         case 4: return 335;
  281.         case 5: return 336;
  282.         case 6: return 337;
  283.         case 7: return 338;
  284.         case 8: return 339;
  285.         case 9: return 341;
  286.         case 10: return 321;
  287.         case 11: return 322;
  288.         case 12: return 323;
  289.         case 13: return 324;
  290.         case 14: return 325;
  291.         case 15: return 326;
  292.         case 16: return 342;
  293.         case 17: return 343;
  294.         case 18: return 344;
  295.         case 22: return 346;
  296.         case 23: return 347;
  297.         case 24: return 348;
  298.         case 25: return 349;
  299.         case 26: return 350;
  300.         case 27: return 351;
  301.         case 28: return 352;
  302.         case 29: return 353;
  303.         case 30: return 355;
  304.         case 31: return 356;
  305.         case 32: return 372;
  306.         case 33: return 357;
  307.         case 34: return 358;
  308.         case 35: return 359;
  309.         case 36: return 360;
  310.         case 37: return 361;
  311.         case 38: return 362;
  312.         case 39: return 363;
  313.         case 40: return 364;
  314.         case 41: return 365;
  315.         case 42: return 366;
  316.         case 43: return 367;
  317.         case 44: return 368;
  318.         case 45: return 369;
  319.         case 46: return 371;
  320.         default: return -1;
  321.     }
  322.     return -1;
  323. }
  324.  
  325. forward RemovePickups(playerid);
  326. public RemovePickups(playerid)
  327. {
  328.     if(WeaponTimer[playerid] != -1) KillTimer(WeaponTimer[playerid]);
  329.     WeaponTimer[playerid] = -1;
  330.     for(new a=0; a<14; a++)
  331.     {
  332.         if(WeaponDrop[playerid][a] != -1)
  333.         {
  334.             DestroyPickup(WeaponDrop[playerid][a]);
  335.             WeaponDrop[playerid][a] = -1;
  336.             WeaponData[playerid][a][0] = -1;
  337.             WeaponData[playerid][a][1] = -1;
  338.             WeaponData[playerid][a][2] = -1;
  339.         }
  340.     }
  341.     return 1;
  342. }
  343.  
  344. stock GetWeaponSlot(weaponid)
  345. {
  346.     switch(weaponid)
  347.     {
  348.         case 0,1: return 0;
  349.         case 2..9: return 1;
  350.         case 22..24: return 2;
  351.         case 25..27: return 3;
  352.         case 28,29,32: return 4;
  353.         case 30,31: return 5;
  354.         case 33,34: return 6;
  355.         case 35..38: return 7;
  356.         case 16..18,39: return 8;
  357.         case 41..43: return 9;
  358.         case 10..15: return 10;
  359.         case 44..46: return 11;
  360.         case 40: return 12;
  361.         default: return -1;
  362.     }
  363.     return -1;
  364. }
  365.  
  366. stock GetJ_WeaponName(id)
  367. {
  368.     new wName[32];
  369.     wName="INVALID_WEAPON";
  370.     switch(id)
  371.     {
  372.         case 0: wName="Fist";
  373.         case 1: wName="Brass Knuckles";
  374.         case 2: wName="Golf Club";
  375.         case 3: wName="Night Stick";
  376.         case 4: wName="Knife";
  377.         case 5: wName="Baseball Bat";
  378.         case 6: wName="Shovel";
  379.         case 7: wName="Pool Cue";
  380.         case 8: wName="Katana";
  381.         case 9: wName="Chainsaw";
  382.         case 10: wName="Purple Dildo";
  383.         case 11: wName="Small White Vibrator";
  384.         case 12: wName="Large White Vibrator";
  385.         case 13: wName="Silver Vibrator";
  386.         case 14: wName="Flowers";
  387.         case 15: wName="Cane";
  388.         case 16: wName="Grenade";
  389.         case 17: wName="Tear Gas";
  390.         case 18: wName="Molotov Cocktail";
  391.         case 22: wName="9mm";
  392.         case 23: wName="Silenced 9mm";
  393.         case 24: wName="Desert Eagle";
  394.         case 25: wName="Shotgun";
  395.         case 26: wName="Sawnoff Shotgun";
  396.         case 27: wName="Combat Shotgun";
  397.         case 28: wName="Micro SMG";
  398.         case 29: wName="MP5";
  399.         case 30: wName="AK 47";
  400.         case 31: wName="M4";
  401.         case 32: wName="Tec 9";
  402.         case 33: wName="Country Rifle";
  403.         case 34: wName="Sniper Rifle";
  404.         case 35: wName="Rocket Launcher";
  405.         case 36: wName="HS Rocket Launcher";
  406.         case 37: wName="Flamethrower";
  407.         case 38: wName="Minigun";
  408.         case 39: wName="Satchel Charge";
  409.         case 40: wName="Detonator";
  410.         case 41: wName="Spraycan";
  411.         case 42: wName="Fire Extinguiser";
  412.         case 43: wName="Camera";
  413.         case 44: wName="Night Vision Goggles";
  414.         case 45: wName="Thermal Goggles";
  415.         case 46: wName="Parachute";
  416.     }
  417.     return wName;
  418. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement