Advertisement
JeffryUGP

[INC] WeaponDrop v1.1

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