Advertisement
sheenidgs

Weapon Shop v1.0

Jul 12th, 2011
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.42 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          28      // 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.     {41,5500,1000},     // Spray Can
  64.     {42,6500,1000},     // Fire Extinguisher
  65.     {43,2000,72},       // Camera
  66.     {46,500,1},         // Parachute
  67.     {0,200,100}         // Health and Armour (I'm using ID 0 because ID 0 is fist (unused).
  68. }// Format array: {Weapon ID, Weapon Price, Ammo} Further Information look at GetPlayerWeaponNameFromModel(weaponid);
  69. new weaponstring[890]// I know this array is too big.
  70. //-----------------------------------------------------------------------------------------------//
  71. public OnFilterScriptInit()
  72. {
  73.     for(new w = 0; w < MAX_WEAPS_SELL; w++)
  74.     {
  75.         format(weaponstring,sizeof(weaponstring),"%s\n%d. %s - %d Ammo - $%d",weaponstring,w+1,GetWeaponNameFromModel(w),WeaponData[w][2],WeaponData[w][1]);
  76.     }
  77.     //-------------------------------------------------------------------------------------------//
  78.     print("\n--------------------------------------");
  79.     print(" Weapon Shop v"#VERSION_WEP_SHOP" by: hack4ever a.k.a. sheenIDGS");
  80.     print(" STATUS: LOADED.");
  81.     print(" WARNING: DON'T REMOVE ANY CREDITS !!!!.");
  82.     print("--------------------------------------\n");
  83.     return 1;
  84. }
  85.  
  86. public OnFilterScriptExit()
  87. {
  88.     print("\n--------------------------------------");
  89.     print(" Weapon Shop v"#VERSION_WEP_SHOP" by: hack4ever a.k.a. sheenIDGS");
  90.     print(" STATUS: UNLOADED.");
  91.     print(" WARNING: DON'T REMOVE ANY CREDITS !!!!.");
  92.     print("--------------------------------------\n");
  93.     return 1;
  94. }
  95.  
  96. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  97. {
  98.     new string[128]; new value = strval(inputtext); new weap = GetPVarInt(playerid, "WeapNumber");
  99.     //-------------------------------------------------------------------------------------------//
  100.     if(dialogid == WEAPONS_DIALOG)
  101.     {
  102.         if(response)
  103.         {
  104.             if(value <= 0 || value > MAX_WEAPS_SELL)
  105.             {
  106.                 SendClientMessage(playerid, COLOR_RED, "ERROR: Wrong input number weapon!");
  107.                 return 1;
  108.             }
  109.             if(WeaponData[value-1][0] == 0)
  110.             {
  111.                 if(GetPlayerMoney(playerid) >= WeaponData[value-1][1])
  112.                 {
  113.                     GivePlayerMoney(playerid, 0-WeaponData[value-1][1]);
  114.                     SetPlayerHealth(playerid, 100.0);
  115.                     SetPlayerArmour(playerid, 100.0);
  116.                     format(string,sizeof(string),"SUCCESS: You have spent $%d for refill \"%s\".", WeaponData[value-1][1], GetWeaponNameFromModel(value-1));
  117.                     SendClientMessage(playerid, COLOR_GREEN, string);
  118.                 }
  119.                 if(GetPlayerMoney(playerid) < WeaponData[value-1][1])
  120.                 {
  121.                     format(string,sizeof(string),"ERROR: You need $%d to refill \"%s\".", WeaponData[value-1][1], GetWeaponNameFromModel(value-1));
  122.                     SendClientMessage(playerid, COLOR_RED, string);
  123.                 }
  124.                 return 1;
  125.             }
  126.             if(WeaponData[value-1][2] == 1)
  127.             {
  128.                 if(GetPlayerMoney(playerid) >= WeaponData[value-1][1])
  129.                 {
  130.                     GivePlayerMoney(playerid, 0-WeaponData[value-1][1]);
  131.                     GivePlayerWeapon(playerid, WeaponData[value-1][0], WeaponData[value-1][2]);
  132.                     format(string,sizeof(string),"SUCCESS: You have spent $%d for bought \"%s\".", WeaponData[value-1][1], GetWeaponNameFromModel(value-1));
  133.                     SendClientMessage(playerid, COLOR_GREEN, string);
  134.                 }
  135.                 if(GetPlayerMoney(playerid) < WeaponData[value-1][1])
  136.                 {
  137.                     format(string,sizeof(string),"ERROR: You need $%d to buy \"%s\"", WeaponData[value-1][1], GetWeaponNameFromModel(value-1));
  138.                     SendClientMessage(playerid, COLOR_RED, string);
  139.                 }
  140.                 return 1;
  141.             }
  142.             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]);
  143.             ShowPlayerDialog(playerid, WEAPONS_DIALOG+1, DIALOG_STYLE_INPUT, "Weapon Shop | created by : hack4ever", string, "Bring it On", "Cancel");
  144.             SetPVarInt(playerid, "WeapNumber", value-1);
  145.         }
  146.     }
  147.    
  148.     if(dialogid == WEAPONS_DIALOG+1)
  149.     {
  150.         if(response)
  151.         {
  152.             if(value < 0 || value == 0)
  153.             {
  154.                 SendClientMessage(playerid, COLOR_RED, "ERROR: Wrong amount.");
  155.                 return 1;
  156.             }
  157.             if(value > 100)
  158.             {
  159.                 SendClientMessage(playerid, COLOR_RED, "ERROR: You can't buy more than 100 packets for 1 transaction!");
  160.                 return 1;
  161.             }
  162.             if(WeaponData[weap][1]*value > GetPlayerMoney(playerid))
  163.             {
  164.                 format(string,sizeof(string),"ERROR: You need $%d to buy \"%s\" for %d packets.", WeaponData[weap][1]*value, GetWeaponNameFromModel(weap), value);
  165.                 SendClientMessage(playerid, COLOR_RED, string);
  166.                 return 1;
  167.             }
  168.             GivePlayerWeapon(playerid, WeaponData[weap][0], WeaponData[weap][2]*value);
  169.             GivePlayerMoney(playerid, 0-WeaponData[weap][1]*value);
  170.             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);
  171.             SendClientMessage(playerid, COLOR_GREEN, string);
  172.         }
  173.     }
  174.     return 1;
  175. }
  176.  
  177. stock GetWeaponNameFromModel(weaponid)
  178. {
  179.     new weapon[32];
  180.     GetWeaponName(WeaponData[weaponid][0],weapon,32);
  181.     if(WeaponData[weaponid][0] == 18) { weapon = "Molotov Cocktail"; }
  182.     if(WeaponData[weaponid][0] == 0) { weapon = "Health and Armour"; }
  183.     return weapon;
  184. }
  185.  
  186. //  I'm using stock IsAtWeaponShop for check is player in ammu-nation
  187. stock IsAtWeaponShop(playerid)
  188. {
  189.     if(IsPlayerConnected(playerid))
  190.     {
  191.         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))
  192.         {
  193.             return 1;
  194.         }
  195.         else if(IsPlayerInRangeOfPoint(playerid, 50.0, 317.4479,-162.2596,999.5938) || IsPlayerInRangeOfPoint(playerid, 50.0, 314.5552,-137.3875,999.6016))
  196.         {
  197.             return 1;
  198.         }
  199.     }
  200.     return 0;
  201. }
  202. //-----------------------------------------------------------------------------------------------//
  203. CMD:weaponlist(playerid, params[])
  204. {
  205.     #pragma unused params
  206.     ShowPlayerDialog(playerid, WEAPONS_DIALOG+2, DIALOG_STYLE_MSGBOX, "Weapon Shop List", weaponstring, "O", "K");
  207.     return 1;
  208. }
  209.  
  210. CMD:buygun(playerid, params[])
  211. {
  212.     #pragma unused params
  213.     if(!IsAtWeaponShop(playerid)) SendClientMessage(playerid, COLOR_RED, "You must at weapon shop!");
  214.     else
  215.     {
  216.         ShowPlayerDialog(playerid, WEAPONS_DIALOG, DIALOG_STYLE_INPUT, "Weapon Shop", weaponstring, "Buy", "Cancel");
  217.     }
  218.     return 1;
  219. }
  220.  
  221. CMD:buyweap(playerid, params[])
  222. {
  223.     new weap,pack,weapon,string[100];
  224.     if(!IsAtWeaponShop(playerid)) return SendClientMessage(playerid, COLOR_RED, "You must at weapon shop!");
  225.     if(sscanf(params,"dd",weapon,pack))
  226.     {
  227.         SendClientMessage(playerid, COLOR_WHITE, "USAGE: /buyweap [weapon_number] [ammount_packet]");
  228.         SendClientMessage(playerid, COLOR_WHITE, "Look weapon number at /weaponlist (except for melee and for refill, packet is only 1 per transaction).");
  229.         return 1;
  230.     }
  231.     weap = weapon-1;
  232.     if(weapon < 1 || weapon > MAX_WEAPS_SELL) return SendClientMessage(playerid, COLOR_RED, "ERROR: Wrong input weapon number! Look at /weaponlist");
  233.     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)!");
  234.     if(WeaponData[weap][0] == 0)
  235.     {
  236.         pack = 1;
  237.         if(GetPlayerMoney(playerid) < WeaponData[weap][1])
  238.         {
  239.             format(string,sizeof(string),"ERROR: You need $%d to refill \"%s\".", WeaponData[weap][1], GetWeaponNameFromModel(weap));
  240.             SendClientMessage(playerid, COLOR_RED, string);
  241.         }
  242.         else if(GetPlayerMoney(playerid) >= WeaponData[weap][1])
  243.         {
  244.             GivePlayerMoney(playerid, 0-WeaponData[weap][1]);
  245.             SetPlayerHealth(playerid, 100.0);
  246.             SetPlayerArmour(playerid, 100.0);
  247.             format(string,sizeof(string),"SUCCESS: You have spent $%d for refill \"%s\".", WeaponData[weap][1], GetWeaponNameFromModel(weap));
  248.             SendClientMessage(playerid, COLOR_GREEN, string);
  249.         }
  250.         return 1;
  251.     }
  252.     if(WeaponData[weap][0] != 0)
  253.     {
  254.         if(GetPlayerMoney(playerid) < WeaponData[weap][1]*pack)
  255.         {
  256.             if(WeaponData[weap][2] == 1)
  257.             {
  258.                 pack = 1;
  259.                 format(string,sizeof(string),"ERROR: You need $%d to buy \"%s\"", WeaponData[weap][1], GetWeaponNameFromModel(weap));
  260.                 SendClientMessage(playerid, COLOR_RED, string);
  261.             }
  262.             else
  263.             {
  264.                 if(pack == 0) return SendClientMessage(playerid, COLOR_RED, "ERROR: You didn't input your packet!");
  265.                 format(string,sizeof(string),"ERROR: You need $%d to buy \"%s\" for %d packets.", WeaponData[weap][1]*pack, GetWeaponNameFromModel(weap),pack);
  266.                 SendClientMessage(playerid, COLOR_RED, string);
  267.             }
  268.             return 1;
  269.         }
  270.         else if(GetPlayerMoney(playerid) >= WeaponData[weap][1]*pack)
  271.         {
  272.             if(WeaponData[weap][2] == 1)
  273.             {
  274.                 pack = 1;
  275.                 GivePlayerWeapon(playerid, WeaponData[weap][0], WeaponData[weap][2]);
  276.                 GivePlayerMoney(playerid, 0-WeaponData[weap][1]);
  277.                 format(string,sizeof(string),"SUCCESS: You have spent $%d for bought \"%s\".", WeaponData[weap][1], GetWeaponNameFromModel(weap));
  278.                 SendClientMessage(playerid, COLOR_GREEN, string);
  279.             }
  280.             else
  281.             {
  282.                 if(pack == 0) return SendClientMessage(playerid, COLOR_RED, "ERROR: You didn't input your packet!");
  283.                 GivePlayerWeapon(playerid, WeaponData[weap][0], WeaponData[weap][2]*pack);
  284.                 GivePlayerMoney(playerid, 0-WeaponData[weap][1]*pack);
  285.                 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);
  286.                 SendClientMessage(playerid, COLOR_GREEN, string);
  287.             }
  288.             return 1;
  289.         }
  290.     }
  291.     return 1;
  292. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement