SRL Archive - SRL Archives

A couple fixes and improvements..


EvilChicken!

2008-08-09 12:16:35

HAI. Please comment.

1:
function FindDead: Boolean;
begin
if not LoggedIn then exit;
Result := FindTextTPA(0, 0, MCX1, MCY1, MCX2, MCY2, 'dear', SmallChars, Nothing);
if not Result then exit;
Inc(Deaths);
SaveToChatLog;
if Reincarnate then exit;
if ScreenShots then
TakeScreen('Found Dead');
if not LogOut then
repeat
Wait(1000 + Random(1000));
until not LoggedIn;
Players[CurrentPlayer].Rand := 'Died';
Players[CurrentPlayer].Active := False;
end;

Shortened.

2: FindLamp skill coords can be shortened using simple maths.

3:
function InBlack: Boolean;
var
I: Byte;
begin
if not LoggedIn then exit;
for I := 1 to 4 do
begin
case I of
1: Result := ((GetColor(650, 155) = 65536) and (GetColor(650, 145) = 65536)
and (GetColor(650, 135) = 65536) and (GetColor(650, 125) = 65536));
2: Result := ((GetColor(650, 15) = 65536) and (GetColor(650, 25) = 65536)
and (GetColor(650, 35) = 65536) and (GetColor(650, 45) = 65536));
3: Result := ((GetColor(580, 82) = 65536) and (GetColor(590, 82) = 65536)
and (GetColor(600, 82) = 65536) and (GetColor(610, 82) = 65536));
4: Result := ((GetColor(714, 82) = 65536) and (GetColor(704, 82) = 65536)
and (GetColor(694, 82) = 65536) and (GetColor(684, 82) = 65536));
end;
if Result then exit;
end;
end;

Shortened by lots.


4:
function NoGameTab: Boolean;
var
I: Byte;
begin
Result := False;
if not LoggedIn then exit;
for I := 1 to 14 do
if not TabExists(I) then
begin
Result := True;
Exit;
end;
end;

I really don't understand the current NoGameTab in Rev#20. No randomness in waiting, and why wait a second if it finds a missing GameTab?

5:
function IntArrayMatch(Ar1, Ar2: TIntegerArray): Boolean;
var
I, L: Integer;
begin
Result := False;
L := High(Ar1);
if L <> High(Ar2) then exit;
for I := 0 to L do
if not InIntArray(Ar2, Ar1[I]) then exit;
Result := True;
end;

Minor fixes.

6: I think DwarfItem should be added to Dwarf Handler.

7:
function FindNonInventoryRandoms: Boolean;
var
I: Byte;
begin
if not LoggedIn then exit;
for I := 1 to 5 do
begin
case I of
1: Result := SolveNonTalkingRandoms; // Why not "Result := .." ?
2: Respond;
3: Result := FindTalk;
4: Result := FindDead;
5: Result := RC;
end;
if Result then exit;
end;
end;

Minor fixes again.

8:
function FindNormalRandoms: Boolean; 
var
I: Byte; // 0..255 and -2147483648..2147483648.
begin
Result := False;
if not LoggedIn then exit;
for I := 1 to 8 do
begin
case I of
1: Result := SolveNonTalkingRandoms; // Again, why not "Result := .." ?
2: Respond;
3: Result := FindTalk;
4: Result := FindDead;
5: Result := FindLamp(LampSkill);
6: Result := (FindBox) and (SolveBox);
7: Result := RC;
8: Result := FindMod;
end;
if Result then exit;
end;
end;

Again, just small fixes..

9
was a fail.


10: What's the use of GambleNewBox?

11:
{*******************************************************************************
Description: Results: 0 if nothing found, 1 for first and 2 for second screen.
Coords are taken from current TradeScreen and TradeScreen2 functions.
*******************************************************************************}
function TradeScreen: Byte;
begin
Result := 0;
if GetColor(90, 61) = 2070783 then
Result := 1
else
if GetColor(142, 55) = 0 then
Result := 2;
end;

Combined the two TradeScreen functions.

12:
function CheckArea(Area: string): Boolean;
begin
Result := False;
case LowerCase(Area) of
'inv', 'inventory': Result := (BankScreen or ShopScreen or TradeScreen or GameTab(4));
'shop': Result := ShopScreen;
'bank': Result := BankScreen; // What if user doesn't want to fix bank..?
'trade', 'your trade': Result := TradeScreen;
else
srl_Warn('CheckArea', Area + ' is an invalid option', warn_AllVersions);
end;
if not Result then
WriteLn('PROBLEM: ' + Area + ' interface not open'); // I'm not sure if thats
end; // even needed.

Shortened.

13:
procedure RandomRClick; // Why evade simplicity?
var
M: Byte;
begin
if not LoggedIn then exit;
M := MouseSpeed;
MouseSpeed := 7 + Random(4);
ActivateClient;
MouseBox(MSX1, MSY1, MIX2, MIY2, 2);
MouseSpeed := M;
end;

Replaced with one single MouseBox.

14:
procedure FixBank;
var
X, Y, T: Integer;
begin
if (BankScreen) and (GetColor(486, 103) = 1975337) then
begin
MMouse(486, 105, 3, 3);
GetMousePos(X, Y);
HoldMouse(X, Y, True); // Random(1) allways returns 0..
T := GetSystemTime;
repeat
Wait(30 + Random(50));
if GetSystemTime - T > 10000 then break;
until GetColor(486, 103) <> 1975337;
Wait(300 + Random(300));
ReleaseMouse(X, Y, True);
end;
end;

UUh. Shortened and removed the Random(1)'s.

15:
function Flag: Boolean; // Small change..
var
timeout, x, y: Integer;
begin
if not LoggedIn then exit;
Result := FindColor(X, Y, 255, MMX1, MMY1, MMX2, MMY2);
if Result then
repeat
Wait(100);
Inc(Timeout);
until (not FindColor(x, y, 255, MMX1, MMY1, MMX2, MMY2)) or (Timeout > 300);
end;

Shortened.

16:
procedure MouseFlag(CX, CY, RandX, RandY, Dist: Integer); // <- Uses FFlag(Dist)
var
I: Byte;
begin
if not LoggedIn then exit;
Mouse(CX, CY, RandX, RandY, True);
repeat
Wait(50 + Random(50));
Inc(i);
until (FlagPresent) or (I < 15);
FFlag(Dist);
Wait(500 + Random(350));
end;

I think I shortened it? And more importantly, replaced Flag with FFlag and added dist parameter.

17:
Procedure ChatsOff;
var
I: Byte; // INTEGER NAZI PEOPLE!!!11
begin
if not LoggedIn then exit;
for I := 1 to 5 do
SetChat('off', I);
end;

Very small change.

18: GetCurrentTab and TabExists can be shortened with simple maths.

19: Please remove my name from the "Retaliate" function credits.

20: SkillToCoords should also be shortened using maths.

21:
{*******************************************************************************
Replaces MouseItem and MMouseItem. 8D
*******************************************************************************}
procedure MouseItem(I, ClickType: Byte);
var
TB: TBox;
begin
if not LoggedIn then exit;
if not GetCurrentTab = 4 then
begin
if not GameTab(4) then exit;
Wait(500 + Random(350));
end;
GetInvItemBounds(I, TB);
MouseBox(TB.X1 + 4, TB.Y1 + 4, TB.X2 - 4, TB.Y2 - 4, ClickType);
end;

Small function to replace both MouseItem and MMouseItem.

{*******************************************************************************
Small fix + "uptated" for use with new MouseItem, if it will be used.
*******************************************************************************}
procedure DragItem(Inv1, Inv2: Byte);
var
X, Y: Integer;
begin
if not LoggedIn then exit;
MouseItem(Inv1, 3);
GetMousePos(X, Y);
HoldMouse(X, Y, True);
Wait(150 + Random(150));
MouseItem(Inv2, 3);
GetMousePos(X, Y);
ReleaseMouse(X, Y, True);
Wait(350 + Random(350));
end;

"Updated" for the new MouseItem, if you people decide to use it..

{*******************************************************************************
If the items are unloaded, they'll appear a little later than the gametab switch..
*******************************************************************************}
function ExistsItem(I: Byte): Boolean;
var
X, Y: Integer;
TB: TBox;
begin
Result := False;
if not LoggedIn then exit;
if not GetCurrentTab = 4 then
begin
if not GameTab(4) then exit;
Wait(500 + Random(350));
end;
TB := InvBox(i);
Result := FindColor(x, y, 65536, TB.x1 + 5, TB.y1 + 5, TB.x2 - 5, TB.y2 - 5);
end;

I noticed a lot of use of Integers where Bytes could be used. An integer has a value of -2147483648..2147483648, while a Byte has a value of 0..255. Saves soem memory and looks prettier. IMO. And also, SmallInt could be used in some places, but I'm currently experiencing some trouble with that, so I decided not to use that var type, in case the problam was global.

Anyway, see proc description.

{*******************************************************************************
Same as above + more small fixes.
*******************************************************************************}
function InvCount: Byte;
var
I: Byte;
begin
Result := 0;
if not LoggedIn then exit;
if not GetCurrentTab = 4 then
begin
if not GameTab(4) then exit;
Wait(500 + Random(350));
end;
for I := 1 to 28 do
if ExistsItem(I) then Inc(Result);
end;

@Description();

function InvFull: Boolean; // ^^^
begin
Result := False;
if not LoggedIn then exit;
if not GetCurrentTab = 4 then
begin
if not GameTab(4) then exit;
Wait(500 + Random(350));
end;
Result := InvCount = 28;
end;

@DescriptionOfProcAbove();

function DropItem(i: Byte): Boolean;
begin
Result := False;
if (not LoggedIn) or (not ExistsItem(i)) then exit;// Existsitem switches gametabs..
MouseItem(I, 2); // New MouseItem..
Wait(170 + Random(150));
Result := ChooseOption('rop');
Wait(RandomRange(50, 200));
end;


All I had time for, please leave comments for me to read when I get back. :)

Thanks.

Harry

2008-08-09 12:22:16

Sex-eh.

Make sure though before scanning for the text in FindDead "if not loggedIn then Exit;". And only other thing is standards in one or two spots.

Looks nice :)

tarajunky

2008-08-09 13:52:50

So if someone says 'oh dear', everyone logs out? Lol.

n3ss3s

2008-08-09 16:02:46

Tara, Tara, Tara ;)

Result := FindTextTPA(0, 0, MCX1, MCY1, MCX2, MCY2, 'dear', SmallChars, Nothing);

It's black text :)

EvilChicken!

2008-08-09 17:24:18

Ok, any comments regarding the actual functions? Or do I have to split them up and comment every single of them?

Edit: Done, now please comment the functions and procedures.


Edit2: No one has anything to comment? :'(

tarajunky

2008-08-12 01:21:58

I don't understand the text tpa stuff too well, but I had a guy stuck with a lamp random, trying to bank it like an idiot.

We could probably do the same thing with the error text RS spits out.

"A magical force prevents you from banking this item."

I think that's the same text it gives you for strange boxes as well. Might be a good failsafe function to have in SRL so people can use it in their banking procedures.

EvilChicken!

2008-08-12 10:01:16

From: tarajunky
I don't understand the text TPA stuff too well, but I had a guy stuck with a lamp random, trying to bank it like an idiot.

We could probably do the same thing with the error text RS spits out.

"A magical force prevents you from banking this item."

I think that's the same text it gives you for strange boxes as well. Might be a good failsafe function to have in SRL so people can use it in their banking procedures.


I do agree, but on the other side, SRL should be capable of deactivating players whop have failed a box or a lamp random. For example, if SRL doesn't recognize a new box or lamp, the player times out (since it isn't certain that the coordinates for the new "close" button matches the old one, if you understand) and gets set to inactive. This should make that failsafe unneeded.

And also, I think that what I mentioned, would be much easier to get done than the depositing failsafe. Firstly, you need to see if there already is a black chat message saying that you cannot deposit something, and even if it is, and the script is aware of that, that message can disappear (or move) while script is depositing, and the script might mistake a old message for being a new, or perhaps ignore the new message, ect..

With other words, my opinion is that although your idea is a good one, all we need is the simple thing I mentioned to be put in Antirandoms.scar.

Once again, I must say that it is only MY opinion, and it may be horrifically wrong.


And going a slight bit off topic, thanks for reminding me to send you a PM :p

tarajunky

2008-08-12 11:37:40

SRL seems to have a problem detecting the lamp in the last inventory position. As far as I know, nobody has figured out why that is. Until that bug is squashed, we really should have a text based backup.

ZephyrsFury

2008-08-22 06:58:08

I've added several of these to SRL. Thanks EC. :)

EvilChicken!

2008-08-22 10:12:42

:)


Which ones?

Nava2

2008-08-22 12:10:24

Now, can a byte be used with an integer as well? So the functions you had returning bytes, what if scripts use it as an integer? Won't that cause massive outdating of scripts? Kinda like fixing the Mouse procedure.

ZephyrsFury

2008-08-23 01:49:20

From: EvilChicken!
:)

Which ones?


Main ones were:
  • Tradescreen returns an int.
  • MouseFlag has FFlag.
  • MouseItems combined

There were some others one too but I can't remember them.

From: Nava2
Now, can a byte be used with an integer as well? So the functions you had returning bytes, what if scripts use it as an integer? Won't that cause massive outdating of scripts? Kinda like fixing the Mouse procedure.


I don't think it causes any compatibility issues as from what I can see Integers can be interchanged with Bytes provided the values fall within the range of a Byte. I didn't change Integers to Byte when commiting though cos I'd rather not risk it.

Nava2

2008-08-23 14:56:37

I will test it out, give me a second or 300.

:)

program New;
var
z : byte;

function RandomByte: byte;

begin
Result := Random(2000);
end;


begin
for z := 0 to 40 do
Writeln(IntToStr(RandomByte));
end.

You won't see anything over 255, meaning, they can be interchanged quite nicely.