Results 1 to 8 of 8

Thread: need help

  1. #1
    Join Date
    Feb 2008
    Posts
    517
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default need help

    SCAR Code:
    program test;

    const
         time_out = 2500;
         mousespeed = 9;
         UserControl = 2; // 0 for disabled, 1 for a wait, 2 for ghost mouse

    var
       mouse_x, mouse_y, mx, my, freeze: integer;
       cursor: integer;

    procedure WaitForAFK();
    var tx,ty,timer:integer;
    begin
         repeat
               GetMousePos(mx,my);
               if (tx = mx) and (ty = my) then
               begin
                    timer := timer + 250;
               end else
               begin
                    tx := mx;
                    ty := my;
                    timer := 0;
               end;
               Wait(250);
         until (timer >= time_out);
    end;

    function within(a,b,c:integer):boolean;
    begin
         result := true;
         if a > b then
         begin
              a := a - c;
              if a > b then
                 result := false;
         end else
         begin
              a := a + c;
              if a < b then
                 result := false;
         end;
    end;

    procedure WaitForReturn();
    var   done:boolean;
    begin
         done := false;
         wait(200);
         repeat
               SafeDrawBitmap(cursor, GetClientCanvas, mouse_x, mouse_y);
               GetMousePos(mx,my);
               if within(mouse_x,mx,10) and within(mouse_y,my,10) then
               begin
                  done := true;
                  freeze := GetTimeRunning() + 500;
               end;
               wait(100);
         until done
    end;
       
    function MM(x,y:integer):boolean;
    begin
         GetMousePos(mx,my);
         if ((mouse_x <> mx) or (mouse_y <> my)) and (GetTimeRunning() >= freeze) then
         begin
            case usercontrol of
                 1: WaitForAFK;
                 2: WaitForReturn;
            end;
            mouse_x := mx;
            mouse_y := my;
            result := true;
         end else
         begin
            MoveMouse(x,y);
            mouse_x := x;
            mouse_y := y;
            result := false;
         end;
    end;

    procedure WindMouse(xs, ys, xe, ye, gravity, wind, minWait, maxWait, maxStep, targetArea: extended);
    var
      veloX, veloY, windX, windY, veloMag, dist, randomDist, lastDist, step: extended;
      lastX, lastY: integer;
      sqrt2, sqrt3, sqrt5: extended;
    begin
      sqrt2:= sqrt(2);
      sqrt3:= sqrt(3);
      sqrt5:= sqrt(5);
      while hypot(xs - xe, ys - ye) > 1 do
      begin
        dist:= hypot(xs - xe, ys - ye);
        wind:= minE(wind, dist);
        if dist >= targetArea then
        begin
          windX:= windX / sqrt3 + (random(round(wind) * 2 + 1) - wind) / sqrt5;
          windY:= windY / sqrt3 + (random(round(wind) * 2 + 1) - wind) / sqrt5;
        end else
        begin
          windX:= windX / sqrt2;
          windY:= windY / sqrt2;
          if (maxStep < 3) then
          begin
            maxStep:= random(3) + 3.0;
          end else
          begin
            maxStep:= maxStep / sqrt5;
          end;
        end;
        veloX:= veloX + windX;
        veloY:= veloY + windY;
        veloX:= veloX + gravity * (xe - xs) / dist;
        veloY:= veloY + gravity * (ye - ys) / dist;
        if hypot(veloX, veloY) > maxStep then
        begin
          randomDist:= maxStep / 2.0 + random(round(maxStep) / 2);
          veloMag:= sqrt(veloX * veloX + veloY * veloY);
          veloX:= (veloX / veloMag) * randomDist;
          veloY:= (veloY / veloMag) * randomDist;
        end;
        lastX:= Round(xs);
        lastY:= Round(ys);
        xs:= xs + veloX;
        ys:= ys + veloY;
        if (lastX <> Round(xs)) or (lastY <> Round(ys)) then
          if MM(Round(xs), Round(ys)) then
          begin
             xs := mx;
             ys := my;
          end;
        step:= hypot(xs - lastX, ys - lastY);
        wait(round((maxWait - minWait) * (step / maxStep) + minWait));
        lastdist:= dist;
      end;
      if (Round(xe) <> Round(xs)) or (Round(ye) <> Round(ys)) then
         if MM(Round(xe), Round(ye)) then
         begin
            xs := mx;
            ys := my;
         end;
    end;

    procedure MMouse(x, y, rx, ry: integer);
    var
      cx, cy: integer;
      randSpeed: Extended;
    begin
      GetMousePos(cx, cy);
      randSpeed:= (random(MouseSpeed) / 2.0 + MouseSpeed) / 10.0;
      if randSpeed = 0.0 then
         randSpeed := 0.1;
      X := x + random(rx);
      Y := y + random(ry);
      WindMouse(cx,cy,x,y,9.0,3.0,10.0/randSpeed,15.0/randSpeed,10.0*randSpeed,10.0*randSpeed);
    end;

    procedure Mouse(mousex, mousey, ranx, rany: Integer; left: Boolean);
    var
      a, b, c: Integer;
    begin
      MMouse(mousex, mousey, ranx, rany);
      Wait(60 + Random(30));
      GetMousePos(b, c);
      HoldMouse(b, c, left);
      repeat
        Wait(20 + Random(30));
        a := a + 1;
      until (a > 4);
      GetMousePos(b, c);
      ReleaseMouse(b, c, left);
      Wait(100 + Random(100));
    end;

    procedure mouseinit();
    begin
         GetMousePos(mouse_x,mouse_y);
         cursor := BitmapFromString(12, 20, 'beNqd0tERgCAIBuB/WnZwrm' +
           'bp0VlIuKPACCuP80E/ORSJwIzeUQ/mbcw145EIC6Zmr5mZiqlZsGh' +
           'yZqZimZmZM48sM7Llw5nzHWSd6Aoz0rjJxJoFtCaRtkaPy268Qkjl' +
           'wccu872qvx/mTSrojXEANM+t0g==');
    end;
       
       

       
    begin
         mouseinit;
         Mouse(1000,900,5,5,true);
    end.


    basically, this imrpoves current mouse functions by replaing MoveMouse with a new function that checks if the mouse was moved by the user, and if it was it will do either (wait for the user to stop doing his thing and continue) or (wait for user to return the mouse to the point of taking it over)


    now, i have solved the taking it over function (not completely, still looking for help at this thread http://www.villavu.com/forum/showthread.php?t=53161), but for the afk wait, after the waiting process has been completed, it will continue on with the script, but the mouse could be anywhere, and it will instantly jump to its old position isntead of transitioning the movement from old to start location

    this could be solved by transitioning some of the local variables to global in wind mouse procedure, but to be honest i cant really think right now and was wondering if anyone was kind enough to help me out, ive been messing around with the mouse crap for far too long to even know what im doing couse i code kinda messy


    edit: fixed it, still need help with drawing an image on the screen tho so you get a visual reminder of where the mouse needs to be put back at for ghost mouse


    oh btw if anyone wants to check it out goahead and run it, try all 3 different modes and tell me what ya think of em


    edit: okay i figured out how to draw, but now i need to know how to clear the painting if the window doesn't refresh by itself, and how to make the drawing have black color (0) be transparent, tried to do SetTranasparentColr(cursor,0); but later realized it only works for "fast" drow not "safe" draw


    got another request

    could anyone help me test out this function

    SCAR Code:
    program Zzz;
    var keyboard, shiftboard, current: array [0..3] of string;
        mistypeprobability:integer;
        lastletter:string;

        { Things that are not finished:

                 ~Adding capitalization of letters

                                                              }


    procedure KeyboardVars;
    begin
         keyboard[0] := '`1234567890-= ';   shiftboard[0] := '~!@#$%^&*()_+' ;
         keyboard[1] := ' qwertyuiop[]\';   shiftboard[1] := ' QWERTYUIOP{}|';
         keyboard[2] := ' asdfghjkl;''' ;   shiftboard[2] := ' ASDFGHJKL:"'  ;
         keyboard[3] := ' zxcvbnm,./'   ;   shiftboard[3] := ' ZXCVBNM<>?'   ;
    end;

    procedure Letter(character:char);
    var key:byte;
    begin
         key := GetKeyCode(character);
         Wait(random(10));
         KeyDown(key);
         Wait(20+Random(40));
         KeyUp(key);
         Wait(random(10));
    end;

    procedure PressEnter();
    begin
         Letter(Chr(13));
    end;

    procedure PressBack();
    begin
         Letter(Chr(8));
    end;

    function TypeLetter(character:char; mistake:boolean):integer;
    var normal, shift:string;
        i, position, positioni:integer;
        key:char;
    begin
         result := 0;
         if character = ' ' then
         begin
              Letter(' ');
              Exit;
         end;
         normal := '`1234567890-=qwertyuiop[]\asdfghjkl;''zxcvbnm,./';
         shift  := '~!@#$%^&*()_+QWERTYUIOP}{|ASDFGHJKL:"ZXCVBNM<>?' ;
         if Pos(character, normal) <> 0 then
            current := keyboard;
         if Pos(character, shift) <> 0 then
            current := shiftboard;
         for i := 0 to 3 do
         begin
              if Pos(character, current[i]) <> 0 then
                 positioni := i;
         end;
         position := Pos(character, current[positioni]);
         key := current[positioni][position];
         if mistake then
         begin
              case Random(120 + mistypeprobability) of
                0..2: // Longer wait, ex. forget key location or something
                begin
                     Wait(30+Random(100));
                     mistypeprobability := mistypeprobability + 10;
                end;
                3..15: // Shorter wait, ex. small brainfart
                begin
                     Wait(Random(40));
                     mistypeprobability := mistypeprobability + 5;
                end;
                16: // No letter typed
                begin
                     result := 1;
                     Exit;
                end;
                17..20: // Chance to mistype letter on the same row
                begin
                     position := position - 1 + Random(3);
                     if position < 1 then
                        position := 1;
                     if (positioni > 0) and (position < 2) then
                        position := 2;
                     if position > Length(current[positioni]) then
                        position := Length(current[positioni]);
                     if key <> current[positioni][position] then
                     begin
                        key := current[positioni][position];
                        result := 2;
                        mistypeprobability := mistypeprobability + 25;
                     end;
                end;
                21: // Mistype the letter upward
                begin
                     positioni := positioni + 1;
                     if positioni > 3 then
                        positioni := 3;
                     if key <> current[positioni][position] then
                     begin
                        key := current[positioni][position];
                        result := 2;
                        mistypeprobability := mistypeprobability + 25;
                     end;
                end;
                22: // Mistype the letter downward
                begin
                     positioni := positioni - 1;
                     if positioni < 0 then
                        positioni := 0;
                     if key <> current[positioni][position] then
                     begin
                        key := current[positioni][position];
                        result := 2;
                        mistypeprobability := mistypeprobability + 25;
                     end;
                end;
                23..300: // No mistype, increase the chance to mistype for the next letter
                begin
                     mistypeprobability := mistypeprobability - 1;
                end;
              end;
         end;
         Letter(key);
    end;

    procedure TypeText(text:string;mistake,fix:boolean);
    var i,n,t,b:integer;
    begin

       i := 1;
       n := 0;
       b := 0;
       mistypeprobability := 100;
       
       while (i <= Length(text)) do
       begin
          if fix then
          begin
             if b = 0 then
             begin
                b := TypeLetter(text[i],mistake);
                if b <> 0 then
                   n := i;
             end else
                TypeLetter(text[i],mistake);
               
             if ((random(6) = 5) and (b <> 0)) or ((Length(text) - i < 2) and (b <> 0)) then
             begin
                Wait(99+Random(300));
                if b = 2 then
                begin
                   Wait(15+Random(45));
                   PressBack;
                end;
                for t := 1 to (i - n) do
                begin
                   Wait(15+Random(45));
                   PressBack;
                end;
                i := n - 1;
                b := 0;
             end;
             
          end else
          begin
             TypeLetter(text[i],mistake);
          end;
          i := i + 1;
          Wait(20+Random(40));
       end;
    end;

    begin
         KeyboardVars;
         TypeText('Harry was a small litte boy, he had no brains but was a very happy child, other children were very envious of his happiness so they went to a witch doctor with horrible intentions.',true,true);
    end.

    basically it's a function to type stuff for ya, it will do it realistically, create realistic errors if you want it to, and it will also fix them realistically if you want it to, only thing i dont have finished with it are capitalization of letters, you can adjust the probability values easily in the function to make it more realistic, if you find a better combination goahead and post it
    Last edited by Feroc1ty; 12-08-2009 at 03:32 AM.

  2. #2
    Join Date
    Feb 2008
    Posts
    517
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    sigh, no one?

  3. #3
    Join Date
    Oct 2007
    Posts
    742
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Don't really have the time right now to think, but just a suggestion, start out with a little easier stuff for your first time codes.
    Woot woot.

  4. #4
    Join Date
    Feb 2007
    Location
    Alberta,Canada
    Posts
    2,358
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    if your painting on the smart canvas (and still need help clearing it)

    SCAR Code:
    Procedure ClearSMARTCanvas;
    var BMP: Integer; SMARTCanvas, Canvas: TCanvas;
    begin
      BMP := BitmapFromString(765, 503, '')
      SMARTCanvas := GetBitmapCanvas(BMP);
      Canvas := GetBitmapCanvas(BMP);
      SMARTCanvas.handle := SmartGetDebugDC;
      CopyCanvas(Canvas, SMARTCanvas, 0, 0, 765, 503, -1000, -1000, 1000, 1000);
      FreeBitmap(BMP);
    end;

    credit N3ss3s for the function.

    and i don't get your second question.

  5. #5
    Join Date
    Feb 2008
    Posts
    517
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    This isn't smart canvas, this is the normal runescape client.

  6. #6
    Join Date
    Feb 2008
    Posts
    517
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    updated original post with another script id like help on making, simply test it out see if you find any errors and if you want adjust probability values

  7. #7
    Join Date
    Oct 2007
    Posts
    742
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    There is a function that turns letters capped, i forgot the name though, but it something like this:
    Capitalize(string);
    Cap(string);
    Caps(string);
    Capital(string);

    Not sure, but play around with it or wait till someone tells it to you.
    Woot woot.

  8. #8
    Join Date
    Feb 2008
    Posts
    517
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Oh I think I can figure it out, shouldn't be too hard, what I'll try to do is hold shift for the keys that are on the shiftboard, while typing out the key in normalboard, and then release it.

    I was more or less hoping for criticism on the method used, and the typing speed/probability calculation for errors made.

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
  •