SRL Archive - SRL Archives

Friends.scar (working)


Shuttleu

2008-06-01 02:48:01

i have got all the functions and procedures in Friends.scar to work

//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- ยป Friends Routines --//
//-----------------------------------------------------------------//

// * Function NumberOfOnlineFriends: Integer; // * by Wizzup?
// * Procedure AddFriend(Friend: String); // * by Wizzup?
// * Procedure DeleteFriend(Friend: String); // * by Wizzup?
// * Procedure AddIgnore(Friend: String); // * by Wizzup?
// * Procedure DeleteIgnore(Friend: String); // * by Wizzup?
// * Function GetFriendTexts: TStringArray; // * by n3ss3s
// * Function FromFriend(Friend: String): String; // * by n3ss3s
// * Function FromFriendMulti(Friend: String): TStringArray; // * by n3ss3s
// * Function GetChatterOfLine(Line: String): String; // * by n3ss3s
// * Function RespondToWith(rTo, rWith: String): Boolean; // * by n3ss3s
// * Function HasResponded(Friend: String): Boolean; // * by n3ss3s


type
TFriends = Record
Name: String;
World: String;
IsOnline: Boolean;
YourWorld: Boolean;
End;

Var
Friends : Array[0..12] Of TFriends;
FriendChars : integer;


{*******************************************************************************
function FriendName(PlayerNumber: Integer): String;
By: Wizzup?
Description: Gets FriendsName and saves it to a string.
*******************************************************************************}
Function FriendName(PlayerNumber: Integer): String;
Begin
FriendChars:=(LoadChars2(AppPath+'Fonts\FriendChars\'));
Result := Trim(GetTextAtEx(562, 233 + (PlayerNumber * 15), 45, FriendChars, True, False, 0,
2, 16777215, 20, False, tr_NormalChars));
End;

{*******************************************************************************
function FriendWorld(PlayerNumber: Integer; SameWorld: Boolean) : String;
By: Wizzup?
Description: Returns current world of a friend.
First Friend = 0
Last Friend = 11
*******************************************************************************}
function FriendWorld(PlayerNumber: Integer; SameWorld: Boolean) : String;

Var
I : Integer;
Begin
FriendChars:=(LoadChars2(AppPath+'Fonts\FriendChars\'));
If SameWorld Then
Result := Trim(GetTextAtEx(665, 233 + (PlayerNumber * 15), 45, FriendChars, True, False, 0,
2, 65280, 20, False, tr_NormalChars))
Else
Result := Trim(GetTextAtEx(665, 233 + (PlayerNumber * 15), 45, FriendChars, True, False, 0,
2, 65535, 20, False, tr_NormalChars));

I := Pos('orld', Result);
If I <> 0 Then
Begin
Delete(Result, 1, 5);
End
Else Result := '';
End;

{*******************************************************************************
procedure GetFriends;
By: Wizzup?
Description: Returns first 12 friends World/Status/Name into the Friends Record.

TFriends = Record
Name: String;
World: String;
IsOnline: Boolean;
YourWorld: Boolean;

*******************************************************************************}
Procedure GetFriends;

Var
I, iX, iY: Integer;
Begin
GameTab(8);
Wait(500);
For I := 0 To 11 Do
Begin
Friends[i].Name := FriendName(I);
If FindColor(iX, iY, 65280, 665, 233 + (I * 15), 718, 244 + (I * 15)) Then
Begin
Friends[i].IsOnline := True;
Friends[i].YourWorld := True;
Friends[i].World := FriendWorld(I, True);
End
Else If FindColor(iX, iY, 65535, 665, 233 + (I * 15), 718, 244 + (I * 15)) Then
Begin
Friends[i].IsOnline := True;
Friends[i].YourWorld := False;
Friends[i].World := FriendWorld(I, False);
End;
End;
End;

{*******************************************************************************
function FriendIsOnline(Var iX, iY: Integer; Friend: String): Boolean;
By: Wizzup?
Description: Returns coordinate of Online friend, if Online.
"Friend:String" May also be a part of the whole name, like Players[].Nick.
*******************************************************************************}
Function FriendIsOnline(Var iX, iY: Integer; Friend: String): Boolean;

Var
I : Integer;
Begin
GetFriends;
Begin
If IsTextInAreaEx(MIX1, MIY1, MIX2, MIY2, iX, iY, Capitalize(Friend), 5, FriendChars, false, false, 0, 0, 16777215) Then
Begin
Result := True;
iX := 562 + Random(130);
iY := 233 + (15 * I)+ Random(13);
End;
End;
End;

{*******************************************************************************
function MessageFriendEx(Friend, TheMessage: String): Boolean;
By: Wizzup?
Description: If a certain friend is online, sends them a message.
"Friend:String" May also be a part of the whole name, like Players[].Nick.
*******************************************************************************}
Function MessageFriendEx(Friend, TheMessage: String): Boolean;

Var
iX, iY : Integer;

Begin
If FriendIsOnline(iX, iY, LowerCase(Friend)) Then
Begin
Result := True;
Mouse(iX, iY, 0, 0, True);
Wait(100 + Random(100))
TypeSend(TheMessage);
End
Else WriteLn('The friend is not online.');
End;
{*******************************************************************************
function NumberOfOnlineFriends: Integer;
By: Wizzup?
Description: Returns # of friends online from 0-11.
Is actually 1-12, but the array only goes from 0 to 11 at the moment.
*******************************************************************************}
Function NumberOfOnlineFriends: Integer;

Var
I: Integer;
Begin
GetFriends;
For I := 0 To 11 Do
If Friends[i].IsOnline Then
Result := Result + 1;
End;

{*******************************************************************************
procedure AddFriend(Friend: String);
By: Wizzup?
Description: Add's 'Friend' to your friends list.
*******************************************************************************}
Procedure AddFriend(Friend: String);

Begin
GetFriends;
Mouse(575 + Random(45), 435 + Random(20), 0, 0, True);
Wait(100 + Random(100));
TypeSend(Friend);
Wait(1000 + Random(500));
End;

{*******************************************************************************
procedure DeleteFriend(Friend: String);
By: Wizzup?
Description: Delete's 'Friend' from your friends list.
*******************************************************************************}
Procedure DeleteFriend(Friend: String);

Begin
GetFriends;
Mouse(656 + Random(45), 435 + Random(20), 0, 0, True);
Wait(100 + Random(100));
TypeSend(Friend);
Wait(1000 + Random(500));
End;

{*******************************************************************************
procedure AddIgnore(Friend: String);
By: Wizzup?
Description: Add's 'Friend' to your ignore list.
*******************************************************************************}
Procedure AddIgnore(Friend: String);

Begin
GameTab(9);
Mouse(575 + Random(45), 435 + Random(20), 0, 0, True);
Wait(100 + Random(100));
TypeSend(Friend);
Wait(1000 + Random(500));
End;

{*******************************************************************************
procedure DeleteIgnore(Friend: String);
By: Wizzup?
Description: Deletes 'Friend' from Ignore list.
*******************************************************************************}
Procedure DeleteIgnore(Friend: String);

Begin
GameTab(9);
Mouse(656 + Random(45), 435 + Random(20), 0, 0, True);
Wait(100 + Random(100));
TypeSend(Friend);
Wait(1000 + Random(500));
End;

{*******************************************************************************
Function GetFriendTexts: TStringArray;
By: n3ss3s
Description: Returns all the friend chats, even the empty lines.
*******************************************************************************}
Function GetFriendTexts: TStringArray;
//* Result[0] is the first PM chatline counting from up to down.
//* Closest one to chatbox is Result[4]
//* There are total 5 PM chatlines visible once.
Var
Sx, Sy, I: Integer;
Begin
FriendChars:=(LoadChars2(AppPath+'Fonts\FriendChars\'));
sx := 4;
sy := 269;
SetArrayLength(Result, 5);
For I := 0 To 4 Do
Begin
Result[i] := GetTextAtEx(sx, sy + 13 * i, 0, FriendChars, false, false, 0, 0, 16776960, 70, false, tr_allchars);
Writeln(Result[i]);
End;
End;


Function GetChatterOfLine(Line: String): String; forward;

{*******************************************************************************
Function FromFriend(Friend: String): String;
By: n3ss3s
Description: Returns the first occurence of text sent by friend Friend.
*******************************************************************************}
Function FromFriend(Friend: String): String;
Var
GFT: TStringArray;
I: Integer;
Begin
GFT := GetFriendTexts;
For I := 0 To High(GFT) Do
Begin
If GetChatterOfLine(GFT[i]) = Friend Then
Begin
Result := GFT[i];
Result := Copy(Result, Pos(':', Result), Length(Result));
Exit;
End;
End;
End;

{*******************************************************************************
Function FromFriendMulti(Friend: String): TStringArray;
By: n3ss3s
Description: Returns all the occurences of text sent by friend Friend.
*******************************************************************************}
Function FromFriendMulti(Friend: String): TStringArray;
Var
GFT: TStringArray;
I: Integer;
Begin
GFT := GetFriendTexts;
For I := 0 To High(GFT) Do
Begin
If GetChatterOfLine(GFT[i]) = Friend Then
Begin
Result[i] := GFT[i];
Result[i] := Copy(Result[i], Pos(':', Result[i]), Length(Result[i]));
End;
End;
End;

{*******************************************************************************
Function GetChatterOfLine(Line: String): String;
By: n3ss3s
Description: Returns the friend who sent the text Line.
*******************************************************************************}
Function GetChatterOfLine(Line: String): String;
Var
A, B: String;
Begin
A := Copy(Line, 1, Pos(':', Line));
B := Copy(Line, 1, Pos(' ', A));
Result := Replace(A, B, '');
Result := Replace(Result, ':', '');
End;

{*******************************************************************************
Function RespondToWith(rTo, rWith: String): Boolean;
By: n3ss3s
Description: Returns true if could respond to message rTo with rWith.
*******************************************************************************}
Function RespondToWith(rTo, rWith: String): Boolean;
Var
GFT: TStringArray;
I: Integer;
Begin
GFT := GetFriendTexts;
For I := 0 To High(GFT) Do
If Pos(rTo, GFT[i]) > 0 Then
Result := MessageFriendEx(GetChatterOfLine(GFT[i]), rWith);
End;

{*******************************************************************************
Function HasResponded(Friend: String): Boolean;
By: n3ss3s
Description: Returns true if friend Friend has responded to you.
*******************************************************************************}
Function HasResponded(Friend: String): Boolean;
Var
GFT: TStringArray;
I: Integer;
Begin
GFT := GetFriendTexts;
Result := True;
For I := 0 To High(GFT) Do
If Pos('From '+Friend, GFT[i]) > 0 Then
Exit;
Result := False;
End;
but you will need these chars and you will need to place them into the folder called fonts in the scar folder

Note i didnt edit all of the functions i just cant remember what ones i edited to get it to work

when scar gets updated to scar 3.16 then just take out all of these

FriendChars:=(LoadChars2(AppPath+'Fonts\FriendChars\'));

~shut

ZephyrsFury

2008-06-01 03:06:33

I think you mean Friends.scar and why is this the 3rd thread I've seen on this subject?

EDIT: Why do you have to make a new set of chars? Doesn't SmallChars work?
EDIT2: No you're right SmallChars won't work. ;)

EDIT3: Changed the thread name for you if you don't mind.

Shuttleu

2008-06-01 05:22:06

yea small chars wont work plus only lowecase, capitals ans numbers will work for the usernames

~shut

EDIT: nope i dont mind i forgot that it was friends not players

Harry

2008-06-05 17:24:18

Excellent Mr. Burns, excellent…

Good work, now let's have Freddy add those chars into SCAR 3.16 :)

ZephyrsFury

2008-06-06 01:51:56

I believe its already done. When Freddy releases SCAR 3.16 with the new chars we'll update SRL. Until then if you need Friends.scar to work just download the chars and modify it yourself.

Closed.

Markus

2008-06-06 05:36:02

Reopened just in case he wants to change something, so he doesn't need to create a new thread.

ZephyrsFury

2008-06-06 05:39:44

He has his other thread. Thats partly why I closed this one.

EDIT: NVM just realised his other thread is different…

Dusk412

2008-07-09 01:10:04

This is kind of back a ways but your Number of friends online function and some other stuff that would either be useful in this include or is the same as stuff you have are in the RC include at the moment. Don't know if you knew that or not.

Good stuff.

- Dusk412