Results 1 to 19 of 19

Thread: Types/Records Help

  1. #1
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default Types/Records Help

    Don't know a thing about them.
    Can someone link me to scripts which utilize them.
    Want to see some examples of them.

    Thanks.

  2. #2
    Join Date
    Dec 2011
    Location
    The Netherlands
    Posts
    1,631
    Mentioned
    47 Post(s)
    Quoted
    254 Post(s)

    Default


    Script source code available here: Github

  3. #3
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Here's an example of creating a new Type:

    Simba Code:
    Type  //Define a new 'Type'
      TEnemy = record   //Name of your new 'Type', in this case "TEnemy"
        WSize,HSize: Integer;
        Cols,Tols: TIntegerArray;
        HMods,SMods: Array of Extended;
        Strings: TStringArray;
        TExp,THPExp: Integer;
      end;  //Everything within this block is what makes up your new 'Type'

    Var
    TEnemies: Array [0..4] of TEnemy;  //Or just TEnemies: Array of TEnemy;

    And here's an example of putting one together, kinda like as one would do with creating/packing a raw DTM:
    Simba Code:
    with TEnemies[Minotaur] do
        begin
          Cols := [8686218];
          Tols := [6];
          WSize := 20;
          HSize := 30;
          HMods := [0.47];
          SMods := [0.14];
          Strings := ['ck M','inot', 'taur'];
          TExp := 40;
          THPExp := 13;
        end;

    Does that make sense? I could explain more with usage if you'd like.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  4. #4
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Sweet tutorial thanks JJ.

    Hey old friend, Flight! Never see you on anymore, it's been too long!
    I pretty much got those parts down already, mainly looking into implementing them into the script/using them (Color, Uptext, etc) and then (later) possibly changing from type to type (or record to record) between characters.

    Thanks guys. Sorry I was too lazy to search on own .

  5. #5
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Give me just a second and I'll show you how I used a custom type "TEnemy" in my Strongholder Rat-Killing script. I'll edit this post and put it in here. Just something simple so you can see yourself as an example on how to use them.

    P.S. Yeah it's been a while man, I've not even been on MSN much lately either. I've got a bunch going on right now, I'm stretched really thin. I don't remember the last time I had 5 hours of straight sleep.

    Edit:
    Ok, here's part of the script that will focus on utilizing a custom Type. Let me know if anything is unclear.
    Simba Code:
    program New;
      {$DEFINE SMART}

      {$i SRL/srl.simba}

    Type
    TEnemy = record
      WSize,HSize: Integer;
      Cols,Tols: TIntegerArray;
      HMods,SMods: Array of Extended;
      Strings: TStringArray;
    end;

    Var
      GiantRat: TEnemy;


      Procedure SetOurEnemy;
      begin
        With GiantRat do
        begin
          Cols := [5066577];
          Tols := [3];
          WSize := 30;
          HSize := 30;
          HMods := [1.86];
          SMods := [0.17];
          Strings := ['ck G','iant', 't ra'];
        end;
      end;

    {*******************************************************************************
    Procedure FindFreeTargets(Target: TEnemy; MinCount, SType: Integer; Var TPs: TPointArray);
    By: Flight
    Description: Finds all available (not in combat) NPCs on the mainscreen
    through the TEnemy type.  Returns a (wrapped) TPointArray of every TEnemy found
    sorted from the center screen.
    -MinCount:  Minimal amount color count to be found in TEnemy's bounds
    to be considered a target
    -SType: TPA Split-type (1 for SplitTPA, 2 for TPAtoATPA)
    *******************************************************************************}

    Procedure FindFreeTargets(Target: TEnemy; MinCount, SType: Integer; Var TPs: TPointArray);
    var
      B,HPB: TBox;
      TP,MHPB,MNPCB: TPoint;
      TPA,GPA,RPA,
      GPB,RPB,RTPA,PArr: TPointArray;
      i,CTS,R,a: Integer;
      ATPA: T2DPointArray;
    begin
      CTS := GetColorToleranceSpeed;
      TPAFromBoxWrap(IntToBox(245, 135, 280, 185), PArr);

      for a := 0 to High(Target.Cols) do   //Target's (TEnemy) Cols (array)
      begin
        ColorToleranceSpeed(2);
        SetColorSpeed2Modifiers(Target.HMods[a], Target.SMods[a]);  //Target's HMods[] & SMods[]
        FindColorsSpiralTolerance(MSCX, MSCY, TPA, Target.Cols[a], MSX1, MSY1, MSX2, MSY2, Target.Tols[a]);   //Target's Col[] & Tols[]
        ClearTPAFromTPAWrap(TPA, PArr, TPA);
        ColorToleranceSpeed(CTS);
        if (Length(TPA) > 0) then break;
      end;

      if (Length(TPA) < 1) then
        Exit;

      if InRange(SType, 1, 2) then
      begin
        if (SType = 1) then
          SplitTPAExWrap(TPA, Target.WSize, Target.HSize, ATPA)    //Target's WSize & HSize
        else if (SType = 2) then
          TPAtoATPAExWrap(TPA, Target.WSize, Target.HSize, ATPA);  //Target's WSize & HSize
      end else
      begin
        Writeln('[Pulse] Error: Invalid SType');
        Exit;
      end;

      SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY));

      for i := 0 to High(ATPA) do
      begin

        if (Length(ATPA[i]) >= MinCount) then
          B := GetTPABounds(ATPA[i])
        else
          Continue;

        with B do
        begin

          TP := Point(((B.X1+B.X2)/2), B.Y1);

          if (TP.X < MSX1) then
            TP.X := MSX1;
          if (TP.Y < MSY1) then
            TP.Y := MSY1;

          HPB:= IntToBox(TP.X-30, TP.Y-40, TP.X+30, TP.Y);

          if (HPB.X1 < MSX1) then
            HPB.X1 := MSX1;
          if (HPB.X2 > MSX2) then
            HPB.X2 := MSX2;
          if (HPB.Y1 < MSY1) then
            HPB.Y1 := MSY1;
          if (HPB.Y2 > MSY2) then
            HPB.Y1 := MSY2;

          MHPB := MiddleBox(HPB);
          MNPCB := MiddleBox(B);

          ColorToleranceSpeed(2);
          SetColorSpeed2Modifiers(0.71, 0.00);
          FindColorsSpiralTolerance(MNPCB.X, MNPCB.Y, GPA, 43824, B.X1, B.Y1, B.X2, B.Y2, 6);
          SetColorSpeed2Modifiers(0.08, 0.00);
          FindColorsSpiralTolerance(MNPCB.X, MNPCB.Y, RPA, 262306, B.X1, B.Y1, B.X2, B.Y2, 5);
          SetColorSpeed2Modifiers(0.71, 0.00);
          FindColorsSpiralTolerance(MHPB.X, MHPB.Y, GPB, 43824, HPB.X1, HPB.Y1, HPB.X2, HPB.Y2, 6);
          SetColorSpeed2Modifiers(0.08, 0.00);
          FindColorsSpiralTolerance(MHPB.X, MHPB.Y, RPB, 262306, HPB.X1, HPB.Y1, HPB.X2, HPB.Y2, 5);
          ColorToleranceSpeed(CTS);

          if ((Length(GPA) = 0) and (Length(RPA) = 0)
            and (Length(GPB) = 0) and (Length(RPB) = 0)) then
          begin
            if (MNPCB <> Point(0, 0)) then
            begin
              SetArrayLength(RTPA, (Length(RTPA)+1));
              RTPA[R] := MNPCB;
              Inc(R);
            end;
          end;
        end;

      end;

      SortTPAFrom(RTPA, Point(MSCX, MSCY));
      TPs := RTPA;

    end;

      Procedure AttackRats;
      Var
        i: Integer;
        RatPoints: TPointArray;
      begin
        FindFreeTargets(GiantRat, 50, 2, RatPoints);  //Because 'FindFreeTargets' is a wrapper, "RatPoints" is
                                                      //input as an emypty variable and given back populated with a TPA

        for i:=0 to High(RatPoints) do
        begin
          //Attacking, ect...
        end;

      end;

    begin
      Smart_Server := 86;
      Smart_Members := True;
      Smart_Signed := True;

      setupSRL();

      SetOurEnemy;  //This MUST be declared before the remaining script; it declares the 'GiantRat' TEnemy
      AttackRats;
    end.
    Last edited by Flight; 05-25-2012 at 10:11 AM.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  6. #6
    Join Date
    Nov 2011
    Posts
    1,532
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    More scripts are now using records, it's nice to see that. Yohojo you may want to look at these in actions.

    Kyle's esswraith - http://villavu.com/forum/showthread.php?t=81178
    A making of ratkiller - http://villavu.com/forum/showthread.php?t=73768

    These are just examples. I think there are more, but these are the ones I can think of right now
    Current activity: Recovering from vacation
    - Nulla pars vitae vacare officio potest -
    SRL membership? Can I buy that?
    Scripts - AGS - SWF - WAR - EMS - W100S-EM
    If you need scripting help, you can pm me. Remember, if you need help you have to ask for it properly though

  7. #7
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Sweet sweet thanks.

    Yeah I'm using Kyle's right now but more examples will help a lot more too, seem to be simple enough and super duper useful and clean!

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

    Default

    Simba Code:
    Program potato;

    type
      TSize = record
        width, height: Extended;
      end;

      TPotato = record
        x, y: Integer;
        size: TSize;
      end;

      TPotatoArray = Array of TPotato;

    function Potato(x, y:Integer; width, height:Extended):TPotato;
    begin
      Result.x := x;
      Result.y := y;
      Result.size.width := width;
      Result.size.height := height;
    end;

    var
      TPA:TPotatoArray;

    begin
      SetLength(TPA,2);

      TPA[0].x := 3;
      TPA[0].y := 4;
      TPA[0].size.width := 50;
      TPA[0].size.height := 20;

      TPA[1] := Potato(10,15,40,40);

      writeln(TPA);
    end.
    Working on: Tithe Farmer

  9. #9
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    pfffbbtbtbtbt
    ^ Lost me.

    I think I'll stick with the tutorials/scripts !

  10. #10
    Join Date
    Sep 2007
    Location
    British Columbia, Canada
    Posts
    4,047
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default

    You can also use a type to keep track of your object like tree or animal.

    I use type in my clan war fighter to keep track of all the data of the entrance portal. Such as:
    Portal Distance,
    Portal Angle,
    Portal Real coordinate
    Portal Real coordinate with some offset.

    http://villavu.com/forum/showthread.php?t=66235
    Oh Hai Dar

  11. #11
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Stop showing off! > : 0

    Thanks !

  12. #12
    Join Date
    Nov 2011
    Posts
    1,532
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    My recently released EMS has also shown possible applications of records in a script. You may want to look at it. http://villavu.com/forum/showthread.php?t=82558
    Current activity: Recovering from vacation
    - Nulla pars vitae vacare officio potest -
    SRL membership? Can I buy that?
    Scripts - AGS - SWF - WAR - EMS - W100S-EM
    If you need scripting help, you can pm me. Remember, if you need help you have to ask for it properly though

  13. #13
    Join Date
    Oct 2008
    Location
    C:\Simba\Includes\
    Posts
    7,566
    Mentioned
    19 Post(s)
    Quoted
    180 Post(s)

    Default

    You can also change types on the fly too, meaning you can update the type properties as the script runs. (As seen in my ess script)
    Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
    { MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }

    When posting a bug, please post debug! Help us, help you!

    I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
    If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.


    SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.


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

    Default

    Let me explain it!

    Simba Code:
    Program potato;
    Standard start of every program!

    type
    Before you can create your own custom types and records you call type. This works the same as calling const and var.

    Simba Code:
    TSize = record
        width, height: Extended;
      end;

      TPotato = record
        x, y: Integer;
        size: TSize;
      end;

      TPotatoArray = Array of TPotato;

    As you can see I created three custom types here. TSize, TPotato and TPotatoArray. I will explain them all since they are all a bit different.

    TSize. Is the Type Size. It contains a width and an height. Both are Extended. Here is an example where I use it:
    Simba Code:
    var size:TSize;
    begin
      size.height := 10;
      size.width := 5.3;

      writeln('the size is ' + ToStr(size.height) + ' pixels width and ' + ToStr(size.width) + ' pixels height');
    end.

    TPotato. This it the type potato. Every potato has a location and a size. For location I added two integers, x and y. Instead of using width and height for the size I used the type TSize I just created. In this example it is only one line shorter but it can be useful in other situations. Example where I use it:
    Simba Code:
    var
      potato:TPotato;
    begin
      potato.x := 3;
      potato.y := 5;
      potato.size.height := 10;
      potato.size.width := 20;

      writeln('where is my potato?');
      writeln('[x = ' + ToStr(potato.x) + ' , y = ' + ToStr(potato.y) + ']');
      writeln('how big is my potato?');
      writeln('[height = ' + ToStr(potato.size.height) + ' , width = ' + ToStr(potato.size.width) + ']');
    end.

    TPotatoArray isn't a record. It is simply an array of TPotato. Similar as that a TPointArray is an array of TPoint.

    Setting values to the potato cost a lot of lines. As you can see above setting a potato takes 4 lines, and this is a very simple type. Sometimes it can be best to create a function that returns that type. So it can be done with one line. Similar IntTobox(xs,ys,xe,ye) returns a TBox and Point(x,y) returns a TPoint. Here you can see a simple example of such a function for the potato type I just created.

    Simba Code:
    function Potato(x, y:Integer; width, height:Extended):TPotato;
    begin
      Result.x := x;
      Result.y := y;
      Result.size.width := width;
      Result.size.height := height;
    end;

    And a small piece of code using all of the above methods and types:

    Simba Code:
    var
      TPA:TPotatoArray;

    begin
      SetLength(TPA,2);

      TPA[0].x := 3;
      TPA[0].y := 4;
      TPA[0].size.width := 50;
      TPA[0].size.height := 20;

      TPA[1] := Potato(10,15,40,40);

      writeln(TPA);
    end.
    Working on: Tithe Farmer

  15. #15
    Join Date
    Jan 2008
    Location
    C:\
    Posts
    1,483
    Mentioned
    2 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    TPA:TPotatoArray;
    snip...
    For some reason that just makes me laugh >.<

    After all the knowledge you've been linked to already you're probably a type master, but I'll give you a layman's view on this hubbub.

    A type is used to conglomerate pieces of information that all pertain to a a single, higher piece of information. If you have alot of specific data for say, A coal ore, then you can create a type "TCoal" and place the child data with it:

    Simba Code:
    TCoal = record
        Color, Tol: Integer;
        x, y: Integer;
        Use: Boolean;
      end;

    Now all three of those variables are linked to the parent "TCoal". You can use it like so:

    Simba Code:
    if TCoal.Use then
    begin
      FindColorsTolerance(TPA, TCoal.Color, MMX1, MMY1, MMX2, MMY2, TCoal.Tol);
      aTPA := SplitTPAEx(TPA, TCoal.x, TCoal.y);
      //blah blah blah
    end;

    It's mostly for organization and saving yourself alot of confusion / variables

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

    Default

    Quote Originally Posted by Runaway View Post
    already you're probably a type master,
    Working on: Tithe Farmer

  17. #17
    Join Date
    Jan 2008
    Location
    C:\
    Posts
    1,483
    Mentioned
    2 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    snip...
    I dunno... I was all about


    E: For Kids... yeah right, that shit was haaard!
    Last edited by Runaway; 05-25-2012 at 04:15 PM.

  18. #18
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    For what it's worth, http://villavu.com/forum/showthread.php?p=601951. It's a '09 ultimate type tutorial via Daniel, but there's already a lot of info on this thread. Figure the more tut/ex's the better :> cheers

  19. #19
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Hmm no one mentioned the difference between a type and a record:

    Simba Code:
    type
      TCharArray = Array Of Char;   //Just a type.. TCharArray is defined as an array of chars.


    type
      FoodStruct = record         //A record is a class.. Classes hold one-to-many data types.
      FoodDTM: Integer;
      FoodUptext: TStringArray;
    end;

    var
      FS: FoodStruct;      //Global Classes..


    Procedure FoodInfo(Which: String);         //Does not return a type.. instead it adds to the global FS.
    begin
      Case Lowercase(Which) Of
        'shark':
              begin
                FS.FoodDTM:= DTMFromString('..............');   //Maybe a Shark DTM?
                FS.FoodUptext:= ['ark', 'hark', 'Shark'];
              end;

        'lobster':
              begin
                //Same as before..  Different uptext..
              end;
      end;
    end;

    Function ReturnFoodInfo(Which: String): FoodStruct;   //Returns a class aka Foodstruct.
    begin
      Case Lowercase(Which) Of
        'shark':
              begin
                Result.FoodDTM:= DTMFromString('..............');   //Maybe a Shark DTM?
                Result.FoodUptext:= ['ark', 'hark', 'Shark'];
              end;

        'lobster':
              begin
                //Same as before..  Different uptext..
              end;
      end;
    end;

    var
      SomeFood: FoodStruct;
    begin
      SomeFood:= ReturnFoodInfo('shark');                            //we use our return foodinfo.
      if FindDTM(SomeFood.FoodDTM, X, Y, MIX1, MIY1, MIX2, MIY2) then
      begin
        MMouse(X, Y, 0, 0);
        if WaitUptextMulti(SomeFood.FoodUptext, 600) then .........
      end;


      //OR We can use the global one..
      FoodInfo('shark');
      If FindDTM(FS.FoodDTM, X, Y, MIX1, MIY1, MIX2, MIY2) then
      begin
        MMouse(X, Y, 0, 0);
        If waitUptextMulti(FS.FoodUptext, 600) then ..............
      end;
    end.
    I am Ggzz..
    Hackintosher

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
  •