Results 1 to 8 of 8

Thread: Floating integer help and logic errors : DS runespan script, GREAT EXP

  1. #1
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default Floating integer help and logic errors : DS runespan script, GREAT EXP

    Hello!

    Hopefully this is the right section. I'd like some help figuring out what is wrong with my script for DS.

    Some of the model ID's float to negative numbers. Also, sometimes the logic for which node to siphon from fails to pick the highest EXP node. really weird...

    You'll have to run my script and debug the Model array (siphonableSpots) to see the floating ID's. Also, to see the failed logic in my SortSiphonableSpotsbyEXP you'll have to run the script for a while.

    Thanks for the help!

    Simba Code:
    program new;
    {$i ogLib/lib/core/core.simba}

    type
      siphonSpot = record
        name: String;
        ID: uInt32;
        lvl: int32;
        xp: extended;
    end;

    const
      _x2 = 575;
      _y2 = 464;
      RCLevel = 80;

    var
      vCharArray: glCharArray;
      vModelArray: glModelArray;
      vTextureArray: glTextureArray;
      lastSiphon_ID, bestSiphonID: integer;
      siphonableSpots: array of siphonSpot;
      startingSpot: TPoint;
      modelIDList: array of integer;

    procedure setupSiphonOptions();
    var
      i: integer;
      siphonSpots: array of siphonSpot;
    begin
      SetLength(siphonSpots, 12);
      SetLength(siphonableSpots, 12);

      with siphonSpots[0] do
      begin
        name := 'Chaotic cloud';
        ID := 3134921782;
        xp := 61.6;
        lvl := 35;
      end;
      with siphonSpots[1] do
      begin
        name := 'Nebula';
        ID := 1874237583;
        xp := 74.7;
        lvl := 40;
      end;
      with siphonSpots[2] do
      begin
        name := 'Shifter';
        ID := 2929715345;
        xp := 86.8;
        lvl := 44;
      end;
      with siphonSpots[3] do
      begin
        name := 'Jumper';
        ID := 1966863770;
        xp := 107.8;
        lvl := 54;
      end;
      with siphonSpots[4] do
      begin
        name := 'Death esswraith';
        ID := 2533163227;
        xp := 60;
        lvl := 65;
      end;
      with siphonSpots[5] do
      begin
        name := 'Skulls';
        ID := 1304649452;
        xp := 120;
        lvl := 65;
      end;
      with siphonSpots[6] do
      begin
        name := 'Blood esswraith';
        ID := 4009427976;
        xp := 73.1;
        lvl := 77;
      end;
      with siphonSpots[7] do
      begin
        name := 'Blood pool';
        ID := 2566560352;
        xp := 146.3;
        lvl := 77;
      end;
      with siphonSpots[8] do
      begin
        name := 'Bloody skulls';
        ID := 1895117757;
        xp := 159.75;
        lvl := 83;
      end;
      with siphonSpots[9] do
      begin
        name := 'Soul esswraith';
        ID := 1218560579;
        xp := 106.5;
        lvl := 90;
      end;
      with siphonSpots[10] do
      begin
        name := 'Living soul';
        ID := 4055789841;
        xp := 213;
        lvl := 90;
      end;
      with siphonSpots[11] do
      begin
        name := 'Undead soul';
        ID := 3400103031;
        xp := 199.75;
        lvl := 95;
      end;

      siphonableSpots := Copy(siphonSpots);
      writeln(length(siphonableSpots));
      for i := 0 to high(siphonableSpots) do
        if (siphonableSpots[i].lvl > RCLevel) or (siphonableSpots[i].ID < 1) then
        begin
          setLength(siphonableSpots, i);
          break;
        end;

      setLength(modelIDList, length(siphonableSpots));

      for i := 0 to high(siphonableSpots) do
        modelIDList[i] := siphonableSpots[i].ID;
     end;

    function expFromModelID(modID: integer): integer;
    var
      i, h: integer;
    begin
      h := high(siphonableSpots);
      for i := 0 to h do
        if (siphonableSpots[i].ID = modID) then exit(round(siphonableSpots[i].xp));
    end;

    function sortSiphonsByEXP: glModel;
    var
      siphonM: glModelArray;
      siphons: TPointArray;
      i, h, tmpXP: integer;
      bestEXP : TPoint;//X holds XP, Y holds array index
    begin
      siphonM := vModelArray.getModels(modelIDList, IntToBox(0, 0,_x2,_y2));
      if length(siphonM) = 0 then exit;
      writeln();
      writeln('We''ve found:');
      for i := 0 to high(siphonM) do
        for h := 0 to high(siphonableSpots) do
          if siphonM[i].ID = siphonableSpots[h].ID then writeln(siphonableSpots[h].name+':'
          + toString(siphonableSpots[h].xp) );

      h := high(siphonM);

      for i := 0 to h do
      begin
        tmpXP := expFromModelID(siphonM[i].ID);
        if tmpXP > bestEXP.X then
        begin
          bestEXP.X := tmpXP;
          bestEXP.Y := i;
        end;
      end;
      bestSiphonID := siphonM[bestEXP.Y].ID;

      writeln('We choose:');
      for i := 0 to high(siphonableSpots) do
          if siphonM[bestEXP.Y].ID = siphonableSpots[i].ID then writeln(siphonableSpots[i].name+':'
          + toString(siphonableSpots[i].xp) );

      exit(siphonM[bestEXP.Y]);

    end;

    function isSiphoning(): boolean;
    begin
      if not ogl.getModels([1512564864, 3097344728],tBox([0, 0,_x2,_y2])).isEmpty() then
      begin
        sortSiphonsByEXP;
        exit(lastSiphon_ID=bestSiphonID);
      end;
    end;

    function siphon(): boolean;
    var
      thisModel: glModel;
      modelPoint: TPoint;
    begin
      if isSiphoning then exit(true);
      status('siphon()');
      thisModel := sortSiphonsByEXP;
      modelPoint := Point(thisModel.x, thisModel.y);
      if not PointInBox(modelPoint, IntToBox(1, 1, _x2, _y2)) then exit(false);
      result := tmouse.rightClickOption(thisModel.randomizePointEllipse(15),['Siphon'],random(155, 800));
      if result then lastSiphon_ID := bestSiphonID;
    end;

    function waitToSiphon(): boolean;
    var
      t: integer := GetSystemTime + RandomRange(3123, 7212);
    begin
      if isSiphoning then exit(true);
      status('waitToSiphon()');
      while t > GetSystemTime do
      begin
        if isSiphoning then exit(true);
        wait(243+random(1000));
      end;
    end;

    procedure waitWhileSiphoning();
    begin
      status('waitWhileSiphoning()');
      wait(randomRange(1231,3421));
    end;

    procedure islandCheck();
    var
      chatttter: TStringArray;
      myPos: TPoint;
    begin
      chatttter := tchat.getChat();
      if length(chatttter) < 1 then exit();
      if (Pos('You can''t reach that.', chatttter[0]) > 0) then
      begin
        myPos := tMinimap.getLocalPosition();
        if Distance(myPos.X, myPos.Y, startingSpot.X, startingSpot.Y) > 3 then
        begin
          tMinimap.ClickLocalPosition(startingSpot.randomizePointEllipse(3));
          wait(randomRange(5000, 12000));
          writeln('walked to start spot');
        end;
      end;
    end;

    procedure mainLoop();
    var
      siphonM: glModelArray;
      siphons: TPointArray;
      i: integer;
    begin
      smart.__Graphics.Clear();
      vCharArray := ogl.getChars();
      vModelArray := ogl.getModels();
      vTextureArray := ogl.getTextures();

      siphonM := vModelArray.getModels(modelIDList, IntToBox(0, 0,_x2,_y2));
      if (length(siphonM) > 0 )then
      begin
        siphons := siphonM.toPointArray();
        for i := 0 to high(siphons) do try
          smart.__Graphics.DrawCircle(siphons[i], 15, clRed, false);
          except end;
      end;

      islandCheck;
      if siphon then if waitToSiphon then waitWhileSiphoning;
      wait(100+ random(333));
    end;

    function TSmart.GetParams(useParameters: boolean): TStringArray; override;
    var
      funcExcludeList:tIntegerArray=[13,47,55,75,90,93,94,95,101,102,107,109,110,111,112,113,118,121,122,125,126,127,128,129,130,131,132,133];
      funcRandom:int32;
      page : String;
      params : TStringArray;
    begin

     if useParameters then
      begin
        page := getPage('http://www.runescape.com/game.ws?j=1');
        result := explode(',', between('worldLink=''', '''', page));
        result[0]:='http://world205.runescape.com/';
        exit;
      end;
      while true do
        if not funcExcludeList.contains(funcRandom:=random(1,141)) then
          begin
            result:=['http://world'+intToStr(funcRandom)+'.runescape.com/',''];
            break;
          end;
    end;

    var
      a: integer = 0;
      b: integer = 0;
      c: integer = _x2;
      d: integer = _y2;
    begin
      ogl.setup(800,600);
      glxviewport(a, b, c, d);
      smart.__Graphics.Clear();
      ogl.setDebugMode('none');

      startingSpot := tMinimap.getLocalPosition();
      setupSiphonOptions;
      writeln(siphonableSpots);
      writeln(modelIDList);
      repeat
        mainLoop();
      until (execRegExpr('(?i).*Oh dear.*',ogl.getChars().toString()));
      writeln('exit main loop');
      writeln(GetTimeRunning);
    end.

  2. #2
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Quote Originally Posted by footballjds View Post
    Hello!

    Hopefully this is the right section. I'd like some help figuring out what is wrong with my script for DS.

    Some of the model ID's float to negative numbers. Also, sometimes the logic for which node to siphon from fails to pick the highest EXP node. really weird...

    You'll have to run my script and debug the Model array (siphonableSpots) to see the floating ID's. Also, to see the failed logic in my SortSiphonableSpotsbyEXP you'll have to run the script for a while.

    Thanks for the help!

    Simba Code:
    ...
      modelIDList: array of integer;
    Didn't run the script but I quickly notice the following:
    modelIDList is an (signed) Integer array.. yet you assign numbers larger than signed integer to it, eg 3,134,921,782 is larger than 2^31 (2.1bill).
    Change modelIDList to "array of UInt32;" (unsigned integer), do the same for all places (if there are more) where you store the ID.
    Last edited by slacky; 10-08-2015 at 02:19 PM.
    !No priv. messages please

  3. #3
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    Quote Originally Posted by slacky View Post
    modelIDList is an (signed) Integer array.. yet you assign numbers larger than signed integer to it, eg 3134921782 is larger than 2^31 (2.1bill).
    Change modelIDList to "array of UInt32;" (unsigned integer), do the same for all places (if there are more) where you store the ID.
    I cannot do that, you can only pass a TIntegerArray to the function that uses the model ID's

  4. #4
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Quote Originally Posted by footballjds View Post
    I cannot do that, you can only pass a TIntegerArray to the function that uses the model ID's
    Well that is why it's wrapping around to a nagative number.. it's however irrelevant since getModels takes an integer array.
    It doesn't cause any harm in this case..

    For debugging you can just cast it back to UInt32, as the binary representation of both is the same.

    Eg: 32bit integer -1 is the same as unsigned 32bit integer 4294967295.
    Last edited by slacky; 10-08-2015 at 02:22 PM.
    !No priv. messages please

  5. #5
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    Quote Originally Posted by slacky View Post
    Well that is why it's wrapping around to a nagative number.. it's however irrelevant since getModels takes an integer array.
    It doesn't cause any harm in this case..

    For debugging you can just cast it back to UInt32, as the binary representation of both is the same.

    Eg: 32bit integer -1 is the same as unsigned 32bit integer 4294967295
    Thank you, I had noticed it does seem to work fine

  6. #6
    Join Date
    Jun 2015
    Location
    New Zealand
    Posts
    322
    Mentioned
    2 Post(s)
    Quoted
    131 Post(s)

    Default

    Quote Originally Posted by footballjds View Post
    Thank you, I had noticed it does seem to work fine
    Any chance of turning this into a workable release for us? Hehe :P

  7. #7
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    Quote Originally Posted by kiwikiwi View Post
    Any chance of turning this into a workable release for us? Hehe :P
    yeah, in time

  8. #8
    Join Date
    Jun 2015
    Location
    New Zealand
    Posts
    322
    Mentioned
    2 Post(s)
    Quoted
    131 Post(s)

    Default

    Quote Originally Posted by footballjds View Post
    yeah, in time
    Perfect - looking forward to it mate

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
  •