NiCbaZ
2008-08-02 06:34:57
Writing Functions With Math
Ok this is just a little brief tut on how to write functions with math to make them allot shorter…..
To follow this tut you will need to know the basics of SCAR/SRL.
Many people do not see this way of making a function and dont bother about it , well im here to teach you, one of the reasons why this is good is because it makes the function 100% shorter and shorter = l33ter.
My example for this tut will be 2 GameTab functions ( gametab means the tab for skills, bag ect)…
This math allows you to make it click is 7 different place with just one line of code.
Take This Function By Hy For example ( not dissing you just using it as an example)
see here
it has a new line for each gameTab, well since there are 2 rows of game tabs one at the top and one at the bottom we can shorten that to 2 lines by using simple Math..
thats is where the simple math comes in….
So what it is doing is , you pick the co-ords of the first GameTab.
so its doing the co-ords of the first GameTab + (tab) ( the number you choose in the function eg. GameTab(4);) -1 the minus 1 is so it wont go to GameTab(2) if you choose (1), Then * it by the distance between each tab simple?
i made this function for tab tab lets look at it
so basically for the first 7 tabs all i have is this…
and on the other one by hy its
better no.
Thats all my tut on this, i will add more if you find it hard to understand.
Nicbaz
Ok this is just a little brief tut on how to write functions with math to make them allot shorter…..
To follow this tut you will need to know the basics of SCAR/SRL.
Many people do not see this way of making a function and dont bother about it , well im here to teach you, one of the reasons why this is good is because it makes the function 100% shorter and shorter = l33ter.
My example for this tut will be 2 GameTab functions ( gametab means the tab for skills, bag ect)…
This math allows you to make it click is 7 different place with just one line of code.
Take This Function By Hy For example ( not dissing you just using it as an example)
function GameTab(tabnumber: Integer): Boolean;
var
c,t,tx,ty: Integer;
begin
if ((Tabnumber < 1) or (TabNumber > 15)) then
begin
srl_Warn('GameTab', IntToStr(tabnumber) + ' is not a valid GameTab', warn_AllVersions);
Result := False;
Exit;
end;
if not TabExists(tabnumber) then
begin
srl_Warn('GameTab', IntToStr(tabnumber) + ' does not exist', warn_AllVersions);
Result := False;
Exit;
end;
if tabnumber <> GetCurrentTab then
case Tabnumber of
1: MouseBox(528,171,554,198,3);
2: MouseBox(564,171,589,198,3);
3: MouseBox(598,171,622,198,3);
4: MouseBox(630,171,653,198,3);
5: MouseBox(663,171,687,198,3);
6: MouseBox(696,171,720,198,3);
7: MouseBox(729,171,760,198,3);
8: MouseBox(564,469,590,499,3);
9: MouseBox(597,469,622,499,3);
10: MouseBox(629,469,656,499,3);
11: MouseBox(662,469,689,499,3);
12: MouseBox(696,469,721,499,3);
13: MouseBox(729,469,758,499,3);
14: MouseBox(743,3,762,23,3);
15: MouseBox(527,469,555,499,3);
end;
while not(GetCurrentTab = tabnumber) and (c < 4) do
Begin
GetMousePos(tx,ty);
Mouse(tx,ty,0,0,True); // MouseBox has already added randomness ;)
Inc(c);
Wait(Random(100));
end;
t := GetCurrentTab;
Result := (t = tabnumber);
if t <> Tabnumber then
srl_Warn('GameTab', 'Failed to switch to tab'+ IntToStr(tabnumber), warn_AllVersions);
end;
see here
1: MouseBox(528,171,554,198,3);
2: MouseBox(564,171,589,198,3);
3: MouseBox(598,171,622,198,3);
4: MouseBox(630,171,653,198,3);
5: MouseBox(663,171,687,198,3);
6: MouseBox(696,171,720,198,3);
7: MouseBox(729,171,760,198,3);
8: MouseBox(564,469,590,499,3);
9: MouseBox(597,469,622,499,3);
10: MouseBox(629,469,656,499,3);
11: MouseBox(662,469,689,499,3);
12: MouseBox(696,469,721,499,3);
13: MouseBox(729,469,758,499,3);
14: MouseBox(743,3,762,23,3);
15: MouseBox(527,469,555,499,3);it has a new line for each gameTab, well since there are 2 rows of game tabs one at the top and one at the bottom we can shorten that to 2 lines by using simple Math..
function gameTab(Tab: integer);
begin
if(Tab <7) // Cheaking that tab you have selceted is lower than 7 so is it was like GameTab(3) it would do this function function gameTab(Tab: integer);
begin
if(Tab <7) then // Cheaking that tab you have selceted is lower than 7 so is it was like GameTab(3) it would do this function
begin
MouseBox(34 + (NumberOfTab - 1) * 50, 54, 34 + (NumberOfTab - 1) * 50, 75, 1);thats is where the simple math comes in….
So what it is doing is , you pick the co-ords of the first GameTab.
MouseBox(34 + (Tab - 1) * 50so its doing the co-ords of the first GameTab + (tab) ( the number you choose in the function eg. GameTab(4);) -1 the minus 1 is so it wont go to GameTab(2) if you choose (1), Then * it by the distance between each tab simple?
i made this function for tab tab lets look at it
function GameTab2(tabnumber: Integer): Boolean;
begin
if ((Tabnumber < 1) or (TabNumber > 15)) then
begin
srl_Warn('GameTab', IntToStr(tabnumber) + ' is no valid GameTab', warn_AllVersions);
Result := False;
Exit;
end;
while not(GetCurrentTab = tabnumber) do
if (tabnumber = 14) then
begin
Mouse(752, 12, 8, 8, True);
Result := (GetCurrentTab = tabnumber);
Exit;
end else
if (tabnumber <= 7) then
begin
MouseBox(537 + (tabnumber - 1) * 35, 175, 537 + (tabnumber - 1) * 35, 192, 1);
Result := (GetCurrentTab = tabnumber);
Exit;
end else
MouseBox(564 + (tabnumber - 8) * 35, 472, 564 + (tabnumber - 8 ) * 35, 490, 1);
Result := (GetCurrentTab = tabnumber);
end;
so basically for the first 7 tabs all i have is this…
MouseBox(537 + (tabnumber - 1) * 35, 175, 537 + (tabnumber - 1) * 35, 192, 1);and on the other one by hy its
1: MouseBox(528,171,554,198,3);
2: MouseBox(564,171,589,198,3);
3: MouseBox(598,171,622,198,3);
4: MouseBox(630,171,653,198,3);
5: MouseBox(663,171,687,198,3);
6: MouseBox(696,171,720,198,3);
7: MouseBox(729,171,760,198,3);better no.
Thats all my tut on this, i will add more if you find it hard to understand.
Nicbaz