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

Help using script.

Ask for help
Post Reply
Kheelt
Neophyte
Neophyte
Posts: 10
Joined: 15.04.2014 0:41

Help using script.

Post by Kheelt »

.
Last edited by Kheelt on 28.04.2014 21:19, edited 2 times in total.
drabadan
Expert
Expert
Posts: 730
Joined: 13.12.2012 17:35
Contact:

Re: Help using script.

Post by drabadan »

Kheelt wrote:Hi there, im new and introduced to scripting, and i would appreciate any help.
The first error i get whit this mining script is, it recalls but when it becames to mine it just keep recalling.
so Recalls > find spot > Use shovel > Where do you wish to dig? > target sending from stealth > and loop.

I tryed changing the target settings from steal to ON/off but didn't change anything.

thanks!
Heres the code:
Your script

Code: Select all

program Mining;

const
IngotsStorage=$52908DA7;
IngotsType=$1BF2;

HomeRuneBook=$4298472C;
HomeRuneIndex=0;
RuneBookShift=5;

MiningType=$0F39;
TinkerType=$1EB8;
TKNumFirst=8;
TKNumSecond=23;
TKMinerNumFirst=8;
TKMinerNumSecond=72;

IronColor=$0000;
IronCount=40;

WaitTime=500;
RecalTime=2000;
WaitCycles=7;
LagWait=10000;

var
CurrentRune:Byte;
CurrentBook,MiningTool,TinkerTool:Integer;
GemTypes,OreTypes,Killers:array of Word;
RuneBooks:array of Cardinal;
cTime,cTime2:TDateTime;

procedure EventMinerGump(Serial, GumpID, X, Y: Cardinal);
begin
  if NumGumpButton(GetGumpsCount-1, TKMinerNumSecond) then Exit;
  if NumGumpButton(GetGumpsCount-1, TKMinerNumFirst) then Exit;
  CloseSimpleGump(GetGumpsCount-1);
end;

procedure EventTinkerGump(Serial, GumpID, X, Y: Cardinal);
begin
  if NumGumpButton(GetGumpsCount-1, TKNumSecond) then Exit;
  if NumGumpButton(GetGumpsCount-1, TKNumFirst) then Exit;
  CloseSimpleGump(GetGumpsCount-1);
end;

function CheckMiningTool: Boolean;
begin
  CheckLag(LagWait);
  FindType(MiningType, Backpack);
  if GetType(MiningTool) <> MiningType then MiningTool := FindItem;
  Result := FindCount > 0;
end;

function CheckTinkerTool: Boolean;
begin
  CheckLag(LagWait);
  FindType(TinkerType, Backpack);
  if GetType(TinkerTool) <> TinkerType then TinkerTool := FindItem;
  Result := FindCount > 1;
end;

procedure CreateTKTools;
var
Counter: Cardinal;
begin
  SetEventProc(evIncomingGump, 'EventTinkerGump');
  UseObject(TinkerTool);
  Counter := 0;
  while True do begin
    if (Dead)
    or (not Connected)
    or (CheckTinkerTool) then begin
      SetEventProc(evIncomingGump, '');
      Break;
    end
    else Wait(1000);
    Inc(Counter);
    if Counter > WaitCycles then begin
      SetEventProc(evIncomingGump, '');
      Break;
    end;
  end;
end;

function CreateMiningTools: Boolean;
var
Counter: Cardinal;
begin
  SetEventProc(evIncomingGump, 'EventMinerGump');
  if not CheckTinkerTool then begin
    CreateTKTools;
  end;
  UseObject(TinkerTool);
  Counter := 0;
  while True do begin
    if (Dead)
    or (not Connected)
    or (CheckMiningTool) then Break;
    Inc(Counter);
    if Counter > WaitCycles then Break;
    Wait(1000);
  end;
  SetEventProc(evIncomingGump, '');
  CloseSimpleGump(GetGumpsCount-1);
  Result := CheckMiningTool;
end;

procedure Move(Item:Array of Word);
var
j:Byte;
begin
  CheckLag(LagWait);
  CheckLag(LagWait);
  for j := 0 to Length(Item)-1 do begin
    if Dead or not Connected then Exit;
    CheckLag(LagWait);
    While (FindType(Item[j], Backpack)>1) do begin
      if Dead or not Connected then Exit;
      CheckLag(LagWait);
      Wait(WaitTime);
      MoveItem(Finditem, GetQuantity(Finditem), IngotsStorage, 0, 0, 0);
    end;
  end;
end;

procedure TakeIngots;
var
Count,CountBox:Word;
begin
  FindTypeEx(IngotsType,IronColor,Backpack,false);
  Count:=FindQuantity;
  if Count<IronCount then begin
    CheckLag(LagWait);
    Wait(WaitTime);
    UseObject(IngotsStorage);
    Wait(WaitTime*4);
    CheckLag(LagWait);
    CountBox:=GetQuantity(FindTypeEx(IngotsType,IronColor,IngotsStorage,false));
    if CountBox < IronCount then begin
      Disconnect;
      Halt;
    end;
    Grab(finditem,(IronCount-Count));
  end;
end;

function RecallRune(RuneBook: Cardinal; Rune: Byte):Boolean;
var
  Counter: Byte;
  X, Y: Word;
begin
  Result := False;
  X := GetX(Self);
  Y := GetY(Self);
  CheckLag(LagWait);
  Wait(WaitTime);
  while Isgump do CloseSimpleGump(0);
  if Dead or not Connected then Exit;
  UseObject(RuneBook);
  CheckLag(LagWait);
  Counter := WaitCycles;
  while Counter > 0 do begin
    if IsGump then Break;
    Wait(WaitTime);
    CheckLag(LagWait);
    Inc(Counter);
  end;
  if IsGump then begin
    if NumGumpButton(0, Rune * 6 + RuneBookShift) then begin
      CheckLag(LagWait);
      Wait(RecalTime);
      CheckLag(LagWait);
      Result := (X <> GetX(Self)) or (Y <> GetY(Self));
    end else Result := False;
  end else Result := False;
end;

function GoBase: Boolean;
begin
  Result:=RecallRune(HomeRuneBook, HomeRuneIndex);
end;

function NextRune: Boolean;
var
Counter:Cardinal;
begin
  if CurrentRune > 15 then begin
    CurrentRune := 0
    Inc(CurrentBook);
    if CurrentBook >= Length(RuneBooks) then CurrentBook := 0;
  end;
  for Counter := 0 to WaitCycles do begin
    if Dead or not Connected then Exit;
    Result := RecallRune(RuneBooks[CurrentBook], CurrentRune);
    if Result then Break;
    Result := RecallRune(RuneBooks[CurrentBook], CurrentRune);
    if Result then Break;
    GoBase;
    Wait(10000);
  end;
end;

procedure CheckState;
begin
  if MaxWeight < Weight + 60 then begin
    while True do begin
      if Dead or not Connected then Exit;
      if GoBase() then Break;
      if not RecallRune(RuneBooks[CurrentBook], CurrentRune) then Wait(10000);
    end;
    Move(OreTypes);
    Move(GemTypes);
    TakeIngots;
    while True do begin
      if Dead or not Connected then Exit;
      if RecallRune(RuneBooks[CurrentBook], CurrentRune) then Break;
      if GoBase() then Continue;
      if not NextRune then Wait(10000);
    end;
  end;
end;

function CheckPK: boolean;
var
i,q:integer;
begin
  FindDistance:=25;
  for q:=0 to high(Killers) do
  for i:=3 to 6 do
  if FindNotoriety(Killers[q],i)>0 then begin
    Result:=True;
    AddToSystemJournal('?????? ?????? ???? - ' + GetName(FindItem));
    AddToSystemJournal('Runebook # '+IntToStr(CurrentBook+1));
    AddToSystemJournal('Rune # '+IntToStr(CurrentRune+1));
    FindDistance:=2;
    Exit;
  end;
  FindDistance:=2;
end;
procedure Mine(X, Y: Integer);
var
Tile:Word;
Z:ShortInt;
Counter:Byte;
StartTime:TDateTime;
begin
  CheckState;
  While IsGump do CloseSimpleGump(GetGumpsCount-1);
  while True do begin
    if Dead or not Connected then Exit;
    if TargetPresent then CancelTarget;
    CheckLag(LagWait);
    Wait(WaitTime);
    while not CheckMiningTool do begin
      if Dead or not Connected then Exit;
      CreateMiningTools;
      While IsGump do CloseSimpleGump(GetGumpsCount-1);
    end;
    UseObject(MiningTool);
    CheckLag(LagWait);
    WaitForTarget(LagWait);
    if TargetPresent then begin
      StartTime := Now;
      TargetToTile(Tile, X, Y, Z);
      Counter:=WaitCycles;
      CheckLag(LagWait);
      if InJournalBetweenTimes('t mine there|is too far away|cannot be seen|is no metal here to mine', StartTime, Now) > 0 then
      Exit;
      Wait(200);
      Dec(Counter);
      CheckState;
      if CheckPK then begin
        cTime:=Now-0.00008;
        GoBase;
        Inc(CurrentRune);
        Wait(WaitTime*100);
        RecallRune(RuneBooks[CurrentBook], CurrentRune);
        CheckLag(LagWait);
        Wait(WaitTime);
      end;
    end;
  end;
end;
procedure MinePoint;
var
X, Y: Word;
begin
  X:=GetX(Self);
  Y:=GetY(Self);
  Mine(X,Y);
  Inc(CurrentRune);
end;

begin
 // AddGumpIgnoreByID(4063159494);
  Ignore(Self); //Added by me(Drabadan)
  SetEventProc(evIncomingGump, '');
  if not Connected() then begin
    Connect();
    Wait(10000);
  end;
  While IsGump do CloseSimpleGump(GetGumpsCount-1);
  cTime:=Now;
  RuneBooks:=[$4389CA6B,$4298472C];
  OreTypes:=[$19B7,$19B8,$19B9,$19BA];
  GemTypes:=[$3192,$3193,$3194,$3195,$3197,$3198,$40068717];
  Killers:=[$0190,$0191,$025E,$025D];
  CurrentBook:=0;
  CurrentRune:=0;
  while True do begin
    if Dead then begin
      AddToSystemJournal('You Dead.');
      AddToSystemJournal('Runebook # '+IntToStr(CurrentBook+1));
      AddToSystemJournal('Rune # '+IntToStr(CurrentRune+1));
      Halt;
    end;
    if not Connected then begin
      Connect;
      Wait(10000);
      Continue;
    end;
    NextRune;
    MinePoint;
  end;
end.
hi there, it's 1 AM at my place... But for a first look i'd say that you are not ignoring your character at PK loops, so i added 1 line of code.
Second look will be tomorrow at work!
Good night!
Kheelt
Neophyte
Neophyte
Posts: 10
Joined: 15.04.2014 0:41

Re: Help using script.

Post by Kheelt »

same here bud, thanks for your fast apply. i'll try tomorrow too.

I just want to mention that in my shard u can make shovels with 50k+ uses so i dont even need to make them (so we can short some code)

See you tomorrow, and thanks again!
Kheelt
Neophyte
Neophyte
Posts: 10
Joined: 15.04.2014 0:41

Re: Help using script.

Post by Kheelt »

Quick Updates:

I forced to delete some parts of the script in order to get it work, so it works fine for the facts i do (just recall mine, come back, drop, loop)
I remove the House runebook from Runebook's array, still working fine and i think the error i had about unstuck was for that.

Facts to improve:

- Move the gems to another Box.
- Make the runebooks recognice by their name as (BASE) (ORE) in order to don't need a setup of ID.
- Make a gump window to see the stat's of quantity.
- Add custom gem from my server (Already done by the array of gems, but want to separe it from in order to get the Ratio% of drops per hour.)
drabadan
Expert
Expert
Posts: 730
Joined: 13.12.2012 17:35
Contact:

Re: Help using script.

Post by drabadan »

Kheelt wrote:Quick Updates:
Facts to improve:

- Move the gems to another Box.
- Make the runebooks recognice by their name as (BASE) (ORE) in order to don't need a setup of ID.
- Make a gump window to see the stat's of quantity.
- Add custom gem from my server (Already done by the array of gems, but want to separe it from in order to get the Ratio% of drops per hour.)
Make gump - that's something above of the Stealth's possibilities;
If you want some GUI - that's all about external scripts;
To make the runebooks recognization - just make a custom object type which will describe all the properties you need!
Make ratio counter - not a problem at all, but to fill the statistics correctly, i think - you'd better write statistics to outer file like .ini to get all time sessions analysis.

If you need any help - you where to ask a questions!
Btw you can ask me at ICQ, it's in my contacts list, at my profile page.
Kheelt
Neophyte
Neophyte
Posts: 10
Joined: 15.04.2014 0:41

Re: Help using script.

Post by Kheelt »

drabadan wrote:
Kheelt wrote:Quick Updates:
Facts to improve:

