Forum in READ ONLY mode! All questions and discussions on Discord official server, invite link: https://discord.gg/VxsGzJ7

Using External Files

Ask for help
Post Reply
DeadLy_DeMaGe
Neophyte
Neophyte
Posts: 17
Joined: 10.01.2015 3:01

Using External Files

Post by DeadLy_DeMaGe »

Is there any working script which uses external file for getting location?

I am currently working on a script that uses x, y and z spots from another file (like diglocations.txt). Main goal is recalling rune's on runebook one by one and digging for ore. Tried to work with scanning area but its a mess and I'm not that good right now so I'm working on some other way. This is the external file example:

Code: Select all

CurrentRune / SpotNumber / X / Y / Z
1 1 1234 1234 1234
1 2 1234 1234 1234
1 3 1234 1234 1234
2 1 1234 1234 1234
2 2 1234 1234 1234
2 3 1234 1234 1234
...
As you see, I need a code that looks for CurrentRune's mining spots. In the example, Rune1 and Rune2 has 3 different mining spots so in the first rune, script should dig that 3 spots and then recall to next rune and dig that rune's spots. I hope I could clearly explained myself.
drabadan
Expert
Expert
Posts: 730
Joined: 13.12.2012 17:35
Contact:

Re: Using External Files

Post by drabadan »

Why do you need external files, in any way you will load it to memory, so maybe it would be simpler if you would just declacre your data in the script?

Here is small code exaple:

Code: Select all

program Digger;


//declaring our type of data;
type
 TDigPoint = record
  Tile : Word;
  X, Y : Integer;
  CurrentRune, SpotNumber : Integer;
 end;


var
 //here is an array which will store all data in itself;
 DigPoints : Array of TDigPoint;

//procedure which makes all the job of adding items to array;
procedure AddDigPointToArray(Tile : Word; X,Y, CurrentRune, SpotNumber : Integer);
begin
 SetLength(DigPoints, Length(DigPoints)+1);
 DigPoints[High(DigPoints)].Tile := Tile;
 DigPoints[High(DigPoints)].X := X;
 DigPoints[High(DigPoints)].Y := Y;
 DigPoints[High(DigPoints)].CurrentRune := CurrentRune;
 DigPoints[High(DigPoints)].SpotNumber := SpotNumber;
end; 

//in this procedure we are adding all the data which will be storing in memory;
procedure Init_DigPoints;
begin
 AddDigPointToArray($1339, 2207, 509, 1, 1);
 AddDigPointToArray($1339, 2208, 509, 1, 2);
 AddDigPointToArray($1339, 2209, 509, 2, 1);
 AddDigPointToArray($1339, 2210, 509, 2, 2);
 AddDigPointToArray($1339, 2211, 509, 2, 3);
 AddDigPointToArray($1339, 2212, 509, 3, 1);
 
 AddToSystemJournal('Dig points in array: ' + IntToStr(Length(DigPoints)));
end;

//not recalling but declaring what to do;
procedure RecallTo(RuneIndex : Integer);
begin
 AddToSystemJournal('Recalling to' + IntToStr(RuneIndex));
end;
//same;
procedure MinTile(Tile : Word; X, Y, currSpot : Integer);
begin
 AddToSystemJournal('Mining at: ' + IntToStr(X) + ' ' + IntToStr(Y) + ' ' + IntToStr(currSpot))
end;


//main procedure for handling our array
procedure GoForEveryElementOfDigPoints;
var
 i, previousRune : Integer;
begin
 //this variable is for knowing that we should recall or our next rune is the same and we don't need to recall
 previousRune := 0;  
 //moving on every element of array
 for i := Low(DigPoints) to High(DigPoints) do begin
  //here we are knowing is the currrune not equals to prevrune;
  if (DigPoints[i].CurrentRune <> previousRune) then begin
   //if so recalling...	
   RecallTo(DigPoints[i].CurrentRune);
   //renewing prevrune so it would be like rune that we racalled;
   previousRune := DigPoints[i].CurrentRune;
  end;   
  
  //get to spot with NewMoveXY
  NewMoveXY(DigPoints[i].X, DigPoints[i].Y, true, 0, true);
  //mining tile, but procedure wouldn't mine it just says where it is;
  MinTile(DigPoints[i].Tile, DigPoints[i].X, DigPoints[i].Y, DigPoints[i].SpotNumber);
 end;
end;

begin
 //we need to declare and create our array with this procedure;
 Init_DigPoints;
 // main procedure;
 GoForEveryElementOfDigPoints;
 
 {Enjoy your coding with pascal!} 
end.

I was trying to show a skeleton of script you want, hope i undestood you clearly.

Btw, you Must work with dynamic data, it would be much more easier.
DeadLy_DeMaGe
Neophyte
Neophyte
Posts: 17
Joined: 10.01.2015 3:01

Re: Using External Files

Post by DeadLy_DeMaGe »

Thanks for help, I'll work on this tonight when I get home. I appreciate your help :)

I was working on tile/map scan before this but couldn't make it work properly. It would be awesome if I could because there would be no need for dig spots anymore with it but scanning area for both caves, sands and mountains is the part I couldn't do. I was able to make the script recall, crafting required tools (like tinker tools and shovel), dropping ores and anything else except tile scanning. Also there is no properly working tile scan script for sands, caves and mountains in both English and Russian section unfortunally.
drabadan
Expert
Expert
Posts: 730
Joined: 13.12.2012 17:35
Contact:

Re: Using External Files

Post by drabadan »

DeadLy_DeMaGe wrote:Thanks for help, I'll work on this tonight when I get home. I appreciate your help :)

I was working on tile/map scan before this but couldn't make it work properly. It would be awesome if I could because there would be no need for dig spots anymore with it but scanning area for both caves, sands and mountains is the part I couldn't do. I was able to make the script recall, crafting required tools (like tinker tools and shovel), dropping ores and anything else except tile scanning. Also there is no properly working tile scan script for sands, caves and mountains in both English and Russian section unfortunally.
Here is Gauhar's script, for digging anything at your feet. There are a lot of information about any kinds of tiles and how to spot them.
Gauhar's script
PROGRAM TestMining;
CONST
tMinerTool = $0F39; //Чем копать (тип инструмента): $0F39 - Shovel. $0E86 - Pickaxe.

Procedure MiningHere();
Var
msgMine_WhereDig, msgMine_Sucs, msgMine_Fail, msgMine_NoMetal,
msgMine_FarAway, msgMine_CantThere, msgMine_CantThat, msgMine_Target,
msgMine_YouMoved, msgMine_PackFull, msgMine_WormTool, msgMine_Riding,
msgMine_Polymorphed, msgMine_ExtractStone, oreAndStone_DoubleHarvest,
sand_NoResources, sand_Fail, sand_Sucs, sand_PackFull,
msgMine_END, msgMine_ALL : String;
MountainTiles, SandTiles, CaveTiles: array of Word;
idMinerTool: Cardinal;
startTime: TDateTime;
MapCell: TMapCell;
StaticCell: TStaticCell;
T, X, Y: Word;
Z: ShortInt;
i, j, ix, iy: Integer;
isMountain: Boolean;
Begin
// СООБЩЕНИЯ ВО ВРЕМЯ ДОБЫЧИ РУДЫ:
msgMine_WhereDig := 'Where do you wish to dig?';
msgMine_Sucs := 'You dig some'; //You dig some ... ore and put it in your backpack.
msgMine_Fail := 'You loosen some rocks but fail to find any useable ore.';
msgMine_NoMetal := 'There is no metal here to mine.';
msgMine_FarAway := 'That is too far away.';
msgMine_CantThere := 'You can''t mine there.';
msgMine_CantThat := 'You can''t mine that.';
msgMine_Target := 'Target cannot be seen.';
msgMine_YouMoved := 'You have moved too far away to continue mining.';
msgMine_PackFull := 'Your backpack is full, so the ore you mined is lost.';
msgMine_WormTool := 'You have worn out your tool!';
msgMine_Riding := 'You can''t mine while riding.';
msgMine_Polymorphed := 'You can''t mine while polymorphed.';
msgMine_ExtractStone := 'You carefully extract some workable stone from the ore vein!';
oreAndStone_DoubleHarvest := 'Someone has gotten to the metal before you.';
sand_Fail := 'You dig for a while but fail to find any of sufficient quality for glassblowing.';
sand_Sucs := 'You carefully dig up sand of sufficient quality for glassblowing.';
sand_NoResources := 'There is no sand here to mine.';
sand_PackFull := 'Your backpack can''t hold the sand, and it is lost!';
// Сообщения при которых завершается добыча:
msgMine_END := msgMine_NoMetal + '|' + msgMine_FarAway + '|' +
msgMine_CantThere + '|' + msgMine_CantThat + '|' +
msgMine_Target + '|' + msgMine_YouMoved + '|' +
sand_NoResources + '|' + msgMine_PackFull + '|' + sand_PackFull;
// Все сообшения:
msgMine_ALL := msgMine_END + '|' + msgMine_Sucs + '|' + msgMine_Fail + '|' +
sand_Fail + '|' + sand_Sucs + '|' + msgMine_ExtractStone;

// ТАЙЛЫ В КОТОРЫХ МОЖНО ВЕСТИ ДОБЫЧУ (из исходников RunUO):
MountainTiles :=
[
220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 236, 237, 238,
239, 240, 241, 242, 243, 244, 245, 246, 247, 252, 253, 254, 255, 256, 257,
258, 259, 260, 261, 262, 263, 268, 269, 270, 271, 272, 273, 274, 275, 276,
277, 278, 279, 286, 287, 288, 289, 290, 291, 292, 293, 294, 296, 296, 297,
321, 322, 323, 324, 467, 468, 469, 470, 471, 472, 473, 474, 476, 477, 478,
479, 480, 481, 482, 483, 484, 485, 486, 487, 492, 493, 494, 495, 543, 544,
545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559,
560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574,
575, 576, 577, 578, 579, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590,
591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 610, 611, 612, 613,
1010, 1741, 1742, 1743, 1744, 1745, 1746, 1747, 1748, 1749, 1750, 1751,
1752, 1753, 1754, 1755, 1756, 1757, 1771, 1772, 1773, 1774, 1775, 1776,
1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788,
1789, 1790, 1801, 1802, 1803, 1804, 1805, 1806, 1807, 1808, 1809, 1811,
1812, 1813, 1814, 1815, 1816, 1817, 1818, 1819, 1820, 1821, 1822, 1823,
1824, 1831, 1832, 1833, 1834, 1835, 1836, 1837, 1838, 1839, 1840, 1841,
1842, 1843, 1844, 1845, 1846, 1847, 1848, 1849, 1850, 1851, 1852, 1853,
1854, 1861, 1862, 1863, 1864, 1865, 1866, 1867, 1868, 1869, 1870, 1871,
1872, 1873, 1874, 1875, 1876, 1877, 1878, 1879, 1880, 1881, 1882, 1883,
1884, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991,
1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
2004, 2028, 2029, 2030, 2031, 2032, 2033, 2100, 2101, 2102, 2103, 2104,
2105, 17723, 17724, 17725, 17726, 17727, 17728, 17729, 17730, 17731, 17732,
17733, 17734, 17735, 17736, 17737, 17738, 17739, 17740, 17741, 17742, 17743
];
SandTiles :=
[
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 68, 69, 70, 71, 72, 73, 74, 75,
286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300,
301, 402, 424, 425, 426, 427, 441, 442, 443, 444, 445, 446, 447, 448, 449,
450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464,
465, 642, 643, 644, 645, 650, 651, 652, 653, 654, 655, 656, 657, 821, 822,
823, 824, 825, 826, 827, 828, 833, 834, 835, 836, 845, 846, 847, 848, 849,
850, 851, 852, 857, 858, 859, 860, 951, 952, 953, 954, 955, 956, 957, 958,
967, 968, 969, 970,
1447, 1448, 1449, 1450, 1451, 1452, 1453, 1454, 1455, 1456, 1457, 1458, 1611,
1612, 1613, 1614, 1615, 1616, 1617, 1618, 1623, 1624, 1625, 1626, 1635, 1636,
1637, 1638, 1639, 1640, 1641, 1642, 1647, 1648, 1649, 1650
];
CaveTiles :=
[
1339, 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1348, 1349,
1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359
];
if TargetPresent then CancelTarget else CancelWaitTarget;
T := 0;
X := GetX(self);
Y := GetY(self);
Z := GetZ(self);
isMountain := TRUE;
// Ищим горы и кочки в радиусе 1 тайл:
for ix := (X - 1) to (X + 1) do
begin
for iy := (Y - 1) to (Y + 1) do
begin
MapCell := GetMapCell(ix, iy, WorldNum);
for i := 0 to (Length(MountainTiles) - 1) do
if (MapCell.Tile = MountainTiles) and (abs(Z - MapCell.Z) < 15) then
begin
AddToSystemJournal('-- MOUNTAIN --');
T := MapCell.Tile;
X := ix;
Y := iy;
Z := MapCell.Z;
BREAK;
end;
if T > 0 then BREAK;
end;
if T > 0 then BREAK;
end;
// Ищим под ногами песок:
if T = 0 then
begin
MapCell := GetMapCell(X, Y, WorldNum);
for i := 0 to (Length(SandTiles) - 1) do
if (MapCell.Tile = SandTiles) and (abs(Z - MapCell.Z) < 15) then
begin
AddToSystemJournal('-- SAND --');
isMountain := TRUE;
T := MapCell.Tile;
Z := MapCell.Z;
BREAK;
end;
end;
// Ищим под ногами пол шахты:
if T = 0 then
begin
isMountain := FALSE;
StaticCell := ReadStaticsXY(X, Y, WorldNum);
if StaticCell.StaticCount > 0 then
begin
for i := 0 to (StaticCell.StaticCount - 1) do
begin
for j := 0 to (Length(CaveTiles) - 1) do
begin
if StaticCell.Statics.Tile = CaveTiles[j] then
begin
AddToSystemJournal('---- CAVE ----');
T := StaticCell.Statics.Tile;
BREAK;
end;
end;
if T > 0 then BREAK;
end;
end;
end;
AddToSystemJournal('-- Tile = ' + IntToStr(T) + ' X = ' + IntToStr(ix) + ' Y = ' + IntToStr(iy) + ' Z = ' + IntToStr(Z));
if T = 0 then
begin
AddToSystemJournal('-- Здесь нельзя добывать.');
ClientPrint('ЗДЕСЬ НЕЛЬЗЯ ДОБЫВАТЬ.');
EXIT;
end;
repeat
idMinerTool := FindType(tMinerTool, Backpack);
if idMinerTool = $0 then
begin
AddToSystemJournal('-- Нет инструментов для добычи!');
ClientPrint('НЕТ ИСТРУМЕНТА ДЛЯ ДОБЫЧИ.');
EXIT;
end;
//if TargetPresent then CancelTarget else CancelWaitTarget;
Wait(100);
startTime := Now;
if isMountain = TRUE then
WaitTargetXYZ(X, Y, Z) //Горы, кочки и песок.
else
WaitTargetTile(T, X, Y, Z); //Шахта.
UseObject(idMinerTool);
repeat
wait(100);
until Dead or not Connected or (InJournalBetweenTimes(msgMine_ALL,startTime,Now) <> -1);
until Dead or not Connected or (InJournalBetweenTimes(msgMine_END,startTime,Now) <> -1);
End;

BEGIN
MiningHere();
END.
DeadLy_DeMaGe
Neophyte
Neophyte
Posts: 17
Joined: 10.01.2015 3:01

Re: Using External Files

Post by DeadLy_DeMaGe »

drabadan wrote:
DeadLy_DeMaGe wrote:Thanks for help, I'll work on this tonight when I get home. I appreciate your help :)

I was working on tile/map scan before this but couldn't make it work properly. It would be awesome if I could because there would be no need for dig spots anymore with it but scanning area for both caves, sands and mountains is the part I couldn't do. I was able to make the script recall, crafting required tools (like tinker tools and shovel), dropping ores and anything else except tile scanning. Also there is no properly working tile scan script for sands, caves and mountains in both English and Russian section unfortunally.
Here is Gauhar's script, for digging anything at your feet. There are a lot of information about any kinds of tiles and how to spot them.
Gauhar's script
PROGRAM TestMining;
CONST
tMinerTool = $0F39; //Чем копать (тип инструмента): $0F39 - Shovel. $0E86 - Pickaxe.

Procedure MiningHere();
Var
msgMine_WhereDig, msgMine_Sucs, msgMine_Fail, msgMine_NoMetal,
msgMine_FarAway, msgMine_CantThere, msgMine_CantThat, msgMine_Target,
msgMine_YouMoved, msgMine_PackFull, msgMine_WormTool, msgMine_Riding,
msgMine_Polymorphed, msgMine_ExtractStone, oreAndStone_DoubleHarvest,
sand_NoResources, sand_Fail, sand_Sucs, sand_PackFull,
msgMine_END, msgMine_ALL : String;
MountainTiles, SandTiles, CaveTiles: array of Word;
idMinerTool: Cardinal;
startTime: TDateTime;
MapCell: TMapCell;
StaticCell: TStaticCell;
T, X, Y: Word;
Z: ShortInt;
i, j, ix, iy: Integer;
isMountain: Boolean;
Begin
// СООБЩЕНИЯ ВО ВРЕМЯ ДОБЫЧИ РУДЫ:
msgMine_WhereDig := 'Where do you wish to dig?';
msgMine_Sucs := 'You dig some'; //You dig some ... ore and put it in your backpack.
msgMine_Fail := 'You loosen some rocks but fail to find any useable ore.';
msgMine_NoMetal := 'There is no metal here to mine.';
msgMine_FarAway := 'That is too far away.';
msgMine_CantThere := 'You can''t mine there.';
msgMine_CantThat := 'You can''t mine that.';
msgMine_Target := 'Target cannot be seen.';
msgMine_YouMoved := 'You have moved too far away to continue mining.';
msgMine_PackFull := 'Your backpack is full, so the ore you mined is lost.';
msgMine_WormTool := 'You have worn out your tool!';
msgMine_Riding := 'You can''t mine while riding.';
msgMine_Polymorphed := 'You can''t mine while polymorphed.';
msgMine_ExtractStone := 'You carefully extract some workable stone from the ore vein!';
oreAndStone_DoubleHarvest := 'Someone has gotten to the metal before you.';
sand_Fail := 'You dig for a while but fail to find any of sufficient quality for glassblowing.';
sand_Sucs := 'You carefully dig up sand of sufficient quality for glassblowing.';
sand_NoResources := 'There is no sand here to mine.';
sand_PackFull := 'Your backpack can''t hold the sand, and it is lost!';
// Сообщения при которых завершается добыча:
msgMine_END := msgMine_NoMetal + '|' + msgMine_FarAway + '|' +
msgMine_CantThere + '|' + msgMine_CantThat + '|' +
msgMine_Target + '|' + msgMine_YouMoved + '|' +
sand_NoResources + '|' + msgMine_PackFull + '|' + sand_PackFull;
// Все сообшения:
msgMine_ALL := msgMine_END + '|' + msgMine_Sucs + '|' + msgMine_Fail + '|' +
sand_Fail + '|' + sand_Sucs + '|' + msgMine_ExtractStone;

