Advertisement
sheenidgs

Weapon Shop v1.0 w/ RPG

Jul 13th, 2011
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.45 KB | None | 0 0
  1. /*  -----------------------------------------------------------------------------------------------
  2.  
  3. .##......##.########....###....########...#######..##....##.....######..##.....##..#######..########.
  4. .##..##..##.##.........##.##...##.....##.##.....##.###...##....##....##.##.....##.##.....##.##.....##
  5. .##..##..##.##........##...##..##.....##.##.....##.####..##....##.......##.....##.##.....##.##.....##
  6. .##..##..##.######...##.....##.########..##.....##.##.##.##.....######..#########.##.....##.########.
  7. .##..##..##.##.......#########.##........##.....##.##..####..........##.##.....##.##.....##.##.......
  8. .##..##..##.##.......##.....##.##........##.....##.##...###....##....##.##.....##.##.....##.##.......
  9. ..###..###..########.##.....##.##.........#######..##....##.....######..##.....##..#######..##.......
  10.  
  11.                                         .########..##....##
  12.                                         .##.....##..##..##.
  13.                                         .##.....##...####..
  14.                                         .########.....##...
  15.                                         .##.....##....##...
  16.                                         .##.....##....##...
  17.                                         .########.....##...
  18.                                        
  19.         .##.....##....###.....######..##....##.##........########.##.....##.########.########.
  20.         .##.....##...##.##...##....##.##...##..##....##..##.......##.....##.##.......##.....##
  21.         .##.....##..##...##..##.......##..##...##....##..##.......##.....##.##.......##.....##
  22.         .#########.##.....##.##.......#####....##....##..######...##.....##.######...########.
  23.         .##.....##.#########.##.......##..##...#########.##........##...##..##.......##...##..
  24.         .##.....##.##.....##.##....##.##...##........##..##.........##.##...##.......##....##.
  25.         .##.....##.##.....##..######..##....##.......##..########....###....########.##.....##
  26.  
  27. ------------------------------------------------------------------------------------------------ */
  28. #define FILTERSCRIPT
  29. #define VERSION_WEP_SHOP        "1.0"   // Version Script.
  30. #define WEAPONS_DIALOG          137     // Dialog ID for Weapon Shop (You can change this value if your script already defined this dialog ID).
  31. #define MAX_WEAPS_SELL          29      // You must correct this value with enumeration on WeaponData. (Ex: I already have 28 weapons, and you must change value to 29 if you add a weapon in enum).
  32. //-----------------------------------------------------------------------------------------------//
  33. #include <a_samp>
  34. #include <colors>
  35. #include <sscanf>
  36. #include <zcmd>
  37. //-----------------------------------------------------------------------------------------------//
  38. new WeaponData[MAX_WEAPS_SELL][3] =
  39. {
  40.     {2,250,1},          // Golf Club
  41.     {3,350,1},          // Nite Stick
  42.     {4,450,1},          // Knife
  43.     {5,550,1},          // Baseball Bat
  44.     {6,650,1},          // Shovel
  45.     {7,750,1},          // Pool Cue
  46.     {8,850,1},          // Katana
  47.     {16,15000,10},      // Grenade
  48.     {17,5000,10},       // Tear Gas
  49.     {18,20000,10},      // Molotov
  50.     {22,1500,250},      // 9MM
  51.     {23,2000,250},      // Silenced Pistol
  52.     {24,3500,250},      // Desert Eagle
  53.     {25,3700,200},      // Shotgun
  54.     {26,3750,200},      // Sawn-off Shotgun
  55.     {27,3800,200},      // Combat Shotgun
  56.     {28,2500,750},      // Micro SMG
  57.     {29,3000,750},      // MP5
  58.     {30,4000,1000},     // AK-47
  59.     {31,5000,1000},     // M4A1
  60.     {32,2500,750},      // TEC-9
  61.     {33,6500,200},      // Country Rifle
  62.     {34,7000,200},      // Sniper Rifle
  63.     {35,10000,20},      // Sniper Rifle
  64.     {41,5500,1000},     // Spray Can
  65.     {42,6500,1000},     // Fire Extinguisher
  66.     {43,2000,72},       // Camera
  67.     {46,500,1},         // Parachute
  68.     {0,200,100}         // Health and Armour (I'm using ID 0 because ID 0 is fist (unused).
  69. }// Format array: {Weapon ID, Weapon Price, Ammo} Further Information look at GetPlayerWeaponNameFromModel(weaponid);
  70. new weaponstring[1024]; // I know this array is too big.
  71. //-----------------------------------------------------------------------------------------------//
  72. public OnFilterScriptInit()
  73. {
  74.     for(new w = 0; w < MAX_WEAPS_SELL; w++)
  75.     {
  76.         format(weaponstring,sizeof(weaponstring),"%s\n%d. %s - %d Ammo - $%d",weaponstring,w+1,GetWeaponNameFromModel(w),WeaponData[w][2],WeaponData[w][1]);
  77.     }
  78.     //-------------------------------------------------------------------------------------------//
  79.     print("\n--------------------------------------");
  80.     print(" Weapon Shop v"#VERSION_WEP_SHOP" by: hack4ever a.k.a. sheenIDGS");
  81.     print(" STATUS: LOADED.");
  82.     print(" WARNING: DON'T REMOVE ANY CREDITS !!!!.");
  83.     print("--------------------------------------\n");
  84.     return 1;
  85. }
  86.  
  87. public OnFilterScriptExit()
  88. {
  89.     print("\n--------------------------------------");
  90.     print(" Weapon Shop v"#VERSION_WEP_SHOP" by: hack4ever a.k.a. sheenIDGS");
  91.     print(" STATUS: UNLOADED.");
  92.     print(" WARNING: DON'T REMOVE ANY CREDITS !!!!.");
  93.     print("--------------------------------------\n");
  94.     return 1;
  95. }
  96.  
  97. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  98. {
  99.     new string[128]; new value = strval(inputtext); new weap = GetPVarInt(playerid, "WeapNumber");
  100.     //-------------------------------------------------------------------------------------------//
  101.     if(dialogid == WEAPONS_DIALOG)
  102.     {
  103.         if(response)
  104.         {
  105.             if(value <= 0 || value > MAX_WEAPS_SELL)
  106.             {
  107.                 SendClientMessage(playerid, COLOR_RED, "ERROR: Wrong input number weapon!");
  108.                 return 1;
  109.             }
  110.             if(WeaponData[value-1][0] == 0)
  111.             {
  112.                 if(GetPlayerMoney(playerid) >= WeaponData[value-1][1])
  113.                 {
  114.                     GivePlayerMoney(playerid, 0-WeaponData[value-1][1]);
  115.                     SetPlayerHealth(playerid, 100.0);
  116.                     SetPlayerArmour(playerid, 100.0);
  117.                     format(string,sizeof(string),"SUCCESS: You have spent $%d for refill \"%s\".", WeaponData[value-1][1], GetWeaponNameFromModel(value-1));
  118.                     SendClientMessage(playerid, COLOR_GREEN, string);
  119.                 }
  120.                 if(GetPlayerMoney(playerid) < WeaponData[value-1][1])
  121.                 {
  122.                     format(string,sizeof(string),"ERROR: You need $%d to refill \"%s\".", WeaponData[value-1][1], GetWeaponNameFromModel(value-1));
  123.                     SendClientMessage(playerid, COLOR_RED, string);
  124.                 }
  125.                 return 1;
  126.             }
  127.             if(WeaponData[value-1][2] == 1)
  128.             {
  129.                 if(GetPlayerMoney(playerid) >= WeaponData[value-1][1])
  130.                 {
  131.                     GivePlayerMoney(playerid, 0-WeaponData[value-1][1]);
  132.                     GivePlayerWeapon(playerid, WeaponData[value-1][0], WeaponData[value-1][2]);
  133.                     format(string,sizeof(string),"SUCCESS: You have spent $%d for bought \"%s\".", WeaponData[value-1][1], GetWeaponNameFromModel(value-1));
  134.                     SendClientMessage(playerid, COLOR_GREEN, string);
  135.                 }
  136.                 if(GetPlayerMoney(playerid) < WeaponData[value-1][1])
  137.                 {
  138.                     format(string,sizeof(string),"ERROR: You need $%d to buy \"%s\"", WeaponData[value-1][1], GetWeaponNameFromModel(value-1));
  139.                     SendClientMessage(playerid, COLOR_RED, string);
  140.                 }
  141.                 return 1;
  142.             }
  143.             format(string,sizeof(string),"You will buy \"%s\" with %d ammo and the prize is $%d per packet.\nPlease input belom how many packets do you want.", GetWeaponNameFromModel(value-1), WeaponData[value-1][2], WeaponData[value-1][1]);
  144.             ShowPlayerDialog(playerid, WEAPONS_DIALOG+1, DIALOG_STYLE_INPUT, "Weapon Shop | created by : hack4ever", string, "Bring it On", "Cancel");
  145.             SetPVarInt(playerid, "WeapNumber", value-1);
  146.         }
  147.     }
  148.    
  149.     if(dialogid == WEAPONS_DIALOG+1)
  150.     {
  151.         if(response)
  152.         {
  153.             if(value < 0 || value == 0)
  154.             {
  155.                 SendClientMessage(playerid, COLOR_RED, "ERROR: Wrong amount.");
  156.                 return 1;
  157.             }
  158.             if(value > 100)
  159.             {
  160.                 SendClientMessage(playerid, COLOR_RED, "ERROR: You can't buy more than 100 packets for 1 transaction!");
  161.                 return 1;
  162.             }
  163.             if(WeaponData[weap][1]*value > GetPlayerMoney(playerid))
  164.             {
  165.                 format(string,sizeof(string),"ERROR: You need $%d to buy \"%s\" for %d packets.", WeaponData[weap][1]*value, GetWeaponNameFromModel(weap), value);
  166.                 SendClientMessage(playerid, COLOR_RED, string);
  167.                 return 1;
  168.             }
  169.             GivePlayerWeapon(playerid, WeaponData[weap][0], WeaponData[weap][2]*value);
  170.             GivePlayerMoney(playerid, 0-WeaponData[weap][1]*value);
  171.             format(string,sizeof(string),"SUCCESS: You have spent $%d for bought \"%s\" with %d packets. (Ammo : %d)", WeaponData[weap][1]*value, GetWeaponNameFromModel(weap), value, WeaponData[weap][2]*value);
  172.             SendClientMessage(playerid, COLOR_GREEN, string);
  173.         }
  174.     }
  175.     return 1;
  176. }
  177.  
  178. stock GetWeaponNameFromModel(weaponid)
  179. {
  180.     new weapon[32];
  181.     GetWeaponName(WeaponData[weaponid][0],weapon,32);
  182.     if(WeaponData[weaponid][0] == 18) { weapon = "Molotov Cocktail"; }
  183.     if(WeaponData[weaponid][0] == 0) { weapon = "Health and Armour"; }
  184.     return weapon;
  185. }
  186.  
  187. //  I'm using stock IsAtWeaponShop for check is player in ammu-nation
  188. stock IsAtWeaponShop(playerid)
  189. {
  190.     if(IsPlayerConnected(playerid))
  191.     {
  192.         if(IsPlayerInRangeOfPoint(playerid, 50.0, 296.0515,-105.3873,1001.5156) || IsPlayerInRangeOfPoint(playerid, 50.0, 291.1880,-84.7032,1001.5156) || IsPlayerInRangeOfPoint(playerid, 50.0, 291.5020,-39.4228,1001.5156))
  193.         {
  194.             return 1;
  195.         }
  196.         else if(IsPlayerInRangeOfPoint(playerid, 50.0, 317.4479,-162.2596,999.5938) || IsPlayerInRangeOfPoint(playerid, 50.0, 314.5552,-137.3875,999.6016))
  197.         {
  198.             return 1;
  199.         }
  200.     }
  201.     return 0;
  202. }
  203. //-----------------------------------------------------------------------------------------------//
  204. CMD:weaponlist(playerid, params[])
  205. {
  206.     #pragma unused params
  207.     ShowPlayerDialog(playerid, WEAPONS_DIALOG+2, DIALOG_STYLE_MSGBOX, "Weapon Shop List", weaponstring, "O", "K");
  208.     return 1;
  209. }
  210.  
  211. CMD:buygun(playerid, params[])
  212. {
  213.     #pragma unused params
  214.     if(!IsAtWeaponShop(playerid)) SendClientMessage(playerid, COLOR_RED, "You must at weapon shop!");
  215.     else
  216.     {
  217.         ShowPlayerDialog(playerid, WEAPONS_DIALOG, DIALOG_STYLE_INPUT, "Weapon Shop", weaponstring, "Buy", "Cancel");
  218.     }
  219.     return 1;
  220. }
  221.  
  222. CMD:buyweap(playerid, params[])
  223. {
  224.     new weap,pack,weapon,string[100];
  225.     if(!IsAtWeaponShop(playerid)) return SendClientMessage(playerid, COLOR_RED, "You must at weapon shop!");
  226.     if(sscanf(params,"dd",weapon,pack))
  227.     {
  228.         SendClientMessage(playerid, COLOR_WHITE, "USAGE: /buyweap [weapon_number] [ammount_packet]");
  229.         SendClientMessage(playerid, COLOR_WHITE, "Look weapon number at /weaponlist (except for melee and for refill, packet is only 1 per transaction).");
  230.         return 1;
  231.     }
  232.     weap = weapon-1;
  233.     if(weapon < 1 || weapon > MAX_WEAPS_SELL) return SendClientMessage(playerid, COLOR_RED, "ERROR: Wrong input weapon number! Look at /weaponlist");
  234.     if(pack > 100 || pack < 0) return SendClientMessage(playerid, COLOR_RED, "ERROR: You must input ammount of packet (More than 0 packet and less than 100 packets)!");
  235.     if(WeaponData[weap][0] == 0)
  236.     {
  237.         pack = 1;
  238.         if(GetPlayerMoney(playerid) < WeaponData[weap][1])
  239.         {
  240.             format(string,sizeof(string),"ERROR: You need $%d to refill \"%s\".", WeaponData[weap][1], GetWeaponNameFromModel(weap));
  241.             SendClientMessage(playerid, COLOR_RED, string);
  242.         }
  243.         else if(GetPlayerMoney(playerid) >= WeaponData[weap][1])
  244.         {
  245.             GivePlayerMoney(playerid, 0-WeaponData[weap][1]);
  246.             SetPlayerHealth(playerid, 100.0);
  247.             SetPlayerArmour(playerid, 100.0);
  248.             format(string,sizeof(string),"SUCCESS: You have spent $%d for refill \"%s\".", WeaponData[weap][1], GetWeaponNameFromModel(weap));
  249.             SendClientMessage(playerid, COLOR_GREEN, string);
  250.         }
  251.         return 1;
  252.     }
  253.     if(WeaponData[weap][0] != 0)
  254.     {
  255.         if(GetPlayerMoney(playerid) < WeaponData[weap][1]*pack)
  256.         {
  257.             if(WeaponData[weap][2] == 1)
  258.             {
  259.                 pack = 1;
  260.                 format(string,sizeof(string),"ERROR: You need $%d to buy \"%s\"", WeaponData[weap][1], GetWeaponNameFromModel(weap));
  261.                 SendClientMessage(playerid, COLOR_RED, string);
  262.             }
  263.             else
  264.             {
  265.                 if(pack == 0) return SendClientMessage(playerid, COLOR_RED, "ERROR: You didn't input your packet!");
  266.                 format(string,sizeof(string),"ERROR: You need $%d to buy \"%s\" for %d packets.", WeaponData[weap][1]*pack, GetWeaponNameFromModel(weap),pack);
  267.                 SendClientMessage(playerid, COLOR_RED, string);
  268.             }
  269.             return 1;
  270.         }
  271.         else if(GetPlayerMoney(playerid) >= WeaponData[weap][1]*pack)
  272.         {
  273.             if(WeaponData[weap][2] == 1)
  274.             {
  275.                 pack = 1;
  276.                 GivePlayerWeapon(playerid, WeaponData[weap][0], WeaponData[weap][2]);
  277.                 GivePlayerMoney(playerid, 0-WeaponData[weap][1]);
  278.                 format(string,sizeof(string),"SUCCESS: You have spent $%d for bought \"%s\".", WeaponData[weap][1], GetWeaponNameFromModel(weap));
  279.                 SendClientMessage(playerid, COLOR_GREEN, string);
  280.             }
  281.             else
  282.             {
  283.                 if(pack == 0) return SendClientMessage(playerid, COLOR_RED, "ERROR: You didn't input your packet!");
  284.                 GivePlayerWeapon(playerid, WeaponData[weap][0], WeaponData[weap][2]*pack);
  285.                 GivePlayerMoney(playerid, 0-WeaponData[weap][1]*pack);
  286.                 format(string,sizeof(string),"SUCCESS: You have spent $%d for bought \"%s\" with %d packets. (Ammo : %d)", WeaponData[weap][1]*pack, GetWeaponNameFromModel(weap), pack, WeaponData[weap][2]*pack);
  287.                 SendClientMessage(playerid, COLOR_GREEN, string);
  288.             }
  289.             return 1;
  290.         }
  291.     }
  292.     return 1;
  293. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement