PDA

View Full Version : Writing Functions With Math



NiCbaZ
08-02-2008, 10:34 AM
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)




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) * 50

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

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

noidea
08-02-2008, 05:24 PM
WOW, this is a nice tutorial. can you explain how to use MouseBox?

EvilChicken!
08-02-2008, 06:44 PM
God dammit, noidea.
Just look in your includes and don't double-post!
{************************************************* ******************************
procedure MouseBox(x1, y1, x2, y2: Integer; ClickType: Integer);
By: SKy Scripter and Nielsie95
Description: Moves mouse into a random position in the box. Clicks if told to.
************************************************** *****************************}

procedure MouseBox(x1, y1, x2, y2: Integer; ClickType: Integer);
begin
case ClickType of
1 : Mouse(RandomRange(x1, x2), RandomRange(y1, y2), 0, 0, True);
2 : Mouse(RandomRange(x1, x2), RandomRange(y1, y2), 0, 0, False);
3 : MMouse(RandomRange(x1, x2), RandomRange(y1, y2), 0, 0);
end;
end;

In overwrite.scar.

noidea
08-02-2008, 07:24 PM
I removed the post. Sorry I double-posted but does using the edit button send the thread to the front of the list like another post?

lordsaturn
01-29-2009, 10:29 AM
You should add some maths about using trigonometry with the minimap. :)

Edit: Super bump on request from nicbaz

NiCbaZ
01-29-2009, 10:31 AM
YAY thanks trigonometry i have not studdied that yet ;)

Kyle Undefined
01-29-2009, 10:32 AM
Thanks, told you I would bump it for you in IRC. Thanks for showing me this ;) Really makes since.

~Camo

NiCbaZ
01-29-2009, 10:33 AM
Thank you as well, also im glad i could help :)

Awkwardsaw
07-05-2009, 03:42 AM
oo. looks fun :P i'll be trying to use this