- Move the gems to another Box.
- Make the runebooks recognice by their name as (BASE) (ORE) in order to don't need a setup of ID.
- Make a gump window to see the stat's of quantity.
- Add custom gem from my server (Already done by the array of gems, but want to separe it from in order to get the Ratio% of drops per hour.)
Make gump - that's something above of the Stealth's possibilities;
If you want some GUI - that's all about external scripts;
To make the runebooks recognization - just make a custom object type which will describe all the properties you need!
Make ratio counter - not a problem at all, but to fill the statistics correctly, i think - you'd better write statistics to outer file like .ini to get all time sessions analysis.

If you need any help - you where to ask a questions!
Btw you can ask me at ICQ, it's in my contacts list, at my profile page.
Yea with gump i mention GUI (my bad)
Can u throw me a bone on how to make the runebook recognization with i've list (ORE & BASE)
Ratio should be fine to implement into GUI.

I maked a ICQ and added you already, i got some questions, hehe.
drabadan
Expert
Expert
Posts: 730
Joined: 13.12.2012 17:35
Contact:

Re: Help using script.

Post by drabadan »

Can you explain why you need to set it up from it's name? Becouse it won't be as secure as it would be done by ID.
Here is the example on how to make it both:

Code: Select all

program MyCustomItem;

const
 Item = $0000001; //Item id;
 
//declaration of a new type with custom options; 
type
 TMyCustomItem = record
  Id : Cardinal;
  Name : String;
  _Type : Word;
end;

//You need to store your values in variable, to have an access, 
//becouse declaration of a type is not getting any memory for it,
//you need to specify it with variable or Array element;
var
 MyCustomItem : TMyCustomItem;
 
begin
 //Here how we fill this new type of items with our values;
 MyCustomItem.Id := Item;
 MyCustomItem.Name := GetName(Item);
 MyCustomItem._Type := GetType(Item);
 //Here how we can call any of our item's option;
 AddToSystemJournal(MyCustomItem.Name); 
end.
If you mented smth else so describe more wider about and we will find a solution!
Crome696
Novice
Novice
Posts: 67
Joined: 04.03.2012 18:57
Location: Germany
Contact:

Re: Help using script.

Post by Crome696 »

Yea with gump i mention GUI (my bad)
Can u throw me a bone on how to make the runebook recognization with i've list (ORE & BASE)
Ratio should be fine to implement into GUI.

I maked a ICQ and added you already, i got some questions, hehe.
1) GUI not possible with Stealth 6.x and Pascal Script. This must be solved via API.
2) Recognizing could be done by BMSearch. If you have Runuo Default Ores keep sure to check for "dull" instead of "dull copper".
Sample :

Code: Select all

If(BMSearch(0,'My Dull Copper Runebook','Dull')>0)then AddToSystemJournal('Yey its my Dullcopper Runebook!');
I used to made a function years ago like

Code: Select all

Function Contains(S1,S2:String;CaseSensitive:Boolean):Boolean;
var 
 SX1 : String;
 SX2 : String;
begin
if ( not CaseSensitive) then
begin
 SX1 := LowerCase(S1);
 SX2 := LowerCase(S2);
end else begin
 SX1 := S1;
 SX2 := S2;
end;
Result := (BMSearch(0,SX1,SX2)>0);
end;
and then just do

Code: Select all

if Contains('My Dull Copper Runebook','Dull',False)then AddToSystemJournal('Yey its my Dullcopper Runebook!');
3) If you dont mind you could also add the Data by using FillInfoWindow or utilize inifiles as draraban said.


Hope i could help you..
Stealth Development Team & Support
Crome696
Novice
Novice
Posts: 67
Joined: 04.03.2012 18:57
Location: Germany
Contact:

Re: Help using script.

Post by Crome696 »

drabadan wrote:Can you explain why you need to set it up from it's name? Becouse it won't be as secure as it would be done by ID.
In Order to dynamicly load the Books. I dont know wich shard the author plays but EA and many shards nowadays have complete random spots, there it isnt required to filter books.
Old scripts in easyuo used something like "Ore XX" where Ore decated its a mining book and XX the amount of Runes from 1 - X to be useful.
So you could just drop books into any backpack, name them Ore and Script recognize them as useful for mining.

If the Author want to go the same way, i would add some delimeters like "Ore | 16" or "Ore # 16".
In case you want to filter out you just scan for your delimeter, if not exist its an unrelevant book. If it exist you could use strbreakapart to break the string into an array of String ( 0 = Name , 1 = Value).
Then you could write a simple Parser to fill an object information depending on your information.
Stealth Development Team & Support
Kheelt
Neophyte
Neophyte
Posts: 10
Joined: 15.04.2014 0:41