// ТАЙЛЫ В КОТОРЫХ МОЖНО ВЕСТИ ДОБЫЧУ (из исходников RunUO):
MountainTiles :=
[
220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 236, 237, 238,
239, 240, 241, 242, 243, 244, 245, 246, 247, 252, 253, 254, 255, 256, 257,
258, 259, 260, 261, 262, 263, 268, 269, 270, 271, 272, 273, 274, 275, 276,
277, 278, 279, 286, 287, 288, 289, 290, 291, 292, 293, 294, 296, 296, 297,
321, 322, 323, 324, 467, 468, 469, 470, 471, 472, 473, 474, 476, 477, 478,
479, 480, 481, 482, 483, 484, 485, 486, 487, 492, 493, 494, 495, 543, 544,
545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559,
560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574,
575, 576, 577, 578, 579, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590,
591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 610, 611, 612, 613,
1010, 1741, 1742, 1743, 1744, 1745, 1746, 1747, 1748, 1749, 1750, 1751,
1752, 1753, 1754, 1755, 1756, 1757, 1771, 1772, 1773, 1774, 1775, 1776,
1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788,
1789, 1790, 1801, 1802, 1803, 1804, 1805, 1806, 1807, 1808, 1809, 1811,
1812, 1813, 1814, 1815, 1816, 1817, 1818, 1819, 1820, 1821, 1822, 1823,
1824, 1831, 1832, 1833, 1834, 1835, 1836, 1837, 1838, 1839, 1840, 1841,
1842, 1843, 1844, 1845, 1846, 1847, 1848, 1849, 1850, 1851, 1852, 1853,
1854, 1861, 1862, 1863, 1864, 1865, 1866, 1867, 1868, 1869, 1870, 1871,
1872, 1873, 1874, 1875, 1876, 1877, 1878, 1879, 1880, 1881, 1882, 1883,
1884, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991,
1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
2004, 2028, 2029, 2030, 2031, 2032, 2033, 2100, 2101, 2102, 2103, 2104,
2105, 17723, 17724, 17725, 17726, 17727, 17728, 17729, 17730, 17731, 17732,
17733, 17734, 17735, 17736, 17737, 17738, 17739, 17740, 17741, 17742, 17743
];
SandTiles :=
[
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 68, 69, 70, 71, 72, 73, 74, 75,
286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300,
301, 402, 424, 425, 426, 427, 441, 442, 443, 444, 445, 446, 447, 448, 449,
450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464,
465, 642, 643, 644, 645, 650, 651, 652, 653, 654, 655, 656, 657, 821, 822,
823, 824, 825, 826, 827, 828, 833, 834, 835, 836, 845, 846, 847, 848, 849,
850, 851, 852, 857, 858, 859, 860, 951, 952, 953, 954, 955, 956, 957, 958,
967, 968, 969, 970,
1447, 1448, 1449, 1450, 1451, 1452, 1453, 1454, 1455, 1456, 1457, 1458, 1611,
1612, 1613, 1614, 1615, 1616, 1617, 1618, 1623, 1624, 1625, 1626, 1635, 1636,
1637, 1638, 1639, 1640, 1641, 1642, 1647, 1648, 1649, 1650
];
CaveTiles :=
[
1339, 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1348, 1349,
1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359
];
if TargetPresent then CancelTarget else CancelWaitTarget;
T := 0;
X := GetX(self);
Y := GetY(self);
Z := GetZ(self);
isMountain := TRUE;
// Ищим горы и кочки в радиусе 1 тайл:
for ix := (X - 1) to (X + 1) do
begin
for iy := (Y - 1) to (Y + 1) do
begin
MapCell := GetMapCell(ix, iy, WorldNum);
for i := 0 to (Length(MountainTiles) - 1) do
if (MapCell.Tile = MountainTiles) and (abs(Z - MapCell.Z) < 15) then
begin
AddToSystemJournal('-- MOUNTAIN --');
T := MapCell.Tile;
X := ix;
Y := iy;
Z := MapCell.Z;
BREAK;
end;
if T > 0 then BREAK;
end;
if T > 0 then BREAK;
end;
// Ищим под ногами песок:
if T = 0 then
begin
MapCell := GetMapCell(X, Y, WorldNum);
for i := 0 to (Length(SandTiles) - 1) do
if (MapCell.Tile = SandTiles) and (abs(Z - MapCell.Z) < 15) then
begin
AddToSystemJournal('-- SAND --');
isMountain := TRUE;
T := MapCell.Tile;
Z := MapCell.Z;
BREAK;
end;
end;
// Ищим под ногами пол шахты:
if T = 0 then
begin
isMountain := FALSE;
StaticCell := ReadStaticsXY(X, Y, WorldNum);
if StaticCell.StaticCount > 0 then
begin
for i := 0 to (StaticCell.StaticCount - 1) do
begin
for j := 0 to (Length(CaveTiles) - 1) do
begin
if StaticCell.Statics.Tile = CaveTiles[j] then
begin
AddToSystemJournal('---- CAVE ----');
T := StaticCell.Statics.Tile;
BREAK;
end;
end;
if T > 0 then BREAK;
end;
end;
end;
AddToSystemJournal('-- Tile = ' + IntToStr(T) + ' X = ' + IntToStr(ix) + ' Y = ' + IntToStr(iy) + ' Z = ' + IntToStr(Z));
if T = 0 then
begin
AddToSystemJournal('-- Здесь нельзя добывать.');
ClientPrint('ЗДЕСЬ НЕЛЬЗЯ ДОБЫВАТЬ.');
EXIT;
end;
repeat
idMinerTool := FindType(tMinerTool, Backpack);
if idMinerTool = $0 then
begin
AddToSystemJournal('-- Нет инструментов для добычи!');
ClientPrint('НЕТ ИСТРУМЕНТА ДЛЯ ДОБЫЧИ.');
EXIT;
end;
//if TargetPresent then CancelTarget else CancelWaitTarget;
Wait(100);
startTime := Now;
if isMountain = TRUE then
WaitTargetXYZ(X, Y, Z) //Горы, кочки и песок.
else
WaitTargetTile(T, X, Y, Z); //Шахта.
UseObject(idMinerTool);
repeat
wait(100);
until Dead or not Connected or (InJournalBetweenTimes(msgMine_ALL,startTime,Now) <> -1);
until Dead or not Connected or (InJournalBetweenTimes(msgMine_END,startTime,Now) <> -1);
End;

BEGIN
MiningHere();
END.


I know this one and this was the closest thing to I was searching for but it stops after first spot it finded consumes (till no ores left). Couldn't loop it for make it search for every spots in +2/-2 radius and dig.

PS: Also I sent him a private message about that problem of mine but he is not logging to forum for a while.
DeadLy_DeMaGe
Neophyte
Neophyte
Posts: 17
Joined: 10.01.2015 3:01

Re: Using External Files

Post by DeadLy_DeMaGe »

I finally could work on this last night, I got stuck from another point. Thanks to your code, I managed to add all dig points to array but how do I use these spots?

I mean how do we get CurrentRune's DigSpots from array? Lets say we are in first rune so CurrentRune will be 1. We need dig spots for rune number 1. In your code, there is 2 different spots for first rune;
AddDigPointToArray($1339, 2207, 509, 1, 1);
AddDigPointToArray($1339, 2208, 509, 1, 2);
How do I get these two spots from array and define as spots to be dig?
drabadan
Expert
Expert
Posts: 730
Joined: 13.12.2012 17:35
Contact:

Re: Using External Files

Post by drabadan »

DeadLy_DeMaGe wrote:I finally could work on this last night, I got stuck from another point. Thanks to your code, I managed to add all dig points to array but how do I use these spots?

I mean how do we get CurrentRune's DigSpots from array? Lets say we are in first rune so CurrentRune will be 1. We need dig spots for rune number 1. In your code, there is 2 different spots for first rune;
AddDigPointToArray($1339, 2207, 509, 1, 1);
AddDigPointToArray($1339, 2208, 509, 1, 2);
How do I get these two spots from array and define as spots to be dig?
all of the spots are for digging... why do you think you need to define spots for digging.

Code: Select all

 //here we are knowing is the currrune not equals to prevrune;
  if (DigPoints[i].CurrentRune <> previousRune) then begin
   //if so recalling...   
   RecallTo(DigPoints[i].CurrentRune);
...

 MinTile(DigPoints[i].Tile, DigPoints[i].X, DigPoints[i].Y, DigPoints[i].SpotNumber); //here you are digging.
you need to understand the code more clearly.
Gauhar
Novice
Novice
Posts: 87
Joined: 08.07.2008 17:40

Re: Using External Files

Post by Gauhar »

DeadLy_DeMaGe wrote:
drabadan wrote:
DeadLy_DeMaGe wrote:Thanks for help, I'll work on this tonight when I get home. I appreciate your help :)

I was working on tile/map scan before this but couldn't make it work properly. It would be awesome if I could because there would be no need for dig spots anymore with it but scanning area for both caves, sands and mountains is the part I couldn't do. I was able to make the script recall, crafting required tools (like tinker tools and shovel), dropping ores and anything else except tile scanning. Also there is no properly working tile scan script for sands, caves and mountains in both English and Russian section unfortunally.
Here is Gauhar's script, for digging anything at your feet. There are a lot of information about any kinds of tiles and how to spot them.
Gauhar's script
PROGRAM TestMining;
CONST
tMinerTool = $0F39; //Чем копать (тип инструмента): $0F39 - Shovel. $0E86 - Pickaxe.

