Advertisement
Guest User

Mining System - With 12 Metals - From Scratch - Version 2.0

a guest
Apr 27th, 2013
1,529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.32 KB | None | 0 0
  1. // Mining System By Avi Raj
  2. // From Scratch
  3. // Thanks To Download.
  4.  
  5. #include <a_samp>
  6. #include <zcmd>
  7. #include <YSI\y_ini>
  8.  
  9. #define PRESSED(%0) \
  10.     ((newkeys & (%0)) == (%0))
  11. #define COLOR_YELLOW 0xFFFF00AA
  12. #define COLOR_CYAN 0x00FFFFFF
  13. #define metals 1
  14. #define inventory 2
  15. #define pInvPath "Inventory/%s.ini"
  16.  
  17. enum inv
  18. {
  19.  Gold,
  20.  Diamond,
  21.  Silver,
  22.  Tin,
  23.  Lead,
  24.  Iron,
  25.  Cobalt,
  26.  Titanium,
  27.  Platinum,
  28.  Copper,
  29.  Manganese,
  30.  Mercury
  31. }
  32.  
  33. new Inventory[MAX_PLAYERS][inv];
  34.  
  35.  
  36. stock pPath(playerid) //To execute the player's name with the INI files.
  37. {
  38.  new Lname[MAX_PLAYER_NAME], string[128];
  39.  GetPlayerName(playerid, Lname, sizeof(Lname));
  40.  format(string, sizeof(string), pInvPath, Lname);
  41.  return string;
  42. }
  43.  
  44. forward LoadPlayer_Inventory(playerid, name[], value[]); //A forward function which loads player's inventory.
  45. public LoadPlayer_Inventory(playerid, name[], value[])
  46. {
  47.  //Function: INI_Int - Which loads the 'int' value (integer). In case of string, it's INI_String, in case of float it's INI_Float.
  48.  INI_Int("Gold", Inventory[playerid][Gold]);
  49.  INI_Int("Diamond", Inventory[playerid][Diamond]);
  50.  INI_Int("Silver", Inventory[playerid][Silver]);
  51.  INI_Int("Tin", Inventory[playerid][Tin]);
  52.  INI_Int("Lead", Inventory[playerid][Lead]);
  53.  INI_Int("Iron", Inventory[playerid][Iron]);
  54.  INI_Int("Cobalt", Inventory[playerid][Cobalt]);
  55.  INI_Int("Titanium", Inventory[playerid][Titanium]);
  56.  INI_Int("Platinum", Inventory[playerid][Platinum]);
  57.  INI_Int("Copper", Inventory[playerid][Copper]);
  58.  INI_Int("Manganese", Inventory[playerid][Manganese]);
  59.  INI_Int("Mercury", Inventory[playerid][Mercury]);
  60.  //Gets the value
  61.  return 1;
  62. }
  63.  
  64. public OnFilterScriptInit()
  65. {
  66.     print("\n--------------------------------------");
  67.     print("    Metal System By Avi Raj loaded      ");
  68.     print("--------------------------------------\n");
  69.     CreateObject(897, 499.57, 779.96, -25.49,   0.00, 0.00, 0.00);
  70.     CreateObject(897, 494.21, 777.72, -25.49,   0.00, 0.00, 0.00);
  71.     CreateObject(897, 486.58, 782.16, -25.49,   0.00, 0.00, 0.00);
  72.     CreateObject(897, 484.11, 790.04, -25.49,   0.00, 0.00, 0.00);
  73.     CreateObject(897, 501.51, 779.70, -25.49,   0.00, 0.00, -98.00);
  74.     CreateObject(897, 504.28, 778.75, -25.49,   0.00, 0.00, -98.00);
  75.     CreateObject(897, 491.51, 782.23, -25.49,   0.00, 0.00, -98.00);
  76.     CreateObject(897, 489.68, 787.14, -25.49,   0.00, 0.00, -98.00);
  77.     return 1;
  78. }
  79.  
  80. CMD:shovel(playerid, params[])
  81. {
  82.     GivePlayerWeapon(playerid, 6, 1);
  83.     SendClientMessage(playerid,COLOR_CYAN,"*You Have Spawned Shovel.");
  84.     return 1;
  85. }
  86.  
  87. forward RandomReactions();
  88. public RandomReactions()
  89. {
  90.    
  91. }
  92.  
  93. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  94. {
  95.     if(IsPlayerInRangeOfPoint(playerid, 10.0, 493.9033,781.3535,-20.0965))
  96.     {
  97.       if(GetPlayerWeapon(playerid) != 6) return SendClientMessage(playerid, COLOR_YELLOW,"You need shovel to Dig Metals.");
  98.       {
  99.         if (PRESSED(KEY_FIRE))
  100.         {
  101.             new Reactions;
  102.             Reactions = random(14);
  103.             switch(Reactions)
  104.             {
  105.                case 0:
  106.                {
  107.                   SendClientMessageToAll(COLOR_YELLOW,"You have Got Mercury From the Mine.");
  108.                   Inventory[playerid][Mercury]++;
  109.                }
  110.                case 1:
  111.                {
  112.                    SendClientMessageToAll(COLOR_YELLOW,"You have Got Gold From the Mine.");
  113.                    Inventory[playerid][Gold]++;
  114.                }
  115.                case 2:
  116.                {
  117.                    SendClientMessageToAll(COLOR_YELLOW,"You have Got Diamond From the Mine.");
  118.                    Inventory[playerid][Diamond]++;
  119.                }
  120.                case 3:
  121.                {
  122.                    SendClientMessageToAll(COLOR_YELLOW,"You have Got Silver From the Mine.");
  123.                    Inventory[playerid][Silver]++;
  124.                }
  125.                case 4:
  126.                {
  127.                    SendClientMessageToAll(COLOR_YELLOW,"You have Got Tin From the Mine.");
  128.                    Inventory[playerid][Tin]++;
  129.                }
  130.                case 5:
  131.                {
  132.                    SendClientMessageToAll(COLOR_YELLOW,"You have Got Lead From the Mine.");
  133.                    Inventory[playerid][Lead]++;
  134.                }
  135.                case 6:
  136.                {
  137.                    SendClientMessageToAll(COLOR_YELLOW,"You have Got Iron From the Mine.");
  138.                    Inventory[playerid][Iron]++;
  139.                }
  140.                case 7:
  141.                {
  142.                    SendClientMessageToAll(COLOR_YELLOW,"You have Got Cobalt From the Mine.");
  143.                    Inventory[playerid][Cobalt]++;
  144.                }
  145.                case 8:
  146.                {
  147.                    SendClientMessageToAll(COLOR_YELLOW,"You have Got Titanium From the Mine.");
  148.                    Inventory[playerid][Titanium]++;
  149.                }
  150.                case 9:
  151.                {
  152.                    SendClientMessageToAll(COLOR_YELLOW,"You have Got Platinum From the Mine.");
  153.                    Inventory[playerid][Platinum]++;
  154.                }
  155.                case 10:
  156.                {
  157.                    SendClientMessageToAll(COLOR_YELLOW,"You have Got Copper From the Mine.");
  158.                    Inventory[playerid][Copper]++;
  159.                }
  160.                case 11:
  161.                {
  162.                    SendClientMessageToAll(COLOR_YELLOW,"You have Got Manganese From the Mine.");
  163.                    Inventory[playerid][Manganese]++;
  164.                }
  165.                case 12:
  166.                {
  167.                new Float:PlayerHealth;
  168.                GetPlayerHealth(playerid, PlayerHealth);
  169.                SetPlayerHealth(playerid, PlayerHealth - 20);
  170.                SendClientMessage(playerid, COLOR_YELLOW,"You have Been Hurted while Mining Metals.");
  171.                }
  172.             }
  173.         }
  174.       }
  175.     }
  176.     return 1;
  177. }
  178.  
  179. CMD:dig(playerid, parmas[])
  180. {
  181.     SendClientMessage(playerid, COLOR_CYAN,"*Press Fire Key(LMB) to Dig Metals.");
  182.     return 1;
  183. }
  184.  
  185. CMD:miningplace(playerid, params[])
  186. {
  187.    SetPlayerPos(playerid,493.9033,781.3535,-20.0965);
  188.    SendClientMessage(playerid, COLOR_CYAN,"You have Been spawned to Mining Place.");
  189.    return 1;
  190. }
  191.  
  192. public OnPlayerConnect(playerid)
  193. {
  194.  if(fexist(pPath(playerid))) //If there's a file for this player: then it loads
  195.  {
  196.  //We must use 'INI_ParseFile' function and execute the 'LoadPlayer_Inventory' with it. It loads the saved stats, via the user path defined in the function.
  197.   INI_ParseFile(pPath(playerid), "LoadPlayer_Inventory", .bExtra = true, .extra = playerid);
  198.  //Loads the data from the path defined and detects the player's file using getting player's name which is done in 'pPath' function.
  199.  //Now the data is loaded.
  200.  }
  201.  return 1;
  202. }
  203.  
  204. public OnPlayerDisconnect(playerid, reason)
  205. {
  206.  //Now the saving part, we must open, create a tag for the file and then write the values. And then, close the file. (INI_Open, INI_SetTag, INI_WriteInt <As it's an integer>, INI_Close )
  207.  new INI:iFile = INI_Open(pPath(playerid)); //Opens the player's path.
  208.  INI_SetTag(iFile, "Inventory"); //Sets a tag called "Inventory"
  209.  INI_WriteInt(iFile, "Gold", Inventory[playerid][Gold]);
  210.  INI_WriteInt(iFile, "Diamond", Inventory[playerid][Diamond]);
  211.  INI_WriteInt(iFile, "Silver", Inventory[playerid][Silver]);
  212.  INI_WriteInt(iFile, "Tin", Inventory[playerid][Tin]);
  213.  INI_WriteInt(iFile, "Lead", Inventory[playerid][Lead]);
  214.  INI_WriteInt(iFile, "Iron", Inventory[playerid][Iron]);
  215.  INI_WriteInt(iFile, "Cobalt", Inventory[playerid][Cobalt]);
  216.  INI_WriteInt(iFile, "Titanium", Inventory[playerid][Titanium]);
  217.  INI_WriteInt(iFile, "Platinum", Inventory[playerid][Platinum]);
  218.  INI_WriteInt(iFile, "Copper", Inventory[playerid][Copper]);
  219.  INI_WriteInt(iFile, "Manganese", Inventory[playerid][Manganese]);
  220.  INI_WriteInt(iFile, "Mercury", Inventory[playerid][Mercury]);
  221.  INI_Close(iFile);
  222.  //Resetting the values after disconnect would be good to avoid bugs happening later.
  223.  return 1;
  224. }
  225.  
  226. CMD:metals(playerid, params[])
  227. {
  228.  new string[256];
  229.  format(string, sizeof(string), "Gold : %d\nDiamond : %d\nSilver : %d\nTin : %d\nLead : %d\nIron : %d\nCobalt : %d\nTitanium : %d\nPlatinum : %d\nCopper : %d\nManganese : %d\nMercury : %d"); //Formatting the string to show the var's value in dialog. Normally the dialog function won't support "{Float_...}"
  230.  ShowPlayerDialog(playerid, 2, DIALOG_STYLE_MSGBOX, "Metals", string, "Close", "");
  231.  return 1;
  232. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement