Page 1 of 2 12 LastLast
Results 1 to 25 of 37

Thread: Tracking a NPC in Reflection

  1. #1
    Join Date
    Apr 2007
    Location
    Colchester, UK
    Posts
    1,220
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Tracking a NPC in Reflection

    Hi,

    i am trying to work on a way to track a specific NPC until its dead for my Ratinator script.

    I have made some progress but i need help to polish this off a bit.

    the way i am doing it, or shall we say trying to do it is using the Index of the NPC to track it.

    for most part is works fine but occasionally it will kill the rat but keep thinking its alive, i am not sure why, its possible at that point a new rat has spawned with the same Index but i would love some help with this.

    This is my check to see if the rat index is found against the current rats on screen.
    Simba Code:
    Function FastFighting:Boolean;   //using this now to check that we are attacking rat, no false positives (hopefully)
    var
    i:integer;
    Char : TNPCArray;
    mx, my, Colour, Shadow:integer;
    ratBMP, TotalBMP:TMufasaBitmap;
    Canvas: TCanvas;
    ratBox:TBox;
    ratpoint:TPoint;
    Foundit:Boolean;
    begin
      Write('Checking for Fight');
      ratBox.X1 := 0;
      ratBox.Y1 := 0;
      ratBox.X2 := 8;
      ratBox.Y2 := 8;

      Foundit:= false;

      if Players[CurrentPlayer].Booleans[0] then
      begin
        repeat
          Char := (SortNPCS(GetNPCS('Giant rat')));  //gets all rats
          if(Length(Char) = 0)then
            Exit;



      {if TileOnMS(rattile, 0) then  //used to draw on smart.
      begin

          SmartSetDebug(True);
      GetClientDimensions(mx,my);

      Colour := 225;      //change color of text
      Shadow := 65536;
      ratBMP := TMufasaBitmap.create;
      ratBMP.SetSize(mx,my);
      ratBMP.FastDrawClear(clBlack);

      ratBMP.Rectangle( ratBox, Colour);

      Canvas := TCANVAS.Create;
      Canvas.Handle := SmartGetDebugDC;
      TotalBMP := TMufasaBitmap.create;
      TotalBMP.SetSize(mx,my);


      ratpoint:= tiletoms(rattile, 0);


      //writeln('rat location is x: '+inttostr(ratpoint.x)+ ' y :'+inttostr(ratpoint.y));

      ratBMP.FastDrawTransparent( ratpoint.x ,ratpoint.y , TotalBMP);

      ratBMP.SetTransparentColor(clBlack);
      TotalBMP.DrawToCanvas(0 ,0, Canvas);

      ratBMP.Free;
      TotalBMP.Free;

      end;     }




          //Writeln('looking for '+inttostr(Rat)+' in array');

          for i := 0 to High(Char) do   //loops through all rats found
          begin

            //writeln('currently in array is ' +inttostr(char[i].Index));
            if (Rat = Char[i].Index) then //checks rat index from attack function to ones in current array
            begin
              Writeln('Rat Index found rat coould still be alive');
              Result:= True;
              Break;
            end;

            if (I = High(Char)) then
            begin
              Write('looped through all rats, exiting');
              Result:= False
              Wait(800+Random(1000));
            end;
          end;
          //writeln('');

          Wait(500+Random(500));
        until( not Result)
      end;
    end;

    I get my initial Rat Index from my attack function when i click it.

    what do you think? am i being stupid and this would not work?

  2. #2
    Join Date
    Dec 2010
    Posts
    431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Just check if you're interacting with the rat. Interaction stops on death.

  3. #3
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Won't work. Better idea: AreWeInteracting(var NPC: TNPC): Boolean; I created it specifically for this purpose. It gets the npc that is interacting with you.

  4. #4
    Join Date
    Apr 2007
    Location
    Colchester, UK
    Posts
    1,220
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ok, brilliant will use that.

    can anyone shed some more light on why my way wont work, it just means i will understand it all better

  5. #5
    Join Date
    Dec 2010
    Posts
    431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I wouldn't know if yours works or not... but wont the index just be replaced after the rat dies?

  6. #6
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Quote Originally Posted by Train View Post
    I wouldn't know if yours works or not... but wont the index just be replaced after the rat dies?
    As soon as a new npc is spawned. NPCs are stored by a node just like everything else pretty much.
    Last edited by mormonman; 02-18-2011 at 08:49 PM.

  7. #7
    Join Date
    Apr 2007
    Location
    Colchester, UK
    Posts
    1,220
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ok i see.

    thanks for the explanation

  8. #8
    Join Date
    Dec 2010
    Posts
    431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by mormonman View Post
    As soon as a new npc is spawned. NPCs are stored by a node just like everything else pretty much.
    That's what I meant. So if in a chance one spawned as soon as yours died, it would return that it's still fighting.

  9. #9
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Can you get health of the rat you are tracking?

  10. #10
    Join Date
    Dec 2010
    Posts
    431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Boreas View Post
    Can you get health of the rat you are tracking?
    yes

  11. #11
    Join Date
    Sep 2006
    Location
    Canada
    Posts
    1,124
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    The Index randomly changes every 8-20~ seconds or so.



  12. #12
    Join Date
    Oct 2008
    Posts
    500
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Train View Post
    yes
    Have you used this personally? It keeps returning 0 for me.

  13. #13
    Join Date
    Sep 2007
    Location
    Michigan
    Posts
    3,862
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by kitchenrange View Post
    Have you used this personally? It keeps returning 0 for me.
    Iirc it actually returns the % its at, also it won't show unless the npcs hp bar is up. Unless there has been a recent hook added to know the current hp.
    (Scripts outdated until I update for new SRL changes)
    AK Smelter & Crafter [SRL-Stats] - Fast Fighter [TUT] [SRL-Stats]
    If you PM me with a stupid question or one listed in FAQ I will NOT respond. -Narcle
    Summer = me busy, won't be around much.

  14. #14
    Join Date
    Oct 2008
    Posts
    500
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    I'm talking about the percentage. NPC.HPRatio.

    But, I've set up a script just to debug the HPRatio of the NPC interacting with me and after manually attacking the NPC's, nothing was debugged besides a a value of 0.

  15. #15
    Join Date
    Sep 2006
    Location
    Canada
    Posts
    1,124
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    Quote Originally Posted by kitchenrange View Post
    I'm talking about the percentage. NPC.HPRatio.

    But, I've set up a script just to debug the HPRatio of the NPC interacting with me and after manually attacking the NPC's, nothing was debugged besides a a value of 0.
    You have to "update" the variables.

    It's kinda like when they move. If you have an array of 10 NPCs and one moves, your mouse will move to the tile were they where when you grabbed them all.

    There really isn't any reason to care about any of that nonsense when AreWeInteracting is perfect for any sort of combat purposes.

    AreWeInteracting(NPC)
    Writeln(NPC.HPRatio)

    Loop that and you will see that it works.



  16. #16
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Simba Code:
    function m_InFight: boolean;
    var
      NPC: TNPC;
    begin
      Result := False;
      if AreWeInteracting(NPC) then
        Result := NPC.Fighting and (NPC.HPRatio > 0);
    end;

  17. #17
    Join Date
    Sep 2006
    Location
    Canada
    Posts
    1,124
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    Quote Originally Posted by mormonman View Post
    Simba Code:
    function m_InFight: boolean;
    var
      NPC: TNPC;
    begin
      Result := False;
      if AreWeInteracting(NPC) then
        Result := NPC.Fighting and (NPC.HPRatio > 0);
    end;
    See now this is a waste, because if the NPC is dead you're not interacting.



  18. #18
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Quote Originally Posted by Capricorn View Post
    See now this is a waste, because if the NPC is dead you're not interacting.
    And if the NPS is dead, you're not fighting it either

  19. #19
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Quote Originally Posted by Capricorn View Post
    See now this is a waste, because if the NPC is dead you're not interacting.
    No because while the NPC is dying it still exists, so you check for the hp bar(NPC.Fighting) and then check its percentage.

  20. #20
    Join Date
    Oct 2008
    Posts
    500
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    procedure WaitForFight;
    var
      Me : TMe;
      i  : integer;
    begin
      Flag;
      Wait(RandomRange(200,300));
      for i := 0 to 10 do
      begin
        WriteLN('waiting');
        if loggedin = false then LoginPlayer;
        ClickContinue(True, False);
        Wait(5);
        Me := GetMe;
        inc(i);
        if Me.Interacting > 0 then i := 0;
      end;
    end;


    This is the shit.

  21. #21
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Quote Originally Posted by kitchenrange View Post
    SCAR Code:
    procedure WaitForFight;
    var
      Me : TMe;
      i  : integer;
    begin
      Flag;
      Wait(RandomRange(200,300));
      for i := 0 to 10 do
      begin
        WriteLN('waiting');
        if loggedin = false then LoginPlayer;
        ClickContinue(True, False);
        Wait(5);
        Me := GetMe;
        inc(i);
        if Me.Interacting > 0 then i := 0;
      end;
    end;


    This is the shit.
    You will still be "Interacting" when the NPC is doing the dying animation. Thus making yours slower.

  22. #22
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    I had this:
    SCAR Code:
    //These were -global- vars:
    //_NPCWeAreFighting, NPCWeWereFighting : TNPC;
    //used like:
    //AreWeInteracting(_NPCWeAreFighting);
    //when a rock crab attacked

    Function NPCWeAreFighting: Boolean;
    Begin
      If Not LoggedIn Then
        Exit;
      _Status('NPCWeAreFighting');
      AreWeInteracting(NPCWeWereFighting);
      Result := (_NPCWeAreFighting.Index <> NPCWeWereFighting.Index);
    End;

    It might not work at all because Rock Crabs are agressive or this is simply wrong code
    Ce ne sont que des gueux


  23. #23
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Quote Originally Posted by Floor66 View Post
    I had this:
    SCAR Code:
    //These were -global- vars:
    //_NPCWeAreFighting, NPCWeWereFighting : TNPC;
    //used like:
    //AreWeInteracting(_NPCWeAreFighting);
    //when a rock crab attacked

    Function NPCWeAreFighting: Boolean;
    Begin
      If Not LoggedIn Then
        Exit;
      _Status('NPCWeAreFighting');
      AreWeInteracting(NPCWeWereFighting);
      Result := (_NPCWeAreFighting.Index <> NPCWeWereFighting.Index);
    End;

    It might not work at all because Rock Crabs are agressive or this is simply wrong code
    NPC indices are not handled like they were when you made this.

  24. #24
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    Aww damnit, well sorry then :0
    Ce ne sont que des gueux


  25. #25
    Join Date
    Sep 2006
    Location
    Canada
    Posts
    1,124
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    Quote Originally Posted by mormonman View Post
    You will still be "Interacting" when the NPC is doing the dying animation. Thus making yours slower.
    That's not how it works for me.



Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •