SRL Archive - SRL Archives

SetFightMode Variant


Quickmarch

2009-05-27 15:34:47

Sets the fight mode using integers and strings:


function SetFightMode(oFightMode: Variant): Boolean;
var
i, x, y, r: Integer;
b: TBox;

begin
if not(Loggedin)then Exit;
GameTab(1);
Wait(200 + Random(777));
case VarType(oFightMode) of
3: case oFightMode of
1: b := IntToBox(575, 255, 630, 290);
2: b := IntToBox(660, 255, 710, 290);
3: b := IntToBox(575, 310, 630, 345);
4: begin
r := 4;
b := IntToBox(660, 310, 710, 345);
end;
end;
256: case Lowercase(oFightMode) of
'attack': b := IntToBox(575, 255, 630, 290);
'strength': b := IntToBox(660, 255, 710, 290);
'defence': begin
b := IntToBox(660, 310, 710, 345);
r := 4;
end;
'multi': b := IntToBox(575, 310, 630, 345);
end;
end;
while (i < 4) and (not FindColorTolerance(x, y, 1777020, b.x1, b.y1, b.x2, b.y2, 2)) do
begin
Mouse(RandomRange(b.x1, b.x2), RandomRange(b.y1, b.y2), 0, 0, True);
Wait(200 + Random(300));
Inc(i);
end;
Result := FindColorTolerance(x, y, 1777020, b.x1, b.y1, b.x2, b.y2, 2);
if (not Result) and (r = 4) then
SetFightMode(3);
end;


Probably can be shortened.

marpis

2009-05-27 15:38:04

very cool :) i think it should have always been like this

Da 0wner

2009-05-27 15:55:33

You do not need to check the vartype.

Edit: Also, you should use MouseBox (edit: what you have does same thing as mousebox, didn't look at it to good just saw mouse :p)
And
           'attack': b := IntToBox(660, 255, 710, 290);
'strength': b := IntToBox(660, 255, 710, 290);
Typo? They are same.

Quickmarch

2009-05-27 16:40:16

From: Da 0wner
You do not need to check the vartype.

Edit: Also, you should use MouseBox.
And
           'attack': b := IntToBox(660, 255, 710, 290);
'strength': b := IntToBox(660, 255, 710, 290);
Typo? They are same.


0.o typo. :p Also, you do need to check the vartype, otherwise it will give runtime errors…

EDIT: Fixed.

Da 0wner

2009-05-27 16:42:28

No it won't.
program New;
var
v : variant;
begin
v := 0;
v := lowercase(v);
case v of
'0', 0 : Writeln('Zero.');
'1', 1 : Writeln('One.');
else
Writeln('Wtf?');
end;
end.

Quickmarch

2009-05-27 16:46:50

From: Da 0wner
No it won't.
program New;
var
v : variant;
begin
v := 0;
v := lowercase(v);
case v of
'0', 0 : Writeln('Zero.');
'1', 1 : Writeln('One.');
else
Writeln('Wtf?');
end;
end.


This:


program New;
var
v : variant;
begin
v := 'attack';
v := lowercase(v);
case v of
'attack', 0 : Writeln('Zero.');
'strength', 1 : Writeln('One.');
else
Writeln('Wtf?');
end;
end.

Da 0wner

2009-05-27 16:56:54

Hmm, my bad, numbers as strings don't error, but when you have characters/letters it does. I will find a workaround.
program New;

var
v : variant;

begin
v := 'one';
if VarType(v) = 3 then
v := IntToStr(v);
v := lowercase(v);
case v of
'0', 'zero' : Writeln('Zero.');
'1', 'one' : Writeln('One.');
else
Writeln('Wtf?');
end;
end.

:D aha.

Nava2

2009-05-27 17:01:52

function SetFightMode(oFightMode: Variant): Boolean;
var
i, x, y, r: Integer;
b: TBox;
cmbBoxes: array of TBox;
strs: array of array of String;
begin
if not(Loggedin)then Exit;
GameTab(1);
Wait(200 + Random(777));

cmbBoxes := [IntToBox(575, 255, 630, 290), IntToBox(660, 255, 710, 290), IntToBox(575, 310, 630, 345), IntToBox(660, 310, 710, 345)];
strs := [TStringArray('attack', 'att'), TStringArray('strength', 'str'), TStringArray('controlled', 'control', 'ctrl', 'multi'), TStringArray('defence', 'def', 'defense')];
try oFightMode := LowerCase(oFightMode); except end;
case VarType(oFightMode) of
3: begin b := cmbBoxs[oFightMode - 1]; r := oFightMode; end;
256: for x := 0 to 3 do
begin
i := High(strs[x]);
for y := 0 to i do
if oFightMode = strs[x][y] then
begin
b := cmbBoxes[x];
r := x + 1;
Break;
end;
if b.x1 <> 0 then Break;
end;
end;
i := 0;
while (i < 4) and (not FindColorTolerance(x, y, 1777020, b.x1, b.y1, b.x2, b.y2, 2)) do
begin
Mouse(RandomRange(b.x1, b.x2), RandomRange(b.y1, b.y2), 0, 0, True);
Wait(200 + Random(300));
Inc(i);
end;
Result := FindColorTolerance(x, y, 1777020, b.x1, b.y1, b.x2, b.y2, 2);
if (not Result) and (r = 4) then
SetFightMode(3);
end;

I THINK I shortened it.

e: Nope, but I made it accept several more options. :)

Da 0wner

2009-05-27 17:04:54

O_O Nava, they are the same length XD.

And Quickmarch, check the post I edited it.

Quickmarch

2009-05-27 17:05:51

From: Nava2
function SetFightMode(oFightMode: Variant): Boolean;
var
i, x, y, r: Integer;
b: TBox;
cmbBoxes: array of TBox;
strs: array of array of String;
begin
if not(Loggedin)then Exit;
GameTab(1);
Wait(200 + Random(777));

cmbBoxes := [IntToBox(575, 255, 630, 290), IntToBox(660, 255, 710, 290), IntToBox(575, 310, 630, 345), IntToBox(660, 310, 710, 345)];
strs := [TStringArray('attack', 'att'), TStringArray('strength', 'str'), TStringArray('controlled', 'control', 'ctrl', 'multi'), TStringArray('defence', 'def', 'defense')];
try oFightMode := LowerCase(oFightMode); except end;
case VarType(oFightMode) of
3: begin b := cmbBoxs[oFightMode - 1]; r := oFightMode; end;
256: for x := 0 to 3 do
begin
i := High(strs[x]);
for y := 0 to i do
if oFightMode = strs[x][y] then
begin
b := cmbBoxes[x];
r := x + 1;
Break;
end;
if b.x1 <> 0 then Break;
end;
end;
i := 0;
while (i < 4) and (not FindColorTolerance(x, y, 1777020, b.x1, b.y1, b.x2, b.y2, 2)) do
begin
Mouse(RandomRange(b.x1, b.x2), RandomRange(b.y1, b.y2), 0, 0, True);
Wait(200 + Random(300));
Inc(i);
end;
Result := FindColorTolerance(x, y, 1777020, b.x1, b.y1, b.x2, b.y2, 2);
if (not Result) and (r = 4) then
SetFightMode(3);
end;

I THINK I shortened it.

e: Nope, but I made it accept several more options. :)


:) Maybe make this bit:
if oFightMode = strs[x][y] then

to:


if oFightMode = Lowercase(strs[x][y]) then

Nava2

2009-05-27 17:08:42

From: Quickmarch
:) Maybe make this bit:
if oFightMode = strs[x][y] then

to:


if oFightMode = Lowercase(strs[x][y]) then


If you check the arrays, they are already lowercase :)

Quickmarch

2009-05-27 17:10:54

From: Nava2
If you check the arrays, they are already lowercase :)


Oh yeah. :p

Also Da 0wner, yours still won't work because it only takes strings.

EDIT: nvm yours does work and it does take ints. :p

Da 0wner

2009-05-27 17:22:28

Mine does work. Test it.
function SetFightModeEx(oFightMode: Variant): Boolean;
var
x, y, t : Integer;
Boxes : TBoxArray;
begin
if not(Loggedin)then Exit;
GameTab(1);
Wait(200 + Random(777));
if VarType(oFightMode) = 3 then
oFightMode := IntToStr(oFightMode);
Boxes := [IntToBox(575, 255, 630, 290), IntToBox(660, 255, 710, 290),
IntToBox(575, 310, 630, 345), IntToBox(660, 310, 710, 345)];
case oFightMode of
'1', 'attack', 'att' : begin end;// so doesn't cause problem with the else
'2', 'strength', 'str' : Boxes[0] := Boxes[1];
'3', 'multi' : Boxes[0] := Boxes[2];
'4', 'defence', 'defense', 'def' : Boxes[0] := Boxes[3];
else
begin
SRL_Warn('SetFightModeEx', 'oFightMode not set correctly!', warn_AllVersions);
exit;
end;
end;
result := FindColorTolerance(x, y, 1777020, Boxes[0].x1, Boxes[0].y1, Boxes[0].x2, Boxes[0].y2, 2);
if not result then
begin
MouseBox(Boxes[0].x1, Boxes[0].y1, Boxes[0].x2, Boxes[0].y2, 1);
result := true;
end;
end;
Mine is the shortest, and includes an SRL_Warn :p.