SRL Archive - Suggestions

Scripts section


Smartzkid

2010-01-31 17:46:21

We need a place to post simba scripts.

Well, here's mine. Basic player-rotater, doesn't push simba, just something quick so I could get the feel for the IDE.

program new;

type TPlayer = record
U, P: String;
active: boolean;
ints: Array of Integer;
end;

var
players: Array of TPlayer;
CurrentPlayer: integer;

procedure DeclarePlayers;
var
i: integer;
begin
CurrentPlayer := 0;

SetArrayLength(players, 1);
players[0].U := '';
players[0].P := '';
players[0].active := true;

for i := 0 to high(players) do
SetLength(players[i].ints, 1);
end;

function AllPlayersInactive: boolean;
var
i: integer;
begin
result := true;
for i := 0 to high(players) do
if(players[i].active = true) then
result := false;
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
MoveMouse(Round(xs), Round(ys));
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
MoveMouse(Round(xe), Round(ye));
end;

procedure MMouse(x, y, rx, ry: integer);
var
cx, cy: integer;
randSpeed: Extended;
{$IFDEF UseLaptopMouse}
seg, e, f, g, nx, ny, hypo: Integer;
a, b, c: Extended;
Miss: Boolean;
{$ENDIF}
begin
GetMousePos(cx, cy);
{$IFDEF UseLaptopMouse}
miss := (Random(LMouse_MissChance) = 0);
e:= 0;
a:= x - cx;
b:= y - cy;
c:= Pow(a,2) + Pow(b,2)
hypo:= Round(Sqrt(c));
case hypo of
0: Exit;
1..225: seg:=1;
226..600: seg:= Random(2) + 1;
601..1800: seg:= random(3) + 2;
else seg := 5;
end;
f := Round( a / seg);
g := Round( b / seg);
repeat
Wait(30 + random(50));
{Begin: Modified from MMouse by Benland100}
randSpeed := 1.1; //(random(MouseSpeed) / 2.0 + MouseSpeed) / 10.0;
if randSpeed = 0.0 then
randSpeed := 0.1;
getMousePos(cx,cy);
nx:= (cx + (f * e)) + random(rx);
ny:= (cy + (g * e)) + random(ry);
{End: Modified from MMouse by Benland100}
if Miss then
begin
nx:= nx + RandomRange(rx, rx * 2);
ny:= ny + RandomRange(ry, ry * 2);
end;
WindMouse(cx,cy,nx,ny,11.0,8.0,10.0/randSpeed,12.0/randSpeed,10.0*randSpeed,10.0*randSpeed);
e:= e + 1;
until(e = seg);
GetMousePos(cx, cy);
if not PointInBox(Point(cx, cy), IntToBox(x, y, x + rx, y + ry)) then
begin
Wait(30 + random(30));
WindMouse(cx,cy,(x + random(rx)),(y + random(ry)),11.0,6.0,10.0/randSpeed,15.0/randSpeed,10.0*randSpeed,10.0*randSpeed);
end;
{$ELSE}
randSpeed:= 1.1; //(random(MouseSpeed) / 2.0 + MouseSpeed) / 10.0;
if randSpeed = 0.0 then
randSpeed := 0.1;
X := x + random(rx) - (rx / 2);
Y := y + random(ry) - (ry / 2);
WindMouse(cx,cy,x,y,9.0,3.0,10.0/randSpeed,15.0/randSpeed,10.0*randSpeed,10.0*randSpeed);
{$ENDIF}
end;

procedure Mouse(mousex, mousey, ranx, rany, left : Integer);
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 TypeKeys(s: String);
var
i: integer;
begin
for i := 1 to length(s) do
begin
SendKeys(s[i]);
wait(70 + random(30));
end;
SendKeys(chr(13));
end;

procedure LoginPlayer;
begin
Mouse(380, 187, 160, 12, MOUSE_LEFT);
repeat
wait(50 + random(10));
until(GetColor(372, 227) = 12509695)
wait(200 + random(200));
TypeKeys(players[CurrentPlayer].U);
wait(100 + random(300));
TypeKeys(players[CurrentPlayer].P);
repeat
wait(50 + random(10));
until(GetColor(259, 431) = 1647915)
Mouse(381, 431, 200, 35, MOUSE_LEFT);
wait(400 + random(200));
end;

procedure LogoutPlayer;
begin
Mouse(755, 10, 10, 10, MOUSE_LEFT);
wait(20 + random(80));
Mouse(636, 377, 60, 11, MOUSE_LEFT);
wait(400 + random(300));
end;

procedure NextPlayer(active: boolean);
begin
LogoutPlayer();
players[CurrentPlayer].active := active;

if(not(active)) then
if(AllPlayersInactive()) then
exit;

repeat
CurrentPlayer := (CurrentPlayer + 1) mod length(players);
until(players[CurrentPlayer].active)

wait(300 + random(200));
LoginPlayer();
end;

begin
DeclarePlayers();
LoginPlayer();

repeat
case players[CurrentPlayer].ints[0] of
0: TypeKeys('This game is boring');
1: TypeKeys('Meh, I give up.');
end;
wait(3000 + random(2000));
inc(players[CurrentPlayer].ints[0]);
if(players[CurrentPlayer].ints[0] < 2) then
NextPlayer(true)
else
NextPlayer(false);
until(AllPlayersInactive)
end.

Wizzup?

2010-01-31 19:19:21

Added the section.

mastaraymond

2010-02-01 10:32:31

Sendkeys() is not the right function to use, since it doesn't take any wait-time in consideration.. I might want to change that, hmm.

Smartzkid

2010-02-02 01:47:32

Good catch! I was too lazy to change that ;)

Nava2

2010-02-02 13:07:28

Use KeyUp and KeyDown.

Wizzup?

2010-02-02 16:25:35

From: Nava2
Use KeyUp and KeyDown.


He obviously knew that…

Smartzkid

2010-02-02 19:17:46

Its all good, maybe some person in the future will find it useful ;)