Advertisement
Guest User

Mining

a guest
Jan 16th, 2016
2,361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 28.31 KB | None | 0 0
  1. #define     FILTERSCRIPT
  2. #include    <a_samp>
  3. #include    <evf>           // http://forum.sa-mp.com/showthread.php?t=486060
  4. #include    <progress2>     // http://forum.sa-mp.com/showthread.php?t=537468
  5. #include    <streamer>      // http://forum.sa-mp.com/showthread.php?t=102865
  6. #include    <izcmd>         // http://forum.sa-mp.com/showthread.php?t=576114
  7.  
  8. #define     MAX_ORE_TYPES   (6)
  9. #define     MAX_VEINS       (128)
  10. #define     MAX_ORES        (256)
  11.  
  12. #define     UPDATE_RATE     (200)       // update rate of mining in miliseconds, higher the value longer the mining time (default: 200)
  13. #define     BAR_MAX         (15.0)      // maximum value of the progress bar, higher the value longer the mining time (default: 15.0)
  14. #define     VEHICLE_LIMIT   (8)         // how many ores someone can store in their vehicle (default: 8)
  15. #define     ATTACH_INDEX    (3)         // setplayerattachedobject index
  16.  
  17. #define     REGEN_TIME      (45)        // how many minutes before respawning veins (default: 45)
  18. #define     ORE_TIME        (5)         // how many minutes before destroying a dropped ore (default: 5)
  19.  
  20. enum    e_ores
  21. {
  22.     Name[16],
  23.     Color,
  24.     Float: Modifier,
  25.     Amount, // how many of this ore spawns in a vein
  26.     Value, // value of this ore
  27.     Rate // successful mining rate
  28. }
  29.  
  30. enum    e_veins
  31. {
  32.     Type,
  33.     Amount,
  34.     bool: BeingMined,
  35.     VeinObject,
  36.     Text3D: VeinLabel,
  37.     bool: VeinExists
  38. }
  39.  
  40. enum    e_dialogs
  41. {
  42.     DIALOG_ORE_INFO = 18740,
  43.     DIALOG_ORE_TAKE
  44. }
  45.  
  46. enum    e_droppedores
  47. {
  48.     Type,
  49.     OreTimer,
  50.     OreObject,
  51.     Text3D: OreLabel,
  52.     bool: OreExists
  53. }
  54.  
  55. enum    e_droppoints
  56. {
  57.     Location[32],
  58.     Float: PointX,
  59.     Float: PointY,
  60.     Float: PointZ,
  61.     PointCP,
  62.     Text3D: PointLabel
  63. }
  64.  
  65. new
  66.     OreData[MAX_ORE_TYPES][e_ores] = {
  67.     // name, color, modifier, spawn amount, value, mining rate
  68.         {"Copper", 0xB87333FF, 0.75, 8, 350, 65},
  69.         {"Amethyst", 0x9B59B6FF, 0.60, 6, 450, 58},
  70.         {"Emerald", 0x2ECC71FF, 0.40, 4, 750, 50},
  71.         {"Ruby", 0xD10056FF, 0.35, 3, 800, 55},
  72.         {"Sapphire", 0x0F52BAFF, 0.30, 3, 850, 45},
  73.         {"Gold", 0xFFD700FF, 0.25, 4, 1000, 40}
  74.     };
  75.    
  76. new
  77.     VeinData[MAX_VEINS][e_veins],
  78.     DroppedOres[MAX_ORES][e_droppedores];
  79.    
  80. new
  81.     MiningVein[MAX_PLAYERS] = {-1, ...},
  82.     MiningTimer[MAX_PLAYERS] = {-1, ...},
  83.     CarryingOre[MAX_PLAYERS] = {-1, ...},
  84.     LoadingPoint[MAX_PLAYERS] = {-1, ...},
  85.     PlayerBar: MiningBar[MAX_PLAYERS] = {INVALID_PLAYER_BAR_ID, ...};
  86.  
  87. new
  88.     LoadedOres[MAX_VEHICLES][MAX_ORE_TYPES];
  89.    
  90. new
  91.     DropPoints[][e_droppoints] = {
  92.     // location, x, y, z
  93.         {"Las Venturas", 2489.462646, 2773.271240, 10.789896},
  94.         {"San Fierro", -1823.034057, 2.284350, 15.117187},
  95.         {"Los Santos", 2660.815673, -1433.876098, 30.050680}
  96.     };
  97.  
  98. new
  99.     PointIcons[MAX_PLAYERS][sizeof(DropPoints)];
  100.  
  101. // Vehicle Functions
  102. Vehicle_LoadedOres(vehicleid)
  103. {
  104.     if(!IsValidVehicle(vehicleid)) return -1;
  105.     new count = 0;
  106.     for(new i; i < MAX_ORE_TYPES; i++) count += LoadedOres[vehicleid][i];
  107.     return count;
  108. }
  109.  
  110. Vehicle_GetOreValue(vehicleid)
  111. {
  112.     if(!IsValidVehicle(vehicleid)) return -1;
  113.     new value = 0;
  114.     for(new i; i < MAX_ORE_TYPES; i++) value += (LoadedOres[vehicleid][i] * OreData[i][Value]);
  115.     return value;
  116. }
  117.  
  118. Vehicle_GetOreValueByType(vehicleid, type)
  119. {
  120.     if(!IsValidVehicle(vehicleid)) return -1;
  121.     return (LoadedOres[vehicleid][type] * OreData[type][Value]);
  122. }
  123.  
  124. Vehicle_CleanUp(vehicleid)
  125. {
  126.     if(!IsValidVehicle(vehicleid)) return -1;
  127.     for(new i; i < MAX_ORE_TYPES; i++) LoadedOres[vehicleid][i] = 0;
  128.     return 1;
  129. }
  130.  
  131. Vehicle_IsMiningVehicle(vehicleid)
  132. {
  133.     switch(GetVehicleModel(vehicleid))
  134.     {
  135.         case 414, 455, 456, 498, 499, 609: return 1;
  136.         default: return 0;
  137.     }
  138.  
  139.     return 0;
  140. }
  141.  
  142. // Player Functions
  143. Player_Init(playerid)
  144. {
  145.     MiningVein[playerid] = -1;
  146.     MiningTimer[playerid] = -1;
  147.     CarryingOre[playerid] = -1;
  148.     LoadingPoint[playerid] = -1;
  149.     MiningBar[playerid] = CreatePlayerProgressBar(playerid, 498.0, 104.0, 113.0, 6.2, -1429936641, BAR_MAX, 0);
  150.     for(new i; i < sizeof(DropPoints); i++)
  151.     {
  152.         TogglePlayerDynamicCP(playerid, DropPoints[i][PointCP], 0);
  153.         PointIcons[playerid][i] = -1;
  154.     }
  155.    
  156.     return 1;
  157. }
  158.  
  159. Player_CleanUp(playerid, ore = 0)
  160. {
  161.     if(MiningVein[playerid] != -1)
  162.     {
  163.         VeinData[ MiningVein[playerid] ][BeingMined] = false;
  164.         Vein_Update(MiningVein[playerid]);
  165.         ClearAnimations(playerid);
  166.         TogglePlayerControllable(playerid, 1);
  167.         MiningVein[playerid] = -1;
  168.     }
  169.    
  170.     if(MiningTimer[playerid] != -1)
  171.     {
  172.         KillTimer(MiningTimer[playerid]);
  173.         MiningTimer[playerid] = -1;
  174.     }
  175.    
  176.     if(ore && CarryingOre[playerid] != -1)
  177.     {
  178.         CarryingOre[playerid] = -1;
  179.         SetPlayerSpecialAction(playerid, SPECIAL_ACTION_NONE);
  180.     }
  181.    
  182.     if(ore && LoadingPoint[playerid] != -1)
  183.     {
  184.         DestroyDynamicCP(LoadingPoint[playerid]);
  185.         LoadingPoint[playerid] = -1;
  186.     }
  187.    
  188.     if(IsPlayerAttachedObjectSlotUsed(playerid, ATTACH_INDEX)) RemovePlayerAttachedObject(playerid, ATTACH_INDEX);
  189.     SetPlayerProgressBarValue(playerid, MiningBar[playerid], 0.0);
  190.     HidePlayerProgressBar(playerid, MiningBar[playerid]);
  191.     return 1;
  192. }
  193.  
  194. Player_GetClosestVein(playerid, Float: range = 3.0)
  195. {
  196.     new id = -1, Float: dist = range, Float: tempdist, Float: pos[3];
  197.     for(new i; i < MAX_VEINS; i++)
  198.     {
  199.         if(!VeinData[i][VeinExists]) continue;
  200.         GetDynamicObjectPos(VeinData[i][VeinObject], pos[0], pos[1], pos[2]);
  201.         tempdist = GetPlayerDistanceFromPoint(playerid, pos[0], pos[1], pos[2]);
  202.        
  203.         if(tempdist > range) continue;
  204.         if(tempdist <= dist)
  205.         {
  206.             dist = tempdist;
  207.             id = i;
  208.         }
  209.     }
  210.    
  211.     return id;
  212. }
  213.  
  214. Player_GetClosestOre(playerid, Float: range = 3.0)
  215. {
  216.     new id = -1, Float: dist = range, Float: tempdist, Float: pos[3];
  217.     for(new i; i < MAX_ORES; i++)
  218.     {
  219.         if(!DroppedOres[i][OreExists]) continue;
  220.         GetDynamicObjectPos(DroppedOres[i][OreObject], pos[0], pos[1], pos[2]);
  221.         tempdist = GetPlayerDistanceFromPoint(playerid, pos[0], pos[1], pos[2]);
  222.  
  223.         if(tempdist > range) continue;
  224.         if(tempdist <= dist)
  225.         {
  226.             dist = tempdist;
  227.             id = i;
  228.         }
  229.     }
  230.  
  231.     return id;
  232. }
  233.  
  234. Player_GiveOre(playerid, type, cooldown = 0)
  235. {
  236.     CarryingOre[playerid] = type;
  237.     SetPlayerSpecialAction(playerid, SPECIAL_ACTION_CARRY);
  238.     SetPlayerAttachedObject(playerid, ATTACH_INDEX, 2936, 5, 0.105, 0.086, 0.22, -80.3, 3.3, 28.7, 0.35, 0.35, 0.35, RGBAToARGB(OreData[type][Color]));
  239.     SetPVarInt(playerid, "LoadingCooldown", gettime() + cooldown);
  240.    
  241.     new Float: x, Float: y, Float: z;
  242.     GetVehicleBoot(GetPVarInt(playerid, "LastVehicleID"), x, y, z);
  243.     LoadingPoint[playerid] = CreateDynamicCP(x, y, z, 3.0, .playerid = playerid);
  244.     SendClientMessage(playerid, 0x2ECC71FF, "MINING: {FFFFFF}You can press N to drop your ore.");
  245.     return 1;
  246. }
  247.  
  248. // Vein Functions
  249. Vein_Update(id)
  250. {
  251.     new label[64], type = VeinData[id][Type], bool: is_red = false;
  252.     if(VeinData[id][BeingMined] || VeinData[id][Amount] < 1) is_red = true;
  253.     format(label, sizeof(label), "%s\n%d/%d%s\n\n/ore info - /ore mine", OreData[type][Name], VeinData[id][Amount], OreData[type][Amount], (is_red) ? ("{E74C3C}") : ("{FFFFFF}"));
  254.     UpdateDynamic3DTextLabelText(VeinData[id][VeinLabel], OreData[type][Color], label);
  255.     return 1;
  256. }
  257.  
  258. Float: Vein_CalculateTime(id)
  259.     return (BAR_MAX / OreData[ VeinData[id][Type] ][Modifier]) * UPDATE_RATE;
  260.  
  261. // Ore Functions
  262. Ore_FindFreeID()
  263. {
  264.     new id = -1;
  265.     for(new i; i < MAX_ORES; i++)
  266.     {
  267.         if(!DroppedOres[i][OreExists])
  268.         {
  269.             id = i;
  270.             break;
  271.         }
  272.     }
  273.    
  274.     return id;
  275. }
  276.  
  277. // http://forum.sa-mp.com/showpost.php?p=3117531&postcount=5
  278. RGBAToARGB(rgba)
  279.     return rgba >>> 8 | rgba << 24;
  280.    
  281. // edited from evf
  282. GetNearestVehicleEx(playerid, Float: range = 6.5)
  283. {
  284.     new Float: fX, Float: fY, Float: fZ, Float: fSX, Float: fSY, Float: fSZ;
  285.  
  286.     for (new i = 1, j = GetVehiclePoolSize(); i <= j; i ++)
  287.     {
  288.         if (!IsVehicleStreamedIn(i, playerid)) continue;
  289.         GetVehiclePos(i, fX, fY, fZ);
  290.         GetVehicleModelInfo(GetVehicleModel(i), VEHICLE_MODEL_INFO_SIZE, fSX, fSY, fSZ);
  291.         if(IsPlayerInRangeOfPoint(playerid, range, fX, fY, fZ) && GetPlayerInterior(playerid) == GetVehicleInterior(i) && GetPlayerVirtualWorld(playerid) == GetVehicleVirtualWorld(i)) return i;
  292.     }
  293.    
  294.     return INVALID_VEHICLE_ID;
  295. }
  296.    
  297. public OnFilterScriptInit()
  298. {
  299.     Vein_Generate();
  300.     SetTimer("Vein_Generate", REGEN_TIME * 60000, true);
  301.    
  302.     new label[128];
  303.     for(new i; i < sizeof(DropPoints); i++)
  304.     {
  305.         format(label, sizeof(label), "Ore Drop Point - %s\n\n{FFFFFF}Bring your ores here to get money!", DropPoints[i][Location]);
  306.         DropPoints[i][PointLabel] = CreateDynamic3DTextLabel(label, 0xF1C40FFF, DropPoints[i][PointX], DropPoints[i][PointY], DropPoints[i][PointZ] + 0.5, 15.0, .testlos = 1);
  307.         DropPoints[i][PointCP] = CreateDynamicCP(DropPoints[i][PointX], DropPoints[i][PointY], DropPoints[i][PointZ], 6.0);
  308.     }
  309.  
  310.     for(new i, pool = GetPlayerPoolSize(); i <= pool; i++)
  311.     {
  312.         if(!IsPlayerConnected(i)) continue;
  313.         Player_Init(i);
  314.     }
  315.    
  316.     return 1;
  317. }
  318.  
  319. public OnFilterScriptExit()
  320. {
  321.     for(new i, pool = GetPlayerPoolSize(); i <= pool; i++)
  322.     {
  323.         if(!IsPlayerConnected(i)) continue;
  324.         Player_CleanUp(i, 1);
  325.         if(IsValidPlayerProgressBar(i, MiningBar[i])) DestroyPlayerProgressBar(i, MiningBar[i]);
  326.     }
  327.    
  328.     return 1;
  329. }
  330.  
  331. public OnPlayerConnect(playerid)
  332. {
  333.     Player_Init(playerid);
  334.     return 1;
  335. }
  336.  
  337. public OnPlayerStateChange(playerid, newstate, oldstate)
  338. {
  339.     if(newstate == PLAYER_STATE_DRIVER)
  340.     {
  341.         new vehicleid = GetPlayerVehicleID(playerid);
  342.         if(Vehicle_LoadedOres(vehicleid) > 0)
  343.         {
  344.             new string[128];
  345.             format(string, sizeof(string), "MINING: {FFFFFF}This vehicle has {F39C12}%d {FFFFFF}ores loaded which is worth {2ECC71}$%d.", Vehicle_LoadedOres(vehicleid), Vehicle_GetOreValue(vehicleid));
  346.             SendClientMessage(playerid, 0x2ECC71FF, string);
  347.             SendClientMessage(playerid, 0x2ECC71FF, "MINING: {FFFFFF}You can sell your loaded ores to drop points marked by a truck icon.");
  348.             SendClientMessage(playerid, 0x2ECC71FF, "MINING: {FFFFFF}You can use /vehicle to see more information.");
  349.             for(new i; i < sizeof(DropPoints); i++)
  350.             {
  351.                 PointIcons[playerid][i] = CreateDynamicMapIcon(DropPoints[i][PointX], DropPoints[i][PointY], DropPoints[i][PointZ], 51, 0, _, _, playerid, 8000.0, MAPICON_GLOBAL);
  352.                 TogglePlayerDynamicCP(playerid, DropPoints[i][PointCP], 1);
  353.             }
  354.         }
  355.        
  356.         SetPVarInt(playerid, "LastVehicleID", vehicleid);
  357.     }
  358.    
  359.     if(oldstate == PLAYER_STATE_DRIVER)
  360.     {
  361.         for(new i; i < sizeof(DropPoints); i++)
  362.         {
  363.             if(IsValidDynamicMapIcon(PointIcons[playerid][i]))
  364.             {
  365.                 DestroyDynamicMapIcon(PointIcons[playerid][i]);
  366.                 PointIcons[playerid][i] = -1;
  367.             }
  368.            
  369.             TogglePlayerDynamicCP(playerid, DropPoints[i][PointCP], 0);
  370.         }
  371.     }
  372.    
  373.     Player_CleanUp(playerid, 1);
  374.     return 1;
  375. }
  376.  
  377. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  378. {
  379.     if((newkeys & KEY_NO) && CarryingOre[playerid] != -1)
  380.     {
  381.         new id = Ore_FindFreeID();
  382.         if(id != -1)
  383.         {
  384.             if(Player_GetClosestOre(playerid, 1.5) != -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't drop your ore here.");
  385.             new label[48], type = CarryingOre[playerid], Float: x, Float: y, Float: z, Float: a;
  386.             GetPlayerPos(playerid, x, y, z);
  387.             GetPlayerFacingAngle(playerid, a);
  388.             x += (1.25 * floatsin(-a, degrees));
  389.             y += (1.25 * floatcos(-a, degrees));
  390.            
  391.             DroppedOres[id][Type] = type;
  392.             DroppedOres[id][OreTimer] = SetTimerEx("Ore_Destroy", ORE_TIME * 60000, false, "i", id);
  393.             DroppedOres[id][OreObject] = CreateDynamicObject(3929, x, y, z - 0.65, 0.0, 0.0, random(360));
  394.             SetDynamicObjectMaterial(DroppedOres[id][OreObject], 0, 2936, "kmb_rckx", "larock256", RGBAToARGB(OreData[type][Color]));
  395.             format(label, sizeof(label), "%s Ore\n{FFFFFF}\n\n/ore take", OreData[type][Name]);
  396.             DroppedOres[id][OreLabel] = CreateDynamic3DTextLabel(label, OreData[type][Color], x, y, z, 5.0, .testlos = 1);
  397.             DroppedOres[id][OreExists] = true;
  398.         }
  399.        
  400.         ApplyAnimation(playerid, "CARRY", "putdwn05", 4.1, 0, 1, 1, 0, 0, 1);
  401.         Player_CleanUp(playerid, 1);
  402.     }
  403.    
  404.     return 1;
  405. }
  406.  
  407. public OnPlayerDisconnect(playerid, reason)
  408. {
  409.     Player_CleanUp(playerid, 1);
  410.     return 1;
  411. }
  412.  
  413. public OnVehicleSpawn(vehicleid)
  414. {
  415.     Vehicle_CleanUp(vehicleid);
  416.     return 1;
  417. }
  418.  
  419. public OnPlayerEnterDynamicCP(playerid, checkpointid)
  420. {
  421.     if(checkpointid == LoadingPoint[playerid])
  422.     {
  423.         if(GetPVarInt(playerid, "LoadingCooldown") > gettime()) return 1;
  424.         new vehicleid = GetPVarInt(playerid, "LastVehicleID");
  425.         if(Vehicle_LoadedOres(vehicleid) >= VEHICLE_LIMIT) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't load any more ores to this vehicle.");
  426.         LoadedOres[vehicleid][ CarryingOre[playerid] ]++;
  427.        
  428.         new string[48];
  429.         format(string, sizeof(string), "MINING: {FFFFFF}Loaded %s.", OreData[ CarryingOre[playerid] ][Name]);
  430.         SendClientMessage(playerid, 0x2ECC71FF, string);
  431.         ApplyAnimation(playerid, "CARRY", "putdwn05", 4.1, 0, 1, 1, 0, 0, 1);
  432.         Player_CleanUp(playerid, 1);
  433.         return 1;
  434.     }
  435.    
  436.     if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  437.     {
  438.         for(new i; i < sizeof(DropPoints); i++)
  439.         {
  440.             if(checkpointid == DropPoints[i][PointCP])
  441.             {
  442.                 new string[128], vehicleid = GetPlayerVehicleID(playerid), cash = Vehicle_GetOreValue(vehicleid);
  443.                 format(string, sizeof(string), "MINING: {FFFFFF}Sold {F39C12}%d {FFFFFF}ores and earned {2ECC71}$%d.", Vehicle_LoadedOres(vehicleid), cash);
  444.                 SendClientMessage(playerid, 0x2ECC71FF, string);
  445.                 GivePlayerMoney(playerid, cash);
  446.                 Vehicle_CleanUp(vehicleid);
  447.                
  448.                 for(new x; x < sizeof(DropPoints); x++)
  449.                 {
  450.                     if(IsValidDynamicMapIcon(PointIcons[playerid][x]))
  451.                     {
  452.                         DestroyDynamicMapIcon(PointIcons[playerid][x]);
  453.                         PointIcons[playerid][x] = -1;
  454.                     }
  455.  
  456.                     TogglePlayerDynamicCP(playerid, DropPoints[x][PointCP], 0);
  457.                 }
  458.  
  459.                 break;
  460.             }
  461.         }
  462.     }
  463.    
  464.     return 1;
  465. }
  466.  
  467. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  468. {
  469.     switch(dialogid)
  470.     {
  471.         case DIALOG_ORE_TAKE:
  472.         {
  473.             if(!response) return 1;
  474.             if(MiningVein[playerid] != -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're already mining.");
  475.             if(CarryingOre[playerid] != -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're already carrying an ore.");
  476.             new id = GetNearestVehicleEx(playerid);
  477.             if(!IsValidVehicle(id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not near any vehicle.");
  478.             new Float: x, Float: y, Float: z;
  479.             GetVehicleBoot(id, x, y, z);
  480.             if(GetPlayerDistanceFromPoint(playerid, x, y, z) > 3.0) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not near the vehicle's back.");
  481.             if(LoadedOres[id][listitem] < 1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}This vehicle doesn't have that ore loaded.");
  482.             LoadedOres[id][listitem]--;
  483.             Player_GiveOre(playerid, listitem, 2);
  484.         }
  485.     }
  486.    
  487.     return 0;
  488. }
  489.  
  490. CMD:vehicle(playerid, params[])
  491. {
  492.     if(isnull(params)) return SendClientMessage(playerid, 0xE88732FF, "USAGE: {FFFFFF}/vehicle [ores/take]");
  493.     if(!strcmp(params, "ores", true)) {
  494.         new vehicleid = GetNearestVehicleEx(playerid);
  495.         if(!IsValidVehicle(vehicleid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not near any vehicle.");
  496.         if(!Vehicle_IsMiningVehicle(vehicleid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Vehicle isn't a mining vehicle.");
  497.         new string[196], title[32];
  498.         format(string, sizeof(string), "Name\tAmount\tValue\n");
  499.         for(new i; i < MAX_ORE_TYPES; i++) format(string, sizeof(string), "%s%s\t%d\t{2ECC71}$%d\n", string, OreData[i][Name], LoadedOres[vehicleid][i], Vehicle_GetOreValueByType(vehicleid, i));
  500.         format(title, sizeof(title), "Loaded Ores {E74C3C}(%d/%d)", Vehicle_LoadedOres(vehicleid), VEHICLE_LIMIT);
  501.         ShowPlayerDialog(playerid, DIALOG_ORE_INFO, DIALOG_STYLE_TABLIST_HEADERS, title, string, "Close", "");
  502.     }else if(!strcmp(params, "take")) {
  503.         if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't do this in a vehicle.");
  504.         if(MiningVein[playerid] != -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're already mining.");
  505.         if(CarryingOre[playerid] != -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're already carrying an ore.");
  506.         new id = GetNearestVehicleEx(playerid);
  507.         if(!IsValidVehicle(id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not near any vehicle.");
  508.         if(!Vehicle_IsMiningVehicle(id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Vehicle isn't a mining vehicle.");
  509.         new Float: x, Float: y, Float: z;
  510.         GetVehicleBoot(id, x, y, z);
  511.         if(GetPlayerDistanceFromPoint(playerid, x, y, z) > 3.0) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not near the vehicle's back.");
  512.         new string[196], title[32];
  513.         format(string, sizeof(string), "Name\tAmount\n");
  514.         for(new i; i < MAX_ORE_TYPES; i++) format(string, sizeof(string), "%s%s\t%d\n", string, OreData[i][Name], LoadedOres[id][i]);
  515.         format(title, sizeof(title), "Loaded Ores {E74C3C}(%d/%d)", Vehicle_LoadedOres(id), VEHICLE_LIMIT);
  516.         ShowPlayerDialog(playerid, DIALOG_ORE_TAKE, DIALOG_STYLE_TABLIST_HEADERS, title, string, "Take", "Close");
  517.     }
  518.  
  519.     return 1;
  520. }
  521.  
  522. CMD:ore(playerid, params[])
  523. {
  524.     if(isnull(params)) return SendClientMessage(playerid, 0xE88732FF, "USAGE: {FFFFFF}/ore [info/mine/take]");
  525.     if(!strcmp(params, "info", true)) {
  526.         new id = Player_GetClosestVein(playerid);
  527.         if(id == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not near a vein.");
  528.         new string[128], type = VeinData[id][Type];
  529.         format(string, sizeof(string), "Name\t{%06x}%s\nValue\t{2ECC71}$%d\nVein Value\t{2ECC71}$%d\nMining Time\t%.2f seconds", OreData[type][Color] >>> 8, OreData[type][Name], OreData[type][Value], (OreData[type][Value] * VeinData[id][Amount]), Vein_CalculateTime(id) / 1000);
  530.         ShowPlayerDialog(playerid, DIALOG_ORE_INFO, DIALOG_STYLE_TABLIST, "Ore Information", string, "Close", "");
  531.     }else if(!strcmp(params, "mine")) {
  532.         if(!Vehicle_IsMiningVehicle(GetPVarInt(playerid, "LastVehicleID"))) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Your last vehicle isn't available for mining.");
  533.         if(MiningVein[playerid] != -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're already mining.");
  534.         if(CarryingOre[playerid] != -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're already carrying an ore.");
  535.         new id = Player_GetClosestVein(playerid);
  536.         if(id == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not near any veins.");
  537.         if(VeinData[id][BeingMined]) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}The vein you want to mine is being mined by someone else.");
  538.         if(VeinData[id][Amount] < 1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}The vein you want to mine is empty.");
  539.         new Float: x, Float: y, Float: z;
  540.         GetVehicleBoot(GetPVarInt(playerid, "LastVehicleID"), x, y, z);
  541.         if(GetPlayerDistanceFromPoint(playerid, x, y, z) > 60.0) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Your last vehicle is too far away.");
  542.         MiningVein[playerid] = id;
  543.  
  544.         MiningTimer[playerid] = SetTimerEx("Player_Mine", UPDATE_RATE, true, "i", playerid);
  545.         SetPlayerProgressBarColour(playerid, MiningBar[playerid], OreData[ VeinData[id][Type] ][Color]);
  546.         SetPlayerProgressBarValue(playerid, MiningBar[playerid], 0.0);
  547.         ShowPlayerProgressBar(playerid, MiningBar[playerid]);
  548.         SetPlayerAttachedObject(playerid, ATTACH_INDEX, 19631, 6, 0.048, 0.029, 0.103, -80.0, 80.0, 0.0);
  549.         TogglePlayerControllable(playerid, 0);
  550.         SetPlayerArmedWeapon(playerid, 0);
  551.         ApplyAnimation(playerid, "BASEBALL", "Bat_1", 4.1, 1, 0, 0, 1, 0, 1);
  552.  
  553.         new string[64];
  554.         format(string, sizeof(string), "~n~~y~~h~Mining %s...", OreData[ VeinData[id][Type] ][Name]);
  555.         GameTextForPlayer(playerid, string, floatround(Vein_CalculateTime(id)) + 1000, 3);
  556.  
  557.         VeinData[id][BeingMined] = true;
  558.         Vein_Update(id);
  559.     }else if(!strcmp(params, "take")) {
  560.         if(!Vehicle_IsMiningVehicle(GetPVarInt(playerid, "LastVehicleID"))) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Your last vehicle isn't available for mining.");
  561.         if(MiningVein[playerid] != -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're already mining.");
  562.         if(CarryingOre[playerid] != -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're already carrying an ore.");
  563.         new id = Player_GetClosestOre(playerid);
  564.         if(id == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not near any ores.");
  565.         new Float: x, Float: y, Float: z;
  566.         GetVehicleBoot(GetPVarInt(playerid, "LastVehicleID"), x, y, z);
  567.         if(GetPlayerDistanceFromPoint(playerid, x, y, z) > 60.0) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Your last vehicle is too far away.");
  568.         Player_GiveOre(playerid, DroppedOres[id][Type]);
  569.         Ore_Destroy(id);
  570.     }
  571.    
  572.     return 1;
  573. }
  574.  
  575. forward Vein_Generate();
  576. public Vein_Generate()
  577. {
  578.     new Float: spawn_coords[][3] = {
  579.         {670.500732, 926.557067, -41.475772},
  580.         {678.838012, 925.259582, -41.473415},
  581.         {673.852478, 922.303161, -41.548767},
  582.         {679.489379, 917.357727, -41.276176},
  583.         {673.862670, 914.984008, -41.207321},
  584.         {666.973205, 921.626342, -41.613155},
  585.         {686.447021, 913.041320, -40.560043},
  586.         {679.475769, 910.190124, -41.048439},
  587.         {689.223510, 906.631835, -40.269996},
  588.         {683.865295, 905.557067, -40.672229},
  589.         {685.984741, 899.446899, -40.296852},
  590.         {694.975097, 902.076049, -39.668643},
  591.         {692.622558, 896.177978, -39.817611},
  592.         {697.621154, 891.354370, -39.355659},
  593.         {687.311584, 891.855468, -40.107055},
  594.         {692.106262, 887.992187, -39.684555},
  595.         {690.451110, 879.733947, -40.143363},
  596.         {696.097167, 882.666015, -39.491031},
  597.         {694.623901, 872.130493, -41.227066},
  598.         {693.549255, 862.414123, -43.129112},
  599.         {688.462280, 868.132019, -42.136383},
  600.         {688.172607, 857.167358, -43.610939},
  601.         {667.181762, 819.235046, -43.610939},
  602.         {663.166503, 811.138061, -43.610939},
  603.         {654.977294, 812.527770, -43.610939},
  604.         {651.793762, 805.835571, -43.610939},
  605.         {660.028137, 820.449340, -43.610939},
  606.         {646.762756, 814.375671, -43.610939},
  607.         {643.352294, 808.098266, -43.610939},
  608.         {637.106994, 812.568725, -43.610939},
  609.         {630.459289, 810.016418, -43.610939},
  610.         {624.303833, 813.422485, -43.610939},
  611.         {615.880615, 812.158264, -43.610939},
  612.         {610.537963, 815.100646, -43.603439},
  613.         {603.759033, 817.793640, -43.646705},
  614.         {597.451904, 822.874328, -43.579505},
  615.         {605.012512, 823.405212, -43.728958},
  616.         {618.658691, 818.265625, -43.603439},
  617.         {580.120239, 931.571899, -43.610939},
  618.         {569.243530, 928.569763, -43.610939},
  619.         {560.821105, 926.251770, -43.610939},
  620.         {576.770385, 923.246215, -43.610939},
  621.         {567.994628, 919.691223, -43.610939},
  622.         {575.571472, 916.415344, -43.664150},
  623.         {569.872924, 912.386962, -43.610939},
  624.         {587.315368, 913.924743, -43.796096},
  625.         {582.004028, 910.695190, -43.892337},
  626.         {560.253540, 909.118286, -43.610939},
  627.         {560.626708, 917.773559, -43.610939},
  628.         {530.954040, 909.995849, -43.610939},
  629.         {611.991699, 933.569702, -40.581710},
  630.         {609.077209, 922.338073, -42.479446},
  631.         {608.724792, 927.748413, -41.762489},
  632.         {649.643249, 928.250976, -39.830272},
  633.         {653.457092, 922.054199, -41.079425},
  634.         {644.637756, 922.242431, -41.463893},
  635.         {647.455993, 914.794494, -42.107845},
  636.         {657.229248, 914.974731, -41.061988},
  637.         {590.929870, 838.788818, -43.386558},
  638.         {600.051147, 841.034545, -44.017189},
  639.         {590.187194, 846.630859, -43.336963},
  640.         {582.725158, 843.719238, -43.011596},
  641.         {576.576538, 849.726928, -43.056209},
  642.         {573.548828, 844.638610, -42.740356},
  643.         {566.613159, 843.542358, -42.616565},
  644.         {559.421691, 840.400390, -42.141761},
  645.         {552.358398, 837.908569, -41.532897},
  646.         {562.215698, 848.450744, -42.990608},
  647.         {553.209289, 843.931945, -42.226833},
  648.         {545.759094, 836.563537, -41.645462},
  649.         {546.358886, 844.129211, -42.148715},
  650.         {553.752990, 849.901916, -42.900249},
  651.         {539.853637, 845.818481, -42.563919},
  652.         {528.839843, 843.820007, -43.529937},
  653.         {533.157653, 848.349853, -43.296516},
  654.         {520.944458, 846.692749, -43.610939},
  655.         {526.440917, 850.654602, -43.610939},
  656.         {536.822448, 852.424804, -43.107326},
  657.         {546.298095, 850.573242, -42.897747},
  658.         {551.512939, 879.981933, -43.265190},
  659.         {559.212646, 886.721923, -43.916355},
  660.         {566.831054, 885.784973, -44.073543},
  661.         {574.826660, 883.917602, -44.008312},
  662.         {573.601867, 877.364135, -44.474807},
  663.         {573.405334, 865.376098, -43.900402},
  664.         {566.972229, 867.566162, -44.025466},
  665.         {566.110717, 875.090148, -44.276050},
  666.         {559.155700, 867.633850, -43.972709},
  667.         {552.657165, 871.074157, -43.586654},
  668.         {590.525634, 884.257019, -44.786952},
  669.         {581.356384, 885.243469, -44.612636},
  670.         {595.025329, 891.404907, -45.047763},
  671.         {601.949951, 893.569396, -45.066448},
  672.         {599.344055, 887.141723, -44.512237},
  673.         {597.956787, 880.352294, -43.925403},
  674.         {597.799316, 872.847290, -43.639019},
  675.         {603.701110, 881.868469, -43.749420},
  676.         {609.776245, 877.436706, -43.610939},
  677.         {609.780212, 888.589721, -44.169811},
  678.         {609.496215, 894.040039, -44.493488},
  679.         {615.364379, 883.519409, -43.610939},
  680.         {616.436218, 866.841308, -43.610939},
  681.         {624.843017, 869.950256, -43.603439},
  682.         {620.875671, 875.108886, -43.603439},
  683.         {631.959045, 874.122375, -43.603439},
  684.         {626.006774, 879.856384, -43.610939},
  685.         {638.100219, 880.400573, -43.610939},
  686.         {634.172485, 885.813476, -43.610939},
  687.         {635.576660, 893.294067, -43.603439},
  688.         {641.967956, 898.003051, -43.558959},
  689.         {648.679199, 897.242004, -42.743541},
  690.         {654.830322, 895.541931, -42.002933},
  691.         {662.546447, 893.076171, -41.048439},
  692.         {652.472778, 889.743713, -42.355361},
  693.         {644.680358, 887.102661, -43.205955},
  694.         {638.895996, 888.600891, -43.603439},
  695.         {643.382629, 892.997375, -43.376350},
  696.         {681.386230, 863.475097, -42.681892},
  697.         {646.588012, 860.239013, -43.376369},
  698.         {648.004821, 851.773437, -43.610939},
  699.         {654.417053, 855.355895, -43.610939},
  700.         {660.318481, 849.473388, -43.610939},
  701.         {661.591796, 861.592041, -43.277667},
  702.         {660.899780, 867.371459, -42.788570}
  703.     };
  704.  
  705.     for(new i, pool = GetPlayerPoolSize(); i <= pool; i++)
  706.     {
  707.         if(!IsPlayerConnected(i)) continue;
  708.         Player_CleanUp(i);
  709.     }
  710.  
  711.     // Destroy Old Veins
  712.     for(new i; i < MAX_VEINS; i++)
  713.     {
  714.         if(!VeinData[i][VeinExists]) continue;
  715.         DestroyDynamicObject(VeinData[i][VeinObject]);
  716.         DestroyDynamic3DTextLabel(VeinData[i][VeinLabel]);
  717.         VeinData[i][VeinExists] = false;
  718.     }
  719.  
  720.     // Respawn
  721.     new type;
  722.     for(new i; i < sizeof(spawn_coords); i++)
  723.     {
  724.         if(i >= MAX_VEINS) break;
  725.         type = random(MAX_ORE_TYPES);
  726.  
  727.         VeinData[i][Type] = type;
  728.         VeinData[i][Amount] = OreData[type][Amount];
  729.         VeinData[i][VeinObject] = CreateDynamicObject(867, spawn_coords[i][0], spawn_coords[i][1], spawn_coords[i][2], 0.0, 0.0, random(360));
  730.         SetDynamicObjectMaterial(VeinData[i][VeinObject], 0, 2936, "kmb_rckx", "larock256", RGBAToARGB(OreData[type][Color]));
  731.         VeinData[i][VeinLabel] = CreateDynamic3DTextLabel("Label", OreData[type][Color], spawn_coords[i][0], spawn_coords[i][1], spawn_coords[i][2] + 0.5, 5.0, .testlos = 1);
  732.         VeinData[i][VeinExists] = true;
  733.         Vein_Update(i);
  734.     }
  735.  
  736.     return 1;
  737. }
  738.  
  739. forward Player_Mine(playerid);
  740. public Player_Mine(playerid)
  741. {
  742.     if(MiningVein[playerid] != -1)
  743.     {
  744.         new vein_id = MiningVein[playerid], Float: value = GetPlayerProgressBarValue(playerid, MiningBar[playerid]) + OreData[ VeinData[vein_id][Type] ][Modifier];
  745.         if(value >= BAR_MAX) {
  746.             Player_CleanUp(playerid);
  747.            
  748.             if(random(100) < OreData[ VeinData[vein_id][Type] ][Rate]) {
  749.                 VeinData[vein_id][Amount]--;
  750.                 Player_GiveOre(playerid, VeinData[vein_id][Type]);
  751.                 Vein_Update(vein_id);
  752.                
  753.                 new string[64];
  754.                 format(string, sizeof(string), "~n~~g~~h~Mined %s", OreData[ VeinData[vein_id][Type] ][Name]);
  755.                 GameTextForPlayer(playerid, string, 2000, 3);
  756.             }else{
  757.                 GameTextForPlayer(playerid, "~n~~r~~h~Mining Failed", 2000, 3);
  758.             }
  759.         }else{
  760.             SetPlayerProgressBarValue(playerid, MiningBar[playerid], value);
  761.         }
  762.     }
  763.    
  764.     return 1;
  765. }
  766.  
  767. forward Ore_Destroy(id);
  768. public Ore_Destroy(id)
  769. {
  770.     KillTimer(DroppedOres[id][OreTimer]);
  771.     DestroyDynamicObject(DroppedOres[id][OreObject]);
  772.     DestroyDynamic3DTextLabel(DroppedOres[id][OreLabel]);
  773.     DroppedOres[id][OreExists] = false;
  774.     return 1;
  775. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement