SRL Archive - SRL Archives

FlagChat.scar Fixes


Tniffoc

2009-03-23 10:00:49

With the recent updates to Runescape, it is happening more and more often that a flag is still around when the character stops walking. I have added a failsafe for such an event and tested it. It worked for me. I seem to have fixed it in its entirety.


//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- ยป Mouse Flag & Chat Routines --//
//-----------------------------------------------------------------//
// * function Flag: Boolean; // * by PPLSUQBAWLZ/Odie533
// * function FlagPresent: Boolean; // * by Mutant Squirrle
// * function FlagDistance: Integer; // * by PPLSUQBAWLZ/Odie533
// * Function MFF(ax, ay, xmod, ymod: Integer):Boolean; // * by WT-Fakawi
// * Function MFNF(ax, ay, xmod, ymod: Integer):Boolean; // * by WT-Fakawi
// * procedure FFlag(Distance: Integer); // * by Wizzup? / WT-Fakawi.
// * procedure MouseFlag(cx, cy, rx, ry, FlagDist: Integer); // * by RsN edit by EvilChicken!
// * procedure SetChat(state: String; chat: Integer); // * by Wizzup? modded by WT-Fakawi and Starblaster100
// * procedure SetAllChats(Pub, Priv, Clan, Trade, Assist: string); // * by ZephyrsFury
// * procedure ChatsOff; // * by Starblaster100

{*******************************************************************************
function Flag: Boolean;
By: PPLSUQBAWLZ/Odie533
Description: Waits while flag exists.
*******************************************************************************}

function Flag: Boolean;
var
timeout, x, y: Integer;
begin
if (FindColor(x, y, 255, MMX1, MMY1, MMX2, MMY2)) then
begin
Result := True;
repeat
Wait(100);
if (SRL_Procs[srl_AntiBan] <> nil) then
SRL_Procs[srl_AntiBan]();
timeout := timeout + 1;
until (not FindColor(x, y, 255, MMX1, MMY1, MMX2, MMY2)) or (timeout > 300);
end;
end;

{*******************************************************************************
function FlagPresent: Boolean;
By: Mutant Squirrle
Description: T/F depending on flag exist.
*******************************************************************************}

function FlagPresent: Boolean;
var
x, y: integer;
begin
Result := FindColor(x, y, 255, MMX1, MMY1, MMX2, MMY2);
end;

{*******************************************************************************
function FlagDistance: Integer;
By: PPLSUQBAWLZ/Odie533
Description: Returns distance in pixels your char dot is from flag on mini-map
*******************************************************************************}

function FlagDistance: Integer;
var
x, y: Integer;
begin
If findcolor(x, y, 255, MMX1, MMy1, MMX2, MMY2) Then
Result := Distance(MMCX, MMCY, x + 1, y + 14);
end;

{*******************************************************************************
Function MFF(ax, ay, xmod, ymod: Integer):Boolean;
By: WT-Fakawi
Description: If the flag is not present it will click at (ax, ay) increasing by
(xmod, ymod) 5 times or until the flag appears.
*******************************************************************************}

Function MFF(ax, ay, xmod, ymod: Integer):Boolean;
var
TT, i, xx, yy, x, y, BreakOutTime: Integer;
begin
if (not LoggedIn) then Exit;
if (not (FlagPresent)) then
begin
xx := ax - xmod;
yy := ay - ymod;
MarkTime(BreakOutTime);
for i := 0 to 4 do
begin
xx := xx + xmod;
yy := yy + ymod;
if rs_OnMiniMap(xx, yy) then
Mouse(xx, yy, 2, 2, True)
else
Continue;
Wait(50);
MarkTime(TT);
repeat
Wait(10);
if FindColor(x, y, 255, MMx1, MMy1, MMx2, MMy2) then
begin
Result := True
Exit;
end;
until TimeFromMark(TT) > 3000;
end;
Result := False;
end;
end;

{*******************************************************************************
Function MFNF(ax, ay, xmod, ymod: Integer):Boolean;
By: WT-Fakawi
Description: Like MFF except it will click even if the flag is present when the
function is called.
*******************************************************************************}

Function MFNF(ax, ay, xmod, ymod: Integer):Boolean;
var
TT, i, xx, yy, x, y: Integer;
begin
Result := False;
if (not LoggedIn) then Exit;
xx := ax - xmod;
yy := ay - ymod;
for i := 0 to 4 do
begin
xx := xx + xmod;
yy := yy + ymod;
if rs_OnMiniMap(xx, yy) then
Mouse(xx, yy, 2, 2, True)
else
Continue;
Wait(50);
MarkTime(TT);
repeat
Wait(100);
if FindColor(x, y, 255, MMx1, MMy1, MMx2, MMy2) then
begin
Result := True;
Exit;
end;
until TimeFromMark(TT) > 3000;
end;
end;


{*******************************************************************************
procedure FFlag(Distance: Integer);
By: Wizzup? / WT-Fakawi.
Description: Waits until Flag is within "Distance" distance.
*******************************************************************************}

function FFlag(Dist: Integer): boolean;
var
XK, YK, XL, YL, x, y: Integer;
var
T1, T2: Extended;
timeout: Integer;
begin
Result := False;
T1 := GetTickCount;
MarkTime(timeout);
repeat
if (not LoggedIn) then Exit;
T2 := GetTickCount;
Wait(100);
if FindColor(x, y, 255, MMX1, MMY1, MMX2, MMY2) Then
if (Dist > Distance(MMCX, MMCY, x + 1, y + 14)) then
begin
Result := True;
Break;
end;
Wait(100);
if T2 - T1 > 30000 then
begin
Result := False;
if FindColor(XL, YL, 255, MMX1, MMY1, MMX2, MMY2) then
MFNF(XL, YL, 1, 1)
else
begin
Mouse(MMCX, MMCY, 0, 0, True);
end;
Exit;
end;
if Random(20) = 1 Then IdleTime(500, 1000, 0.01);
if (SRL_Procs[srl_AntiBan] <> nil) then
SRL_Procs[srl_AntiBan]();
if(TimeFromMark(timeout) > 20000) then
begin
Exit;
end;
until (not FindColor(XK, YK, 255, MMX1, MMY1, MMX2, MMY2));
end;

{*******************************************************************************
procedure MouseFlag(cx, cy, rx, ry, FlagDist: Integer);
By: RsN edit by EvilChicken!
Description: Mouse and Flag combined into one easy procedure.
*******************************************************************************}

procedure MouseFlag(cx, cy, rx, ry, FlagDist: Integer);
var
i: Integer;
begin
if (not LoggedIn) then Exit;
Mouse(cx, cy, rx, ry, True);
while (not FlagPresent) and (i < 10) do
begin
Wait(100);
Inc(i);
end;
FFlag(FlagDist);
Wait(300 + Random(200));
end;

{*******************************************************************************
procedure SetChat(state: String; chat: Integer);
By: Wizzup? modded by WT-Fakawi and Starblaster100
Description: Sets Chat to desired state
*******************************************************************************}

procedure SetChat(state: string; chat: Integer);
var
x, y, mx, my, Color: Integer;
begin
case chat of
1: mx := 145;
2: mx := 200;
3: mx := 260;
4: mx := 320;
5: mx := 373;
else
begin
srl_Warn('SetChat', 'chat(' + IntToStr(chat) + ') does not exist.', warn_AllVersions);
Exit;
end;
end;
my := 496;
case LowerCase(State) of
'on': begin Color := 65280; State :='On'; end;
'off': begin Color := 255; State :='Off'; end;
'hide': begin Color := 16776960; State :='Hide'; end;
'friends': begin Color := 65535; State :='Friends'; end;
else srl_Warn('SetChat', state + ' does not exist.', warn_AllVersions);
end;
if not FindColor(x, y, Color, mx - 10, my - 10, mx + 10, my + 10) then
begin
Mouse(mx, my, 8, 8, False);
Wait(450 + Random(175));
ChooseOption(State);
end;
end;

{*******************************************************************************
procedure SetAllChats(Pub, Priv, Clan, Trade, Assist: string);
By: ZephyrsFury
Description: Sets all the chats to a particular state in one simple procedure.
Leave the parameter as '' if you wish to leave the chat as it is:
Example: SetAllChats('on', 'friends', '', 'off', '');
*******************************************************************************}

procedure SetAllChats(Pub, Priv, Clan, Trade, Assist: string);
var
States: TStringArray;
II: Integer;
begin
if (not(LoggedIn)) then Exit;
States := ['', Pub, Priv, Clan, Trade, Assist];
for II := 1 to 5 do
begin
if (States[II] = '') then Continue;
States[II] := Lowercase(States[II]);
if ((II <> 1) and (States[II] = 'hide')) or ((States[II] <> 'on') and
(States[II] <> 'friends') and (States[II] <> 'off') and (States[II] <> 'hide')) then
begin
srl_Warn('SetAllChats', 'ChatState ''' + States[II] + ''' does not exist for chat ''' + IntToStr(II) + ''' ', warn_AllVersions);
Continue;
end;
SetChat(States[II], II);
end
end;

{*******************************************************************************
procedure ChatsOff;
By: Starblaster100
Description: Sets all Chats to off.
*******************************************************************************}

Procedure ChatsOff;
var
i: Integer;
Begin
For i := 1 to 5 do
SetChat('off', i);
end;

Nava2

2009-03-23 10:12:38

What did you change…?

elmotheskaat

2009-03-23 10:12:55

Great, hope it will work. I'll give it a try in a minute.
Thanks!

Tniffoc

2009-03-23 10:24:52

From: Nava2
What did you change…?


I added a timeout to FFlag.

Nava2

2009-03-23 10:46:36

 T1 := GetTickCount;
MarkTime(timeout);
repeat
if (not LoggedIn) then Exit;
T2 := GetTickCount;

This is a time out as well..

zealkctro

2009-03-23 11:01:39

what will the changes do ?

Tniffoc

2009-03-23 11:12:03

From: emuleuser12345
what will the changes do ?

They will create a timeout in FFlag so that characters won't get stuck.

From: Nava2
 T1 := GetTickCount;
MarkTime(timeout);
repeat
if (not LoggedIn) then Exit;
T2 := GetTickCount;

This is a time out as well..

That timeout wasn't working for my characters. That's why I added the new one.

EvilChicken!

2009-03-23 11:36:06

Why did you post the whole include if you added one (AFAIK) line?

Tniffoc

2009-03-23 11:42:51

From: EvilChicken!
Why did you post the whole include if you added one (AFAIK) line?

At first, I thought that more functions than FFlag needed to be edited. Later, I found this was not the case. It was more than 1 line btw.

EvilChicken!

2009-03-23 11:48:51

Still doesn't justify posting the whole include.
Supposing Flag and FFlag were the only ones you fixed, your statement actually goes against it.

elmotheskaat

2009-03-23 11:52:49

At least he fixed the include. Pasting the whole include or a part of it doesn't really make a difference, does it?

Tniffoc

2009-03-23 11:55:01

From: EvilChicken!
Still doesn't justify posting the whole include.
Supposing Flag and FFlag were the only ones you fixed, your statement actually goes against it.


I posted the whole thing to make life easier on people k?

elmotheskaat

2009-03-23 11:57:09

And I thank you for it =) ++

WT-Fakawi

2009-03-23 12:47:03

I believe FFlag has a 30 seconds timeout. After those 30 secs it performs a MFNF, meaning it will click on the flagcolor if it sees the flag is still in the MM.
So, FFlag has a timeout already build in. All you need to do is wait 30 seconds :)

Sir R. M8gic1an

2009-03-23 13:18:51

Fakawi, that is no longer viable because of this:

http://www.villavu.com/forum/showthread.php?p=541158

~RM

WT-Fakawi

2009-03-23 13:37:29

a ok. didnt know about that indeed!

Naum

2009-03-23 14:13:36

Yeah FFlag just mucks up, Thanks for this.

Tniffoc

2009-03-23 15:55:37

From: NaumanAkhlaQ
Yeah FFlag just mucks up, Thanks for this.


Woo! Glad it's working.

Sandstorm

2009-03-23 21:22:53

Perhaps add a GetDistance or whatever the function is, and check it 3 seconds later. If the distance is the same, your character isn't moving?

~Sandstorm

wombocombo

2009-03-23 21:32:07

great job this was something that was messing up many of the scripts that we all use and you solved it quickly and effectivly (+rep)

Tniffoc

2009-03-23 21:51:18

From: Sandstorm
Perhaps add a GetDistance or whatever the function is, and check it 3 seconds later. If the distance is the same, your character isn't moving?

~Sandstorm

I thought about that, the problem is that, at least in my case, the minimap shifts around sometimes. This is simpler and more failproof imo.

Nava2

2009-03-23 22:37:31

I posted a Flag fix as well in my Core changes thread.

By the way… Why did everyone attack poor Tniffoc. :(

Tniffoc

2009-03-23 22:45:56

From: Nava2
I posted a Flag fix as well in my Core changes thread.

By the way… Why did everyone attack poor Tniffoc. :(


LOL! I wasn't attacked, well, kind of. I just noticed a changes forum. I'll have the thread moved there.

Sir R. M8gic1an

2009-03-24 03:32:01

From: Tniffoc
LOL! I wasn't attacked, well, kind of. I just noticed a changes forum. I'll have the thread moved there.



I wonder what this changes forum is as i failed to find it. If it is in the Public SVN forum please ask one of the developers to do it as it is up to them to decide where snippets of new code are fit in this subsection of srl.

~RM

ZephyrsFury

2009-03-24 05:35:01

What you've added is already part of the procedure:


if T2 - T1 > 30000 then
begin
Result := False;
if FindColor(XL, YL, 255, MMX1, MMY1, MMX2, MMY2) then
MFNF(XL, YL, 1, 1)
else
begin
Mouse(MMCX, MMCY, 0, 0, True);
end;
Exit;
end;


That will attempt to reclick the flag after 30 seconds. However with the new update that won't work any more and the flag will still appear no matter if the tile is walkable or not. So a better idea would be to check if the distance between the flag and the player changes in a certain time frame. If it doesn't then the flag is stuck and we exit.

Redeye_6

2009-03-29 23:16:38

How do you add this to a script?? help? im new…

xiaoina

2009-03-30 00:38:55

you add it to
C:\Program Files\SCAR 3.15\Includes\SRL\SRL\core


says it right at the top of this thread…

Sir R. M8gic1an

2009-03-30 02:38:16


Function FlagStuck: boolean;
var dist, Time: integer;
begin
dist := FlagDistance;

if dist <= 0 then
begin
Result := false;
exit;
end;

Time := GetSystemTime;
while (GetSystemTime - Time < 10000) do
if FlagDistance <> dist then
begin
Result := false;
break;
end;

if FlagDistance = dist then
Result := true;
end;

FFlag can also be done in this fashion.
This will avoid chaos if the flag is stuck somewhere you can't walk.

~RM

JPHamlett

2009-03-30 08:02:40

ok how do i stop the code from jsut being in a straight line

exaple


this
is
the
code

and when i copy that in to scar it look slike this

thisisthecode

any help would be greatly apreciated

Cazax

2009-03-30 18:37:15

We have also need to remove these lines from autocolor.scar:
Flag;
So it doesn't wait for ever unless flag also gets changed. It took me a few hours to figure that out :(

JPHamlett

2009-03-30 20:22:05

can u add the fille to the post and then il go in and save it tot he correct spot plz cause copy and pasting ocdes doenst work for me look at other post for the problem

Redeye_6

2009-04-03 19:11:46

K… ive added this code into the core folder but it still messes up??? it still gets no banks.. any1 help?

Tniffoc

2009-04-03 19:41:16

What do you mean by "gets no banks"?

Redeye_6

2009-04-03 21:27:19

What i mean is …. it still gets stuck the FLAG…. and it causes no banks…

Tniffoc

2009-04-03 22:11:07

In the script, change this:

Flag;

To This:

FFlag(0);

Redeye_6

2009-04-04 00:02:34

From: Tniffoc
In the script, change this:

Flag;

To This:

FFlag(0);


Which script are you talking about?.. Because there are many fixes out but i dont know which one is most effective one. Thanks.
Also you add the script in (C:\Program Files\SCAR 3.15\Includes\SRL\SRL\core) right? Just making sure.. = ]

Nava2

2009-04-04 00:58:08

Please see the sticky in this forum for the fixes.

gamemaste789

2009-04-14 18:07:39

where do u save it too

Tniffoc

2009-04-14 20:53:07

OMG! There is an official release now. I'm going to get this closed. This was a temporary fix.

Nava2

2009-04-14 21:49:12

Done.