SRL Archive - SRL Archives

Magic.scar functions


Cazax

2008-06-10 10:31:04

Magic.scar got outdated. Why? Jagex changed the colors, etc and they dont work. So i made functions to avoid outdated bitmaps:

Function SpellBox(Spell : Integer): TBox;
Var
SpellX : Integer;
Begin
If Not InRange(Spell, 1, 67) Then
Begin
srl_Warn('SpellBox', 'Invalid Spell', Warn_AllVersions);
Exit;
End;
SpellX := Spell;
While SpellX > 7 Do
DecEx(SpellX, 7);
Result.X1 := 540 + (SpellX * 21);
Result.Y1 := 205 + (Ceil(SpellX / 7.0) * 25);
Result.X2 := 560 + (SpellX * 21);
Result.Y2 := 221 + (Ceil(SpellX / 7.0) * 25);
End;

Function SpellCoords(Spell : Integer): TPoint;
Var
Box : TBox;
Begin
If Not InRange(Spell, 1, 67) Then
Begin
srl_Warn('SpellCoords', 'Invalid Spell', Warn_AllVersions);
Exit;
End;
Box := SpellBox(Spell);
Result.X := (Box.X1 + Box.X2) Shr 1;
Result.Y := (Box.Y1 + Box.Y2) Shr 1;
End;
Usage:
Procedure CastLumby;
Var
Box : TBox;
Begin
Box := SpellBox(1);
Gametab(7);
//If SpellExists(1) Then
MouseBox(Box.X1, Box.Y1, Box.X2, Box.Y2);
End;
Or:
Procedure CastLumby;
Var
TP : TPoint;
Begin
TP := SpellCoords(1);
Gametab(7);
//If SpellExists(1) Then
Mouse(TP.X, TP.Y, 4, 4, True);

Now we just need a checker if the spell exists…
Or more tolerance.

PS: I made those functions for more randomness while clicking :) SpellBox covers all the spell :rolleyes:


Test them!

Freddy1990

2008-06-10 14:13:41

Why do people keep insisting on capitalising the first letter of keywords? It's wrong! And above all, ugly as hell!

ShowerThoughts

2008-06-10 14:16:49

From: Freddy1990
Why do people keep insisting on capitalising the first letter of keywords? It's wrong! And above all, ugly as hell!


It is wrong but I like(d) it :)

Freddy1990

2008-06-10 14:21:20

From: Hermpie
It is wrong but I like(d) it :)



Appart from that they look good, if someone can confirm they work (and that the current ones are actually outdated, I don't really keep up), I think they could go in SRL (unless some other dev thinks I'm wrong :p) (well, the coordinate calculating might be un-srl-like, not rly sure :p)

Sir R. M8gic1an

2008-06-10 14:32:52


SpellX := Spell;
While SpellX > 7 Do
DecEx(SpellX, 7);



SpellX := (Spell mod 7);

GJ

but i think spell coords is disnecessary.


procedure CastSpell(spell:integer);
var TB: TBox;
begin
TB := SpellBox(spell);
//if bitmap or color or something
MouseBox(TB.x1, TB.y1, TB.x2, TB.y2, 1);
end;


~RM

nielsie95

2008-06-10 16:53:34

From: Rasta Magician

SpellX := Spell;
While SpellX > 7 Do
DecEx(SpellX, 7);



SpellX := (Spell mod 7);

~RM



program New;
var
x, y: Integer;
begin
x := 7;
y := 7;
while (x > 7) do
x := x - 7;
y := y mod 7;
WriteLn(IntToStr(x)+', '+IntToStr(y));
end.

It's not the same.

Cazax

2008-06-10 17:02:35

From: Freddy1990
Why do people keep insisting on capitalising the first letter of keywords? It's wrong! And above all, ugly as hell!

Nah :)

From: Hermpie
It is wrong but I like(d) it :)
Glad you liked it

From: Freddy1990

Appart from that they look good, if someone can confirm they work (and that the current ones are actually outdated, I don't really keep up), I think they could go in SRL (unless some other dev thinks I'm wrong :p) (well, the coordinate calculating might be un-srl-like, not rly sure :p)

Well you can test it :)

From: Rasta Magician

but i think spell coords is disnecessary.

procedure CastSpell(spell:integer);
var TB: TBox;
begin
TB := SpellBox(spell);
//if bitmap or color or something
MouseBox(TB.x1, TB.y1, TB.x2, TB.y2, 1);
end;
~RM

I know, maybe its uselles, but some people dont know TBoxes. Look at Inventory.scar for example.

Sir R. M8gic1an

2008-06-10 17:25:52

From: nielsie95

program New;
var
x, y: Integer;
begin
x := 7;
y := 7;
while (x > 7) do
x := x - 7;
y := y mod 7;
WriteLn(IntToStr(x)+', '+IntToStr(y));
end.

It's not the same.


right, well spotted.
if y = 0 then y:= 7;


program New;
var
x, y, time: Integer;
begin
x := 7000000;
y := 7000000;
time:=GetSystemTime;
while (x > 7) do
x := x - 7;
writeln('while took: '+IntToStr(GetSystemTime-time));
time:=GetSystemTime;
y := y mod 7;
if y=0 then y:=7;
writeln('mod took: '+IntToStr(GetSystemTime-time));
WriteLn(IntToStr(x)+', '+IntToStr(y));
end.

From: debug

Successfully compiled (126 ms)
while took: 7219
mod took: 0
7, 7
Successfully executed


but i guess it wouldn't cus there aren't that many spells. i tried with 70, both took 0 ms. mod still looks better :p

~RM

Nava2

2008-06-10 18:21:08

From: Freddy1990
Why do people keep insisting on capitalising the first letter of keywords? It's wrong! And above all, ugly as hell!


Agreed.

Wouldn't using bmp's of the Magic panel be better? With your functions, maybe a co-operating function which will take a string and convert it into the necessary integer for the spell?

function SpellStrToBox(spell:string):TBox;
var i : integer;
begin
case Lowercase(spell) of
'home teleport' : i := 1;
//Blah blah you know the rest...
end;
Result := SpellBox(i);
end;

Also, maybe setting an AncientMagicks.scar would be helpful? Also lunar?

Nava2

Cazax

2008-06-10 18:26:48

From: Nava2
Agreed.

Wouldn't using bmp's of the Magic panel be better? Also, maybe setting an AncientMagicks.scar would be helpful? Also lunar?

Nava2


Using a bmp of the magic panel would be used to find if the magic can be casted. But i made SpellBox to make it more randomness with mousebox. My main can't use AncientMagiks and Lunar :( So i cant help with that :redface:

Freddy1990

2008-06-11 17:52:17

From: Cazax
Nah :)

Well you can test it :)


It's wrong AND ugly ;) I stick by that

And I can't test it because for one I don't play RS and I haven't in years and 2 I don't macro RS because I think it's a waste of power, bandwidth and cpu lifetime seeing I don't play RS and finally.