Re: Help using script.

Post by Kheelt »

The reason for use names by runebooks it's just for simply comfort, i mean, it's faster to the script for someone that dosn't have to seetup things like ID's.

So i hopefully can do it with the runebooks and with the containers. :D Thanks for all the help i really aprecciate it.

also want to mention one thing, i just have 2 scripts atm for mine in normal caves and another for Abyss mining, let's put some code.


I use this procedure "mining" for mine in the abyss.
Procedure Mining Abyss

Code: Select all

procedure Mine(X, Y: Integer);
var
Tile:Word;
Z:ShortInt;
Counter:Byte;
StartTime:TDateTime;
begin
  CheckState;
  While IsGump do CloseSimpleGump(GetGumpsCount-1);
  while True do begin
    if Dead or not Connected then Exit;
    if TargetPresent then CancelTarget;
    CheckLag(LagWait);
    Wait(WaitTime);
    while not CheckMiningTool do begin
      if Dead or not Connected then Exit;
      CreateMiningTools;
      While IsGump do CloseSimpleGump(GetGumpsCount-1);
    end;
    UseObject(MiningTool);
    CheckLag(LagWait);
    WaitForTarget(LagWait);
    if TargetPresent then begin
      StartTime := Now;
      TargetToTile(Tile, X, Y, Z);
      Counter:=WaitCycles;
      CheckLag(LagWait);
      if InJournalBetweenTimes('t mine there|is too far away|cannot be seen|is no metal here to mine', StartTime, Now) > 0 then
      Exit;
      Wait(200);
      Dec(Counter);
      CheckState;
      if CheckPK then begin
        cTime:=Now-0.00008;
        GoBase;
        Inc(CurrentRune);
        Wait(WaitTime*100);
        RecallRune(RuneBooks[CurrentBook], CurrentRune);
        CheckLag(LagWait);
        Wait(WaitTime);
      end;
    end;
  end;
end;

procedure MinePoint;
var
X, Y: Word;
begin
  X:=GetX(Self);
  Y:=GetY(Self);
  Mine(X,Y);
  Inc(CurrentRune);
end;
And this one for the normal caves <mountains>
Normal caves procedure.

Code: Select all

procedure Mine(X, Y: Integer);
var
  StaticData: TStaticCell;
  Tile: Word;
  Z: ShortInt;
  Finded: Boolean;
  Counter: Byte;
  StartTime: TDateTime;
  i: Integer;
begin
  Finded := False;
  StaticData := ReadStaticsXY(X, Y, WorldNum);
  for i := 0 to StaticData.StaticCount - 1 do begin
    if i >= StaticData.StaticCount then Break;
    if (GetTileFlags(2, StaticData.Statics[i].Tile) and $200) = $200 then begin
      Tile := StaticData.Statics[i].Tile;
      Z := StaticData.Statics[i].Z;
      Finded := True;
      Break;
    end; 
  end;
  
  CheckState; 
  while Finded do begin
    if Dead or not Connected then Exit;
    if TargetPresent then CancelTarget;
    while not CheckMiningTool do begin
      if Dead or not Connected then Exit;
      CreateMiningTools;
    end;
    UseObject(MiningTool);
    CheckLag(LagWait);
    WaitForTarget(WaitTime);
    if TargetPresent then begin
      StartTime := Now;
      TargetToTile(Tile, X, Y, Z);
      Counter := WaitCycles;
      Finded := False;
      while (not Finded) and (Counter > 0) do begin
      
        if InJournalBetweenTimes('t mine there|is too far away|cannot be seen|is no metal here to mine', StartTime, Now) > 0 then Exit;
        if InJournalBetweenTimes('put it in your backpack|loosen some rocks but fail to find any useable ore|have worn out your tool', StartTime, Now) > 0 then Finded := True;
        if Not Finded then Wait(200);
        Dec(Counter);
        if CheckPK then begin
        cTime:=Now-0.00008;
        GoBase;
        Inc(CurrentRune);
        Wait(WaitTime*100);
        RecallRune(RuneBooks[CurrentBook], CurrentRune);
        CheckLag(LagWait);
        Wait(WaitTime);
      end;
      end;
      CheckState();
    end;
  end;    
end;
I may not see the difference but i can't mine with the second in the abyss because it read statics? i don't understand.
Post Reply