Results 1 to 15 of 15

Thread: Arrays..

  1. #1
    Join Date
    Mar 2008
    Location
    Look behind you.
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default Arrays..

    Hey, I'm fixing up my yew script to make it faster so I need to convert a few things to arrays. This really slows the script down:
    Simba Code:
    if (GetObjectIdAt(Tile(2941 ,3233)) = 38755) then
        TreeTile := Tile(2941 ,3233);
      if (GetObjectIdAt(Tile(2934 ,3234)) = 38755) then
        TreeTile := Tile(2934 ,3234);
      if (GetObjectIdAt(Tile(2935 ,3226)) = 38755) then
        TreeTile := Tile(2935 ,3226);
      if (GetObjectIdAt(Tile(2928 ,3231)) = 38755) then
        TreeTile := Tile(2928 ,3231);

    How do I convert that into a working array? I'm not familiar with it because it deals with tiles.
    ~Thanks,
    DeSnob.

  2. #2
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Progress Report:
    var
      i: integer;
      tiles: TTileArray;
    begin
      tiles := [Tile(2941 ,3233), Tile(2934 ,3234), Tile(2928 ,3231), Tile(2928 ,3231)];
      for i := 0 to high(tiles) do
        if (getObjectIDAt(tiles[i]) = 38755)) then
        begin
          treeTile := tiles[i];
          break;
        end;
    end;
    That what you mean?

    That's not going to speed up your script. I'm pretty sure it's the object functions that are slow. I remember reading in the Reflection 2 thread that they have been significantly sped up though.

  3. #3
    Join Date
    Mar 2008
    Location
    Look behind you.
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    Progress Report:
    var
      i: integer;
      tiles: TTileArray;
    begin
      tiles := [Tile(2941 ,3233), Tile(2934 ,3234), Tile(2928 ,3231), Tile(2928 ,3231)];
      for i := 0 to high(tiles) do
        if (getObjectIDAt(tiles[i]) = 38755)) then
        begin
          treeTile := tiles[i];
          break;
        end;
    end;
    That what you mean?

    That's not going to speed up your script. I'm pretty sure it's the object functions that are slow. I remember reading in the Reflection 2 thread that they have been significantly sped up though.
    Here's the function I made:
    Simba Code:
    Function GetObjectIdAt(ObjTile: TTile): Integer;
    var
      TheObject: TRSObject;
    begin
      TheObject := GetObjectAt(ObjTile, 0);
      Result := TheObject.ID;
    end;
    I has a noticeable delay (a second or two, which is horrible when competing against other bots).

  4. #4
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Yeah it's the Reflection object routines that are slow. I'm not sure what else you could do as I'm not really an expert on reflection. Here's some info. about the speed of object finding though.

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

    Default

    Kinda offtopic but DeSnob, weren't you SRL members once? :P I r confused
    Ce ne sont que des gueux


  6. #6
    Join Date
    Mar 2008
    Location
    Look behind you.
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Floor66 View Post
    Kinda offtopic but DeSnob, weren't you SRL members once? :P I r confused
    I was never an SRL Member. I can make a script and apply with it, but I don't have much time to do so.

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

    Default

    oh my bad
    Ce ne sont que des gueux


  8. #8
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    This one should be a bit faster:
    SCAR Code:
    function R_GetTrees(treeTiles:TTileArray;treeIDs:IntegerArray): TTile;
    var
      Plane, GroundObj, BaseX, BaseY: Integer;
      Temp: TRSObject;
    begin
      BaseX := SmartGetFieldInt(0, hook_static_BaseX);
      BaseY := SmartGetFieldInt(0, hook_static_BaseY);
      Plane := SmartGetFieldInt(0, hook_static_LoadedPlane);

      for i:= 0 to Length(treeTiles) do
      begin
        GroundObj := SmartGetFieldArray3DObject(0, hook_static_GroundTiles, Plane, treeTiles[i].y - BaseX, treeTiles[i].y - BaseX);
        Temp := NULL_RSOBJECT;

        Temp := R_GetInteractableObject(GroundObj, BaseX, BaseY);

        if (not(Temp = NULL_RSOBJECT) and Temp.ID = treeIDs[i])then
        begin
          SmartFreeObject(GroundObj);
          Result := Temp.Tile;
          Exit;
        end;
        SmartFreeObject(GroundObj)
      end;
    end;

    Edit: Almost forgot, its based on drags work, so credits.

    Edit: edit:
    And use reflection 2_1 or just include this function:
    Simba Code:
    (*
    R_GetInteractableObject
    ~~~~~~~~~~~~~~~~~~~~~~~

    .. code-block:: pascal

        function R_GetInteractableObject(GroundObj, BaseX, BaseY: Integer): TRSObject;

    Loads the information from the inputed GroundObj and returns a TRSObject. For
    use in object searching functions in this include, not in scripts.

    .. note::

      by Drags111

    *)

    function R_GetInteractableObject(GroundObj, BaseX, BaseY: Integer): TRSObject;
    var
      Node, Last, Obj: Integer;
      ID, SecondLevel: Integer;
    begin
      Node := SmartGetFieldObject(GroundObj, hook_ground_AnimableList);
      while(Node <> 0)do
      begin
        Obj := SmartGetFieldObject(Node, hook_AnimableNode_GetAnimable);
        if(Obj <> 0)then
          Break;
        Last := Node;
        Node := SmartGetFieldObject(Last, hook_AnimableNode_GetNext);
        SmartFreeObject(Last);
      end;
      SmartFreeObject(Node);

      if(Obj <= 0)then
        Exit;

      ID := SmartGetFieldShort(Obj, hook_InteractiveObject_GetID) and $FFFF;
      if(ID = -1) or (ID = 65535)then   //65535 is an unsigned -1...
      begin
        SecondLevel := SmartGetFieldObject(Obj, hook_interactiveobject2_GetObjectData);
        ID := SmartGetFieldInt(SecondLevel, hook_secondlevelobject_GetID) and $FFFF;
        if(ID = -1) or (ID = 65535)then
        begin
          SmartFreeObject(SecondLevel);
          SmartFreeObject(Obj);
          Exit;
        end;
      end;

      if(ID <> -1) and (ID <> 65535)then
      begin
        Result.ID := ID;
        Result.ObjType := OBJ_INTERACTABLE;

        Result.Tile.X := BaseX + (SmartGetFieldInt(Obj, hook_animable_PixelX) / 512);
        Result.Tile.Y := BaseY + (SmartGetFieldInt(Obj, hook_animable_PixelY) / 512);

        Result.TileArea.X1 := (BaseX + SmartGetFieldShort(Obj, hook_animableentity_getAreaX1));
        Result.TileArea.Y1 := (BaseY + SmartGetFieldShort(Obj, hook_animableentity_getAreaY1));
        Result.TileArea.X2 := (BaseX + SmartGetFieldShort(Obj, hook_animableentity_getAreaX2));
        Result.TileArea.Y2 := (BaseY + SmartGetFieldShort(Obj, hook_animableentity_getAreaY2));
      end;

      SmartFreeObject(SecondLevel);
      SmartFreeObject(Obj);
    end;
    Last edited by masterBB; 06-19-2011 at 11:33 AM.

  9. #9
    Join Date
    Mar 2008
    Location
    Look behind you.
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Ah, thanks. I'll just include the function. I'll see how it works out.
    E: I'd rather just use the complete ref 2.1. Where can I get it, and what kind of "set up" for the includes at the top of the script must be used?
    Last edited by DeSnob; 06-19-2011 at 01:31 PM.

  10. #10
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    It was typed in browser, so probably still contains some errors.

    Edit:
    This one makes more sense:
    Simba Code:
    function R_GetInteractableObject(GroundObj, BaseX, BaseY: Integer): TRSObject;
    var
      Node, Last, Obj: Integer;
      ID, SecondLevel: Integer;
    begin
      Node := SmartGetFieldObject(GroundObj, hook_ground_AnimableList);
      while(Node <> 0)do
      begin
        Obj := SmartGetFieldObject(Node, hook_AnimableNode_GetAnimable);
        if(Obj <> 0)then
          Break;
        Last := Node;
        Node := SmartGetFieldObject(Last, hook_AnimableNode_GetNext);
        SmartFreeObject(Last);
      end;
      SmartFreeObject(Node);

      if(Obj <= 0)then
        Exit;

      ID := SmartGetFieldShort(Obj, hook_InteractiveObject_GetID) and $FFFF;
      if(ID = -1) or (ID = 65535)then   //65535 is an unsigned -1...
      begin
        SecondLevel := SmartGetFieldObject(Obj, hook_interactiveobject2_GetObjectData);
        ID := SmartGetFieldInt(SecondLevel, hook_secondlevelobject_GetID) and $FFFF;
        if(ID = -1) or (ID = 65535)then
        begin
          SmartFreeObject(SecondLevel);
          SmartFreeObject(Obj);
          Exit;
        end;
      end;

      if(ID <> -1) and (ID <> 65535)then
      begin
        Result.ID := ID;
        Result.ObjType := 1;

        Result.Tile.X := BaseX + (SmartGetFieldInt(Obj, hook_animable_PixelX) / 512);
        Result.Tile.Y := BaseY + (SmartGetFieldInt(Obj, hook_animable_PixelY) / 512);

      end;

      SmartFreeObject(SecondLevel);
      SmartFreeObject(Obj);
    end;


    function R_GetTrees(treeTiles:TTileArray;treeIDs:TIntegerArray): TTile;
    var
      Plane, GroundObj, i, BaseX, BaseY: Integer;
      Temp: TRSObject;
    begin
      BaseX := SmartGetFieldInt(0, hook_static_BaseX);
      BaseY := SmartGetFieldInt(0, hook_static_BaseY);
      Plane := SmartGetFieldInt(0, hook_static_LoadedPlane);

      for i:= 0 to Length(treeTiles) do
      begin
        GroundObj := SmartGetFieldArray3DObject(0, hook_static_GroundTiles, Plane, treeTiles[i].y - BaseX, treeTiles[i].y - BaseX);
        Temp := NULL_RSOBJECT;

        Temp := R_GetInteractableObject(GroundObj, BaseX, BaseY);

        if (not(Temp = NULL_RSOBJECT) and (Temp.ID = treeIDs[i]))then
        begin
          SmartFreeObject(GroundObj);
          Result := Temp.Tile;
          Exit;
        end;
        SmartFreeObject(GroundObj);
      end;
    end;

    Edit: Edit: Last edit, I fixed most errors. Could you try this?
    Last edited by masterBB; 06-19-2011 at 01:27 PM.

  11. #11
    Join Date
    Mar 2008
    Location
    Look behind you.
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Ah, there's something out of range. Can't tell what's wrong since I don't understand most of the SMART field grabbing procedures.
    Simba Code:
    Error: Out Of Range at line 249
    The following DTMs were not freed: [SRL - Lamp bitmap, 1]
    The following bitmaps were not freed: [SRL - Mod bitmap, SRL - Admin bitmap]

    Here's the issue:
    Simba Code:
    GroundObj := SmartGetFieldArray3DObject(0, hook_static_GroundTiles, Plane, treeTiles[i].y - BaseX, treeTiles[i].y - BaseX);
    Thanks.

  12. #12
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Found it:
    [SIMBA]
    Simba Code:
    function R_GetInteractableObject(GroundObj, BaseX, BaseY: Integer): TRSObject;
    var
      Node, Last, Obj: Integer;
      ID, SecondLevel: Integer;
    begin
      Node := SmartGetFieldObject(GroundObj, hook_ground_AnimableList);
      while(Node <> 0)do
      begin
        Obj := SmartGetFieldObject(Node, hook_AnimableNode_GetAnimable);
        if(Obj <> 0)then
          Break;
        Last := Node;
        Node := SmartGetFieldObject(Last, hook_AnimableNode_GetNext);
        SmartFreeObject(Last);
      end;
      SmartFreeObject(Node);

      if(Obj <= 0)then
        Exit;

      ID := SmartGetFieldShort(Obj, hook_InteractiveObject_GetID) and $FFFF;
      if(ID = -1) or (ID = 65535)then   //65535 is an unsigned -1...
      begin
        SecondLevel := SmartGetFieldObject(Obj, hook_interactiveobject2_GetObjectData);
        ID := SmartGetFieldInt(SecondLevel, hook_secondlevelobject_GetID) and $FFFF;
        if(ID = -1) or (ID = 65535)then
        begin
          SmartFreeObject(SecondLevel);
          SmartFreeObject(Obj);
          Exit;
        end;
      end;

      if(ID <> -1) and (ID <> 65535)then
      begin
        Result.ID := ID;
        Result.ObjType := 1;

        Result.Tile.X := BaseX + (SmartGetFieldInt(Obj, hook_animable_PixelX) / 512);
        Result.Tile.Y := BaseY + (SmartGetFieldInt(Obj, hook_animable_PixelY) / 512);

      end;

      SmartFreeObject(SecondLevel);
      SmartFreeObject(Obj);
    end;


    function R_GetTrees(treeTiles:TTileArray;treeIDs:TIntegerArray): TTile;
    var
      Plane, GroundObj, i, BaseX, BaseY: Integer;
      Temp: TRSObject;
    begin
      BaseX := SmartGetFieldInt(0, hook_static_BaseX);
      BaseY := SmartGetFieldInt(0, hook_static_BaseY);
      Plane := SmartGetFieldInt(0, hook_static_LoadedPlane);

      for i:= 0 to High(treeTiles) do
      begin
        GroundObj := SmartGetFieldArray3DObject(0, hook_static_GroundTiles, Plane, treeTiles[i].x - BaseX, treeTiles[i].y - BaseY);
        Temp := NULL_RSOBJECT;

        Temp := R_GetInteractableObject(GroundObj, BaseX, BaseY);

        if (not(Temp = NULL_RSOBJECT) and (Temp.ID = treeIDs[i]))then
        begin
          SmartFreeObject(GroundObj);
          Result := Temp.Tile;
          Exit;
        end;
        SmartFreeObject(GroundObj);
      end;
    end;

    Sorry I can't test it right now...

  13. #13
    Join Date
    Mar 2008
    Location
    Look behind you.
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    It worked! TYYY. It's a lot faster too. That small delay is gone and now it can compete with the other bots for logs. REP++. Now.. just gotta find the issue where it doesn't go to the fourth tree.

    E: Found the problem.. wrong tiles D: lol
    Last edited by DeSnob; 06-19-2011 at 02:24 PM.

  14. #14
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    Found it:
    [SIMBA]
    Simba Code:
    function R_GetTreeObjectID(GroundObj: Integer): Integer;
    var
      Node, Last, Obj: Integer;
      ID, SecondLevel: Integer;
    begin
      Node := SmartGetFieldObject(GroundObj, hook_ground_AnimableList);
      while(Node <> 0)do
      begin
        Obj := SmartGetFieldObject(Node, hook_AnimableNode_GetAnimable);
        if(Obj <> 0)then
          Break;
        Last := Node;
        Node := SmartGetFieldObject(Last, hook_AnimableNode_GetNext);
        SmartFreeObject(Last);
      end;
      SmartFreeObject(Node);

      if(Obj <= 0)then
        Exit;

      ID := SmartGetFieldShort(Obj, hook_InteractiveObject_GetID) and $FFFF;
      if(ID = -1) or (ID = 65535)then   //65535 is an unsigned -1...
      begin
        SecondLevel := SmartGetFieldObject(Obj, hook_interactiveobject2_GetObjectData);
        ID := SmartGetFieldInt(SecondLevel, hook_secondlevelobject_GetID) and $FFFF;
        if(ID = -1) or (ID = 65535)then
        begin
          SmartFreeObject(SecondLevel);
          SmartFreeObject(Obj);
          Exit;
        end;
      end;

      if(ID <> -1) and (ID <> 65535)then
      begin
        Result := ID;
      end;

      SmartFreeObject(SecondLevel);
      SmartFreeObject(Obj);
    end;


    function R_GetTrees(treeTiles:TTileArray;treeIDs:TIntegerArray): TTile;
    var
      Plane, GroundObj, i, BaseX, BaseY,TreeID: Integer;
      Temp: TRSObject;
    begin
      BaseX := SmartGetFieldInt(0, hook_static_BaseX);
      BaseY := SmartGetFieldInt(0, hook_static_BaseY);
      Plane := SmartGetFieldInt(0, hook_static_LoadedPlane);

      for i:= 0 to High(treeTiles) do
      begin
        GroundObj := SmartGetFieldArray3DObject(0, hook_static_GroundTiles, Plane, treeTiles[i].x - BaseX, treeTiles[i].y - BaseY);

        TreeID:= R_GetTreeObjectID(GroundObj);

        if (TreeID = treeIDs[i])then
        begin
          SmartFreeObject(GroundObj);
          Result := treeTiles[i];
          Exit;
        end;
        SmartFreeObject(GroundObj);
      end;
    end;

    Sorry I can't test it right now...
    Maybe this is faster, and again, it's created in browser so.. :P

    ^Don't forget to rep drags, for his work on reflection2_1. I just customized it.

  15. #15
    Join Date
    Mar 2008
    Location
    Look behind you.
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    Maybe this is faster, and again, it's created in browser so.. :P

    ^Don't forget to rep drags, for his work on reflection2_1. I just customized it.
    This is just a private script, but I'm grateful that he and the others are working on Ref2. Can't wait for its release.

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
  •