Procedure MiningHere();
Var
msgMine_WhereDig, msgMine_Sucs, msgMine_Fail, msgMine_NoMetal,
msgMine_FarAway, msgMine_CantThere, msgMine_CantThat, msgMine_Target,
msgMine_YouMoved, msgMine_PackFull, msgMine_WormTool, msgMine_Riding,
msgMine_Polymorphed, msgMine_ExtractStone, oreAndStone_DoubleHarvest,
sand_NoResources, sand_Fail, sand_Sucs, sand_PackFull,
msgMine_END, msgMine_ALL : String;
MountainTiles, SandTiles, CaveTiles: array of Word;
idMinerTool: Cardinal;
startTime: TDateTime;
MapCell: TMapCell;
StaticCell: TStaticCell;
T, X, Y: Word;
Z: ShortInt;
i, j, ix, iy: Integer;
isMountain: Boolean;
Begin
// СООБЩЕНИЯ ВО ВРЕМЯ ДОБЫЧИ РУДЫ:
msgMine_WhereDig := 'Where do you wish to dig?';
msgMine_Sucs := 'You dig some'; //You dig some ... ore and put it in your backpack.
msgMine_Fail := 'You loosen some rocks but fail to find any useable ore.';
msgMine_NoMetal := 'There is no metal here to mine.';
msgMine_FarAway := 'That is too far away.';
msgMine_CantThere := 'You can''t mine there.';
msgMine_CantThat := 'You can''t mine that.';
msgMine_Target := 'Target cannot be seen.';
msgMine_YouMoved := 'You have moved too far away to continue mining.';
msgMine_PackFull := 'Your backpack is full, so the ore you mined is lost.';
msgMine_WormTool := 'You have worn out your tool!';
msgMine_Riding := 'You can''t mine while riding.';
msgMine_Polymorphed := 'You can''t mine while polymorphed.';
msgMine_ExtractStone := 'You carefully extract some workable stone from the ore vein!';
oreAndStone_DoubleHarvest := 'Someone has gotten to the metal before you.';
sand_Fail := 'You dig for a while but fail to find any of sufficient quality for glassblowing.';
sand_Sucs := 'You carefully dig up sand of sufficient quality for glassblowing.';
sand_NoResources := 'There is no sand here to mine.';
sand_PackFull := 'Your backpack can''t hold the sand, and it is lost!';
// Сообщения при которых завершается добыча:
msgMine_END := msgMine_NoMetal + '|' + msgMine_FarAway + '|' +
msgMine_CantThere + '|' + msgMine_CantThat + '|' +
msgMine_Target + '|' + msgMine_YouMoved + '|' +
sand_NoResources + '|' + msgMine_PackFull + '|' + sand_PackFull;
// Все сообшения:
msgMine_ALL := msgMine_END + '|' + msgMine_Sucs + '|' + msgMine_Fail + '|' +
sand_Fail + '|' + sand_Sucs + '|' + msgMine_ExtractStone;

// ТАЙЛЫ В КОТОРЫХ МОЖНО ВЕСТИ ДОБЫЧУ (из исходников RunUO):
MountainTiles :=
[
220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 236, 237, 238,
239, 240, 241, 242, 243, 244, 245, 246, 247, 252, 253, 254, 255, 256, 257,
258, 259, 260, 261, 262, 263, 268, 269, 270, 271, 272, 273, 274, 275, 276,
277, 278, 279, 286, 287, 288, 289, 290, 291, 292, 293, 294, 296, 296, 297,
321, 322, 323, 324, 467, 468, 469, 470, 471, 472, 473, 474, 476, 477, 478,
479, 480, 481, 482, 483, 484, 485, 486, 487, 492, 493, 494, 495, 543, 544,
545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559,
560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574,
575, 576, 577, 578, 579, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590,
591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 610, 611, 612, 613,
1010, 1741, 1742, 1743, 1744, 1745, 1746, 1747, 1748, 1749, 1750, 1751,
1752, 1753, 1754, 1755, 1756, 1757, 1771, 1772, 1773, 1774, 1775, 1776,
1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788,
1789, 1790, 1801, 1802, 1803, 1804, 1805, 1806, 1807, 1808, 1809, 1811,
1812, 1813, 1814, 1815, 1816, 1817, 1818, 1819, 1820, 1821, 1822, 1823,
1824, 1831, 1832, 1833, 1834, 1835, 1836, 1837, 1838, 1839, 1840, 1841,
1842, 1843, 1844, 1845, 1846, 1847, 1848, 1849, 1850, 1851, 1852, 1853,
1854, 1861, 1862, 1863, 1864, 1865, 1866, 1867, 1868, 1869, 1870, 1871,
1872, 1873, 1874, 1875, 1876, 1877, 1878, 1879, 1880, 1881, 1882, 1883,
1884, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991,
1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
2004, 2028, 2029, 2030, 2031, 2032, 2033, 2100, 2101, 2102, 2103, 2104,
2105, 17723, 17724, 17725, 17726, 17727, 17728, 17729, 17730, 17731, 17732,
17733, 17734, 17735, 17736, 17737, 17738, 17739, 17740, 17741, 17742, 17743
];
SandTiles :=
[
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 68, 69, 70, 71, 72, 73, 74, 75,
286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300,
301, 402, 424, 425, 426, 427, 441, 442, 443, 444, 445, 446, 447, 448, 449,
450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464,
465, 642, 643, 644, 645, 650, 651, 652, 653, 654, 655, 656, 657, 821, 822,
823, 824, 825, 826, 827, 828, 833, 834, 835, 836, 845, 846, 847, 848, 849,
850, 851, 852, 857, 858, 859, 860, 951, 952, 953, 954, 955, 956, 957, 958,
967, 968, 969, 970,
1447, 1448, 1449, 1450, 1451, 1452, 1453, 1454, 1455, 1456, 1457, 1458, 1611,
1612, 1613, 1614, 1615, 1616, 1617, 1618, 1623, 1624, 1625, 1626, 1635, 1636,
1637, 1638, 1639, 1640, 1641, 1642, 1647, 1648, 1649, 1650
];
CaveTiles :=
[
1339, 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1348, 1349,
1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359
];
if TargetPresent then CancelTarget else CancelWaitTarget;
T := 0;
X := GetX(self);
Y := GetY(self);
Z := GetZ(self);
isMountain := TRUE;
// Ищим горы и кочки в радиусе 1 тайл:
for ix := (X - 1) to (X + 1) do
begin
for iy := (Y - 1) to (Y + 1) do
begin
MapCell := GetMapCell(ix, iy, WorldNum);
for i := 0 to (Length(MountainTiles) - 1) do
if (MapCell.Tile = MountainTiles) and (abs(Z - MapCell.Z) < 15) then
begin
AddToSystemJournal('-- MOUNTAIN --');
T := MapCell.Tile;
X := ix;
Y := iy;
Z := MapCell.Z;
BREAK;
end;
if T > 0 then BREAK;
end;
if T > 0 then BREAK;
end;
// Ищим под ногами песок:
if T = 0 then
begin
MapCell := GetMapCell(X, Y, WorldNum);
for i := 0 to (Length(SandTiles) - 1) do
if (MapCell.Tile = SandTiles) and (abs(Z - MapCell.Z) < 15) then
begin
AddToSystemJournal('-- SAND --');
isMountain := TRUE;
T := MapCell.Tile;
Z := MapCell.Z;
BREAK;
end;
end;
// Ищим под ногами пол шахты:
if T = 0 then
begin
isMountain := FALSE;
StaticCell := ReadStaticsXY(X, Y, WorldNum);
if StaticCell.StaticCount > 0 then
begin
for i := 0 to (StaticCell.StaticCount - 1) do
begin
for j := 0 to (Length(CaveTiles) - 1) do
begin
if StaticCell.Statics.Tile = CaveTiles[j] then
begin
AddToSystemJournal('---- CAVE ----');
T := StaticCell.Statics.Tile;
BREAK;
end;
end;
if T > 0 then BREAK;
end;
end;
end;
AddToSystemJournal('-- Tile = ' + IntToStr(T) + ' X = ' + IntToStr(ix) + ' Y = ' + IntToStr(iy) + ' Z = ' + IntToStr(Z));
if T = 0 then
begin
AddToSystemJournal('-- Здесь нельзя добывать.');
ClientPrint('ЗДЕСЬ НЕЛЬЗЯ ДОБЫВАТЬ.');
EXIT;
end;
repeat
idMinerTool := FindType(tMinerTool, Backpack);
if idMinerTool = $0 then
begin
AddToSystemJournal('-- Нет инструментов для добычи!');
ClientPrint('НЕТ ИСТРУМЕНТА ДЛЯ ДОБЫЧИ.');
EXIT;
end;
//if TargetPresent then CancelTarget else CancelWaitTarget;
Wait(100);
startTime := Now;
if isMountain = TRUE then
WaitTargetXYZ(X, Y, Z) //Горы, кочки и песок.
else
WaitTargetTile(T, X, Y, Z); //Шахта.
UseObject(idMinerTool);
repeat
wait(100);
until Dead or not Connected or (InJournalBetweenTimes(msgMine_ALL,startTime,Now) <> -1);
until Dead or not Connected or (InJournalBetweenTimes(msgMine_END,startTime,Now) <> -1);
End;

BEGIN
MiningHere();
END.


I know this one and this was the closest thing to I was searching for but it stops after first spot it finded consumes (till no ores left). Couldn't loop it for make it search for every spots in +2/-2 radius and dig.

PS: Also I sent him a private message about that problem of mine but he is not logging to forum for a while.

Так:

Code: Select all

PROGRAM TestMining;
CONST
   tMinerTool = $0F39;   //Чем копать (тип инструмента): $0F39 - Shovel. $0E86 - Pickaxe.

Procedure MiningHere();
Var
   msgMine_WhereDig, msgMine_Sucs, msgMine_Fail, msgMine_NoMetal,
    msgMine_FarAway, msgMine_CantThere, msgMine_CantThat, msgMine_Target,
     msgMine_YouMoved, msgMine_PackFull, msgMine_WormTool, msgMine_Riding,
      msgMine_Polymorphed, msgMine_ExtractStone, msgMine_DoubleHarvest,
       sand_NoResources, sand_Fail, sand_Sucs, sand_PackFull,
        msgMine_END, msgMine_ALL : String;
   MountainTiles, SandTiles, CaveTiles: array of Word;
   idMinerTool: Cardinal;
   startTime: TDateTime;
   MapCell: TMapCell;
   StaticCell: TStaticCell;
   T, X, Y: Word;
   Z: ShortInt;
   i, j, ix, iy: Integer;
   isMountain: Boolean;
Begin
   // СООБЩЕНИЯ ВО ВРЕМЯ ДОБЫЧИ РУДЫ:
   msgMine_WhereDig := 'Where do you wish to dig?';
   msgMine_Sucs      := 'You dig some';     //You dig some ... ore and put it in your backpack.
   msgMine_Fail      := 'You loosen some rocks but fail to find any useable ore.';
   msgMine_NoMetal   := 'There is no metal here to mine.';
   msgMine_FarAway   := 'That is too far away.';
   msgMine_CantThere := 'You can''t mine there.';
   msgMine_CantThat  := 'You can''t mine that.';
   msgMine_Target    := 'Target cannot be seen.';
   msgMine_YouMoved  := 'You have moved too far away to continue mining.';
   msgMine_PackFull  := 'Your backpack is full, so the ore you mined is lost.';
   msgMine_WormTool  := 'You have worn out your tool!';
   msgMine_Riding    := 'You can''t mine while riding.';
   msgMine_Polymorphed := 'You can''t mine while polymorphed.';
   msgMine_ExtractStone := 'You carefully extract some workable stone from the ore vein!';
   msgMine_DoubleHarvest := 'Someone has gotten to the metal before you.';
   sand_Fail        := 'You dig for a while but fail to find any of sufficient quality for glassblowing.';
   sand_Sucs        := 'You carefully dig up sand of sufficient quality for glassblowing.';
   sand_NoResources := 'There is no sand here to mine.';
   sand_PackFull    := 'Your backpack can''t hold the sand, and it is lost!';
   // Сообщения при которых завершается добыча:
   msgMine_END := msgMine_NoMetal  + '|' + msgMine_FarAway   + '|' +
                 msgMine_CantThere + '|' + msgMine_CantThat  + '|' +
                 msgMine_Target    + '|' + msgMine_YouMoved  + '|' +
                 sand_NoResources  + '|' +  msgMine_PackFull + '|' + sand_PackFull;
   // Все сообшения:
   msgMine_ALL := msgMine_END + '|' + msgMine_Sucs + '|' + msgMine_Fail + '|' +
                 sand_Fail + '|' + sand_Sucs + '|' + msgMine_ExtractStone + '|' +
                 msgMine_DoubleHarvest;

   // ТАЙЛЫ В КОТОРЫХ МОЖНО ВЕСТИ ДОБЫЧУ (из исходников RunUO):
   MountainTiles :=
   [
      220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 236, 237, 238,
      239, 240, 241, 242, 243, 244, 245, 246, 247, 252, 253, 254, 255, 256, 257,
      258, 259, 260, 261, 262, 263, 268, 269, 270, 271, 272, 273, 274, 275, 276,
      277, 278, 279, 286, 287, 288, 289, 290, 291, 292, 293, 294, 296, 296, 297,
      321, 322, 323, 324, 467, 468, 469, 470, 471, 472, 473, 474, 476, 477, 478,
      479, 480, 481, 482, 483, 484, 485, 486, 487, 492, 493, 494, 495, 543, 544,
      545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559,
      560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574,
      575, 576, 577, 578, 579, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590,
      591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 610, 611, 612, 613,
      1010, 1741, 1742, 1743, 1744, 1745, 1746, 1747, 1748, 1749, 1750, 1751,
      1752, 1753, 1754, 1755, 1756, 1757, 1771, 1772, 1773, 1774, 1775, 1776,
      1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788,
      1789, 1790, 1801, 1802, 1803, 1804, 1805, 1806, 1807, 1808, 1809, 1811,
      1812, 1813, 1814, 1815, 1816, 1817, 1818, 1819, 1820, 1821, 1822, 1823,
      1824, 1831, 1832, 1833, 1834, 1835, 1836, 1837, 1838, 1839, 1840, 1841,
      1842, 1843, 1844, 1845, 1846, 1847, 1848, 1849, 1850, 1851, 1852, 1853,
      1854, 1861, 1862, 1863, 1864, 1865, 1866, 1867, 1868, 1869, 1870, 1871,
      1872, 1873, 1874, 1875, 1876, 1877, 1878, 1879, 1880, 1881, 1882, 1883,
      1884, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991,
      1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
      2004, 2028, 2029, 2030, 2031, 2032, 2033, 2100, 2101, 2102, 2103, 2104,
      2105, 17723, 17724, 17725, 17726, 17727, 17728, 17729, 17730, 17731, 17732,
      17733, 17734, 17735, 17736, 17737, 17738, 17739, 17740, 17741, 17742, 17743
   ];
   SandTiles :=
   [
      22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
      41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
      60, 61, 62, 68, 69, 70, 71, 72, 73, 74, 75,
      286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300,
      301, 402, 424, 425, 426, 427, 441, 442, 443, 444, 445, 446, 447, 448, 449,
      450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464,
      465, 642, 643, 644, 645, 650, 651, 652, 653, 654, 655, 656, 657, 821, 822,
      823, 824, 825, 826, 827, 828, 833, 834, 835, 836, 845, 846, 847, 848, 849,
      850, 851, 852, 857, 858, 859, 860, 951, 952, 953, 954, 955, 956, 957, 958,
      967, 968, 969, 970,
      1447, 1448, 1449, 1450, 1451, 1452, 1453, 1454, 1455, 1456, 1457, 1458, 1611,
      1612, 1613, 1614, 1615, 1616, 1617, 1618, 1623, 1624, 1625, 1626, 1635, 1636,
      1637, 1638, 1639, 1640, 1641, 1642, 1647, 1648, 1649, 1650
   ];
   CaveTiles :=
   [
      1339, 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1348, 1349,
      1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359
   ];
   if TargetPresent then CancelTarget else CancelWaitTarget;
   for ix := (GetX(self) - 2) to (GetX(self) + 2) do
   begin
      for iy := (GetY(self) - 2) to (GetY(self) + 2) do
      begin
         T := 0;
         X := ix;
         Y := iy;
         Z := GetZ(self);
         isMountain := TRUE;
         // Ищим горы и кочки:
         MapCell := GetMapCell(ix, iy, WorldNum);
         for i := 0 to (Length(MountainTiles) - 1) do
         begin
            if (MapCell.Tile = MountainTiles[i]) and (abs(Z - MapCell.Z) < 15) then
            begin
               AddToSystemJournal('-- MOUNTAIN --');
               T := MapCell.Tile;
               Z := MapCell.Z;
               BREAK;
            end;
         end;
         // Ищим песок:
         if T = 0 then
         begin
            MapCell := GetMapCell(ix, iy, WorldNum);
            for i := 0 to (Length(SandTiles) - 1) do
            begin
               if (MapCell.Tile = SandTiles[i]) and (abs(Z - MapCell.Z) < 15) then
               begin
                  AddToSystemJournal('-- SAND --');
                  T := MapCell.Tile;
                  Z := MapCell.Z;
                  BREAK;
               end;
            end;
         end;
         // Ищим пол шахты:
         if T = 0 then
         begin
            isMountain := FALSE;
            StaticCell := ReadStaticsXY(ix, iy, WorldNum);
            if StaticCell.StaticCount > 0 then
            begin
               for i := 0 to (StaticCell.StaticCount - 1) do
               begin
                  for j := 0 to (Length(CaveTiles) - 1) do
                  begin
                     if StaticCell.Statics[i].Tile = CaveTiles[j] then
                     begin
                        AddToSystemJournal('-- CAVE --');
                        T := StaticCell.Statics[i].Tile;
                        Z := StaticCell.Statics[i].Z;
                        BREAK;
                     end;
                  end;
                  if T > 0 then BREAK;
               end;
            end;
         end;
         AddToSystemJournal('-- Tile = ' + IntToStr(T) + '  X = ' + IntToStr(ix) + '  Y = ' + IntToStr(iy) + '  Z = ' + IntToStr(Z));
         if T = 0 then
         begin
            AddToSystemJournal('-- Здесь нельзя добывать.');
            ClientPrint('ЗДЕСЬ НЕЛЬЗЯ ДОБЫВАТЬ.');
            CONTINUE;
         end;
         repeat
            idMinerTool := FindType(tMinerTool, Backpack);
            if idMinerTool = $0 then
            begin
               AddToSystemJournal('-- Нет инструментов для добычи!');
               ClientPrint('НЕТ ИСТРУМЕНТА ДЛЯ ДОБЫЧИ.');
               EXIT;
            end;
            //if TargetPresent then CancelTarget else CancelWaitTarget;
            Wait(100);
            startTime := Now;
            if isMountain = TRUE then
               WaitTargetXYZ(X, Y, Z)       //Горы, кочки и песок.
            else
               WaitTargetTile(T, X, Y, Z);  //Шахта.
            UseObject(idMinerTool);
            repeat
               wait(100);
            until Dead or not Connected or (InJournalBetweenTimes(msgMine_ALL,startTime,Now) <> -1);
         until Dead or not Connected or (InJournalBetweenTimes(msgMine_END,startTime,Now) <> -1);
      end;
   end;
End;

BEGIN
   MiningHere();
END.
Или так:

Code: Select all

PROGRAM TestMining;
CONST
   tMinerTool = $0F39;   //Чем копать (тип инструмента): $0F39 - Shovel. $0E86 - Pickaxe.
VAR
   x, y: Integer;

Procedure MiningHere(ix, iy: Integer);
Var
   msgMine_WhereDig, msgMine_Sucs, msgMine_Fail, msgMine_NoMetal,
    msgMine_FarAway, msgMine_CantThere, msgMine_CantThat, msgMine_Target,
     msgMine_YouMoved, msgMine_PackFull, msgMine_WormTool, msgMine_Riding,
      msgMine_Polymorphed, msgMine_ExtractStone, msgMine_DoubleHarvest,
       sand_NoResources, sand_Fail, sand_Sucs, sand_PackFull,
        msgMine_END, msgMine_ALL : String;
   MountainTiles, SandTiles, CaveTiles: array of Word;
   idMinerTool: Cardinal;
   startTime: TDateTime;
   MapCell: TMapCell;
   StaticCell: TStaticCell;
   T, X, Y: Word;
   Z: ShortInt;
   i, j: Integer;
   isMountain: Boolean;
Begin
   // СООБЩЕНИЯ ВО ВРЕМЯ ДОБЫЧИ РУДЫ:
   msgMine_WhereDig := 'Where do you wish to dig?';
   msgMine_Sucs      := 'You dig some';     //You dig some ... ore and put it in your backpack.
   msgMine_Fail      := 'You loosen some rocks but fail to find any useable ore.';
   msgMine_NoMetal   := 'There is no metal here to mine.';
   msgMine_FarAway   := 'That is too far away.';
   msgMine_CantThere := 'You can''t mine there.';
   msgMine_CantThat  := 'You can''t mine that.';
   msgMine_Target    := 'Target cannot be seen.';
   msgMine_YouMoved  := 'You have moved too far away to continue mining.';
   msgMine_PackFull  := 'Your backpack is full, so the ore you mined is lost.';
   msgMine_WormTool  := 'You have worn out your tool!';
   msgMine_Riding    := 'You can''t mine while riding.';
   msgMine_Polymorphed := 'You can''t mine while polymorphed.';
   msgMine_ExtractStone := 'You carefully extract some workable stone from the ore vein!';
   msgMine_DoubleHarvest := 'Someone has gotten to the metal before you.';
   sand_Fail        := 'You dig for a while but fail to find any of sufficient quality for glassblowing.';
   sand_Sucs        := 'You carefully dig up sand of sufficient quality for glassblowing.';
   sand_NoResources := 'There is no sand here to mine.';
   sand_PackFull    := 'Your backpack can''t hold the sand, and it is lost!';
   // Сообщения при которых завершается добыча:
   msgMine_END := msgMine_NoMetal  + '|' + msgMine_FarAway   + '|' +
                 msgMine_CantThere + '|' + msgMine_CantThat  + '|' +
                 msgMine_Target    + '|' + msgMine_YouMoved  + '|' +
                 sand_NoResources  + '|' +  msgMine_PackFull + '|' + sand_PackFull;
   // Все сообшения:
   msgMine_ALL := msgMine_END + '|' + msgMine_Sucs + '|' + msgMine_Fail + '|' +
                 sand_Fail + '|' + sand_Sucs + '|' + msgMine_ExtractStone + '|' +
                 msgMine_DoubleHarvest;

   // ТАЙЛЫ В КОТОРЫХ МОЖНО ВЕСТИ ДОБЫЧУ (из исходников RunUO):
   MountainTiles :=
   [
      220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 236, 237, 238,
      239, 240, 241, 242, 243, 244, 245, 246, 247, 252, 253, 254, 255, 256, 257,
      258, 259, 260, 261, 262, 263, 268, 269, 270, 271, 272, 273, 274, 275, 276,
      277, 278, 279, 286, 287, 288, 289, 290, 291, 292, 293, 294, 296, 296, 297,
      321, 322, 323, 324, 467, 468, 469, 470, 471, 472, 473, 474, 476, 477, 478,
      479, 480, 481, 482, 483, 484, 485, 486, 487, 492, 493, 494, 495, 543, 544,
      545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559,
      560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574,
      575, 576, 577, 578, 579, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590,
      591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 610, 611, 612, 613,
      1010, 1741, 1742, 1743, 1744, 1745, 1746, 1747, 1748, 1749, 1750, 1751,
      1752, 1753, 1754, 1755, 1756, 1757, 1771, 1772, 1773, 1774, 1775, 1776,
      1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788,
      1789, 1790, 1801, 1802, 1803, 1804, 1805, 1806, 1807, 1808, 1809, 1811,
      1812, 1813, 1814, 1815, 1816, 1817, 1818, 1819, 1820, 1821, 1822, 1823,
      1824, 1831, 1832, 1833, 1834, 1835, 1836, 1837, 1838, 1839, 1840, 1841,
      1842, 1843, 1844, 1845, 1846, 1847, 1848, 1849, 1850, 1851, 1852, 1853,
      1854, 1861, 1862, 1863, 1864, 1865, 1866, 1867, 1868, 1869, 1870, 1871,
      1872, 1873, 1874, 1875, 1876, 1877, 1878, 1879, 1880, 1881, 1882, 1883,
      1884, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991,
      1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
      2004, 2028, 2029, 2030, 2031, 2032, 2033, 2100, 2101, 2102, 2103, 2104,
      2105, 17723, 17724, 17725, 17726, 17727, 17728, 17729, 17730, 17731, 17732,
      17733, 17734, 17735, 17736, 17737, 17738, 17739, 17740, 17741, 17742, 17743
   ];
   SandTiles :=
   [
      22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
      41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
      60, 61, 62, 68, 69, 70, 71, 72, 73, 74, 75,
      286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300,
      301, 402, 424, 425, 426, 427, 441, 442, 443, 444, 445, 446, 447, 448, 449,
      450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464,
      465, 642, 643, 644, 645, 650, 651, 652, 653, 654, 655, 656, 657, 821, 822,
      823, 824, 825, 826, 827, 828, 833, 834, 835, 836, 845, 846, 847, 848, 849,
      850, 851, 852, 857, 858, 859, 860, 951, 952, 953, 954, 955, 956, 957, 958,
      967, 968, 969, 970,
      1447, 1448, 1449, 1450, 1451, 1452, 1453, 1454, 1455, 1456, 1457, 1458, 1611,
      1612, 1613, 1614, 1615, 1616, 1617, 1618, 1623, 1624, 1625, 1626, 1635, 1636,
      1637, 1638, 1639, 1640, 1641, 1642, 1647, 1648, 1649, 1650
   ];
   CaveTiles :=
   [
      1339, 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1348, 1349,
      1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359
   ];
   if TargetPresent then CancelTarget else CancelWaitTarget;
   T := 0;
   X := ix;
   Y := iy;
   Z := GetZ(self);
   isMountain := TRUE;
   // Ищим горы и кочки:
   MapCell := GetMapCell(ix, iy, WorldNum);
   for i := 0 to (Length(MountainTiles) - 1) do
   begin
      if (MapCell.Tile = MountainTiles[i]) and (abs(Z - MapCell.Z) < 15) then
      begin
         AddToSystemJournal('-- MOUNTAIN --');
         T := MapCell.Tile;
         Z := MapCell.Z;
         BREAK;
      end;
   end;
   // Ищим песок:
   if T = 0 then
   begin
      MapCell := GetMapCell(ix, iy, WorldNum);
      for i := 0 to (Length(SandTiles) - 1) do
      begin
         if (MapCell.Tile = SandTiles[i]) and (abs(Z - MapCell.Z) < 15) then
         begin
            AddToSystemJournal('-- SAND --');
            T := MapCell.Tile;
            Z := MapCell.Z;
            BREAK;
         end;
      end;
   end;
   // Ищим пол шахты:
   if T = 0 then
   begin
      isMountain := FALSE;
      StaticCell := ReadStaticsXY(ix, iy, WorldNum);
      if StaticCell.StaticCount > 0 then
      begin
         for i := 0 to (StaticCell.StaticCount - 1) do
         begin
            for j := 0 to (Length(CaveTiles) - 1) do
            begin
               if StaticCell.Statics[i].Tile = CaveTiles[j] then
               begin
                  AddToSystemJournal('-- CAVE --');
                  T := StaticCell.Statics[i].Tile;
                  Z := StaticCell.Statics[i].Z;
                  BREAK;
               end;
            end;
            if T > 0 then BREAK;
         end;
      end;
   end;
   AddToSystemJournal('-- Tile = ' + IntToStr(T) + '  X = ' + IntToStr(ix) + '  Y = ' + IntToStr(iy) + '  Z = ' + IntToStr(Z));
   if T = 0 then
   begin
      AddToSystemJournal('-- Здесь нельзя добывать.');
      ClientPrint('ЗДЕСЬ НЕЛЬЗЯ ДОБЫВАТЬ.');
      CONTINUE;
   end;
   repeat
      idMinerTool := FindType(tMinerTool, Backpack);
      if idMinerTool = $0 then
      begin
         AddToSystemJournal('-- Нет инструментов для добычи!');
         ClientPrint('НЕТ ИСТРУМЕНТА ДЛЯ ДОБЫЧИ.');
         EXIT;
      end;
      //if TargetPresent then CancelTarget else CancelWaitTarget;
      Wait(100);
      startTime := Now;
      if isMountain = TRUE then
         WaitTargetXYZ(X, Y, Z)       //Горы, кочки и песок.
      else
         WaitTargetTile(T, X, Y, Z);  //Шахта.
      UseObject(idMinerTool);
      repeat
         wait(100);
      until Dead or not Connected or (InJournalBetweenTimes(msgMine_ALL,startTime,Now) <> -1);
   until Dead or not Connected or (InJournalBetweenTimes(msgMine_END,startTime,Now) <> -1);
End;

BEGIN
   for x := (GetX(self) - 2) to (GetX(self) + 2) do
      for y := (GetY(self) - 2) to (GetY(self) + 2) do
         MiningHere(x, y);
END.
DeadLy_DeMaGe
Neophyte
Neophyte
Posts: 17
Joined: 10.01.2015 3:01

Re: Using External Files

Post by DeadLy_DeMaGe »

First script you posted (Так:) looks like working for me. My script working now (ish). I need to make some improvements ofcourse but thank you all for your kindness and help.
Post Reply