SRL Archive - OSR Help

TIntegerArray Question


Bionicle

2010-01-29 19:27:49

Ok. I have a TIntegerArray, is there any way I can have it in a For..To..Do loop from the first integer to the last in order? I did a quick look through the WizzyPlugin, nothing caught my eye…help?

Wanted

2010-01-29 19:31:54

From: bionicle1800
Ok. I have a TIntegerArray, is there any way I can have it in a For..To..Do loop from the first integer to the last in order? I did a quick look through the WizzyPlugin, nothing caught my eye…help?


You mean, the normal first order?

for I := to High(IntArr) do
//stuff

or do you mean by size?

QuickSort is the best… it will do [0] big, last small… so you could just InvertTPA or do [High(Arr)]

Not sure what you want though based on that question

Bionicle

2010-01-29 19:35:25

k ill explain what i'm trying to do.
im making a dropping procedure for my script.
i have a few TIntegerArrays:
  WayDrop1 := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28];

WayDrop2 := [1, 5, 9, 13, 17, 21, 25, 2, 6, 10, 14, 18, 22, 26, 3, 7, 11, 15,
19, 23, 27, 4, 8, 12, 16, 20, 24, 28];

WayDrop3 := [1, 5, 9, 13, 17, 21, 25, 26, 22, 18, 14, 10, 6, 2, 3, 7, 11, 15,
19, 23, 27, 28, 24, 20, 16, 12, 8, 4];

WayDrop4 := [4, 3, 8, 2, 7, 12, 1, 6, 11, 16, 5, 10, 15, 20, 9, 14, 19, 24, 13,
18, 23, 28, 17, 22, 27, 21, 26, 25];

WayDrop5 := [4, 2, 7, 12, 5, 10, 15, 20, 13, 18, 23, 28, 21, 26, 25, 17, 22,
27, 9, 14, 19, 24, 1, 6, 11, 16, 3, 8];
Each integer representing an InvBox. I tryed this:
  Case Random(5) Of
0: Begin
L := Low(WayDrop1);
H := High(WayDrop1);
End;
1: Begin
L := Low(WayDrop2);
H := High(WayDrop2);
End;
2: Begin
L := Low(WayDrop3);
H := High(WayDrop3);
End;
3: Begin
L := Low(WayDrop4);
H := High(WayDrop4);
End;
4: Begin
L := Low(WayDrop5);
H := High(WayDrop5);
End;
End;

and
  For I := L To H Do
but it does it in order from the first to the last (eg, if the array starts with 4 and ends with 8, it does 4, 5, 6, 7, 8 instead of 4, 2, 7, 12, 5, 10, 15, 20, 13, 18, 23, 28, 21, 26, 25, 17, 22, 27, 9, 14, 19, 24, 1, 6, 11, 16, 3, 8)

(these have a distinct pattern when dropped on a side note)

Wanted

2010-01-29 19:44:40

case Random(5) of
0: WayDrop := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28];
1: WayDrop := [1, 5, 9, 13, 17, 21, 25, 2, 6, 10, 14, 18, 22, 26, 3, 7, 11, 15,
19, 23, 27, 4, 8, 12, 16, 20, 24, 28];
2: WayDrop := [1, 5, 9, 13, 17, 21, 25, 26, 22, 18, 14, 10, 6, 2, 3, 7, 11, 15,
19, 23, 27, 28, 24, 20, 16, 12, 8, 4];
3: WayDrop := [4, 3, 8, 2, 7, 12, 1, 6, 11, 16, 5, 10, 15, 20, 9, 14, 19, 24, 13,
18, 23, 28, 17, 22, 27, 21, 26, 25];
4: WayDrop := [4, 2, 7, 12, 5, 10, 15, 20, 13, 18, 23, 28, 21, 26, 25, 17, 22,
27, 9, 14, 19, 24, 1, 6, 11, 16, 3, 8];
end;

Much easier IMO, even better ways to do it than that even… this one is pretty suited for your use though. I think SRL has drop patterns though you could use… not entirely sure about that one…

Bionicle

2010-01-29 19:56:46

From: IceFire908
case Random(5) of
0: WayDrop := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28];
1: WayDrop := [1, 5, 9, 13, 17, 21, 25, 2, 6, 10, 14, 18, 22, 26, 3, 7, 11, 15,
19, 23, 27, 4, 8, 12, 16, 20, 24, 28];
2: WayDrop := [1, 5, 9, 13, 17, 21, 25, 26, 22, 18, 14, 10, 6, 2, 3, 7, 11, 15,
19, 23, 27, 28, 24, 20, 16, 12, 8, 4];
3: WayDrop := [4, 3, 8, 2, 7, 12, 1, 6, 11, 16, 5, 10, 15, 20, 9, 14, 19, 24, 13,
18, 23, 28, 17, 22, 27, 21, 26, 25];
4: WayDrop := [4, 2, 7, 12, 5, 10, 15, 20, 13, 18, 23, 28, 21, 26, 25, 17, 22,
27, 9, 14, 19, 24, 1, 6, 11, 16, 3, 8];
end;

Much easier IMO, even better ways to do it than that even… this one is pretty suited for your use though. I think SRL has drop patterns though you could use… not entirely sure about that one…


Yes it does, but i ask you this. if everyone uses these drop patterns in their script, it would seem kind of suspicious, don't you think? :)
Anyway, thanks, I got it working(well compiled, testing it now) :p
I'd rep you, but it says i need to spread some around first :/
E: Yep, all five patterns work flawlessly, Thanks :D

Wanted

2010-01-29 20:05:37

From: bionicle1800
Yes it does, but i ask you this. if everyone uses these drop patterns in their script, it would seem kind of suspicious, don't you think? :)
Anyway, thanks, I got it working(well compiled, testing it now) :p
I'd rep you, but it says i need to spread some around first :/


True, in-case you feel like being OCD:

var
WayDrop: array [0..4] of TIntegerArray;
Index, I: Byte;
begin
WayDrop[0] := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28];
WayDrop[1] := [1, 5, 9, 13, 17, 21, 25, 2, 6, 10, 14, 18, 22, 26, 3, 7, 11, 15,
19, 23, 27, 4, 8, 12, 16, 20, 24, 28];
WayDrop[2] := [1, 5, 9, 13, 17, 21, 25, 26, 22, 18, 14, 10, 6, 2, 3, 7, 11, 15,
19, 23, 27, 28, 24, 20, 16, 12, 8, 4];
WayDrop[3] := [4, 3, 8, 2, 7, 12, 1, 6, 11, 16, 5, 10, 15, 20, 9, 14, 19, 24, 13,
18, 23, 28, 17, 22, 27, 21, 26, 25];
WayDrop[4] := [4, 2, 7, 12, 5, 10, 15, 20, 13, 18, 23, 28, 21, 26, 25, 17, 22,
27, 9, 14, 19, 24, 1, 6, 11, 16, 3, 8];
Index := Random(5);
for I := 0 to High(WayDrop[Index]) do
WriteLn(WayDrop[Index][I]);
end.

Or just plain stupid like me:

function IArr(IA: TIntegerArray): TIntegerArray;
begin
Result := IA;
end;

var
WayDrop: T2DIntegerArray;
Index, I: Byte;
begin
WayDrop := [IArr([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28]), IArr([1, 5, 9, 13, 17, 21, 25, 2,
6, 10, 14, 18, 22, 26, 3, 7, 11, 15, 19, 23, 27, 4, 8, 12, 16, 20, 24,
28]), IArr([1, 5, 9, 13, 17, 21, 25, 26, 22, 18, 14, 10, 6, 2, 3, 7, 11,
15, 19, 23, 27, 28, 24, 20, 16, 12, 8, 4]), IArr([4, 3, 8, 2, 7, 12, 1,
6, 11, 16, 5, 10, 15, 20, 9, 14, 19, 24, 13, 18, 23, 28, 17, 22, 27, 21,
26, 25]), IArr([4, 2, 7, 12, 5, 10, 15, 20, 13, 18, 23, 28, 21, 26, 25,
17, 22, 27, 9, 14, 19, 24, 1, 6, 11, 16, 3, 8])];
Index := Random(Length(WayDrop));
for I := 0 to High(WayDrop[Index]) do
WriteLn(WayDrop[Index][I]);
end.

Maybe some math rhythm?… but I'm too lazy :-P

Bionicle

2010-01-29 20:43:48

Actually i simply did:
Begin
If Not LoggedIn Then
Exit;

If Not GameTab(Tab_Inv) Then
GameTab(Tab_Inv);

Case Random(5) Of
0: WayDrop := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28];
1: WayDrop := [1, 5, 9, 13, 17, 21, 25, 2, 6, 10, 14, 18, 22, 26, 3, 7, 11, 15,
19, 23, 27, 4, 8, 12, 16, 20, 24, 28];
2: WayDrop := [1, 5, 9, 13, 17, 21, 25, 26, 22, 18, 14, 10, 6, 2, 3, 7, 11, 15,
19, 23, 27, 28, 24, 20, 16, 12, 8, 4];
3: WayDrop := [4, 3, 8, 2, 7, 12, 1, 6, 11, 16, 5, 10, 15, 20, 9, 14, 19, 24, 13,
18, 23, 28, 17, 22, 27, 21, 26, 25];
4: WayDrop := [4, 2, 7, 12, 5, 10, 15, 20, 13, 18, 23, 28, 21, 26, 25, 17, 22,
27, 9, 14, 19, 24, 1, 6, 11, 16, 3, 8];
End;

For I := 0 To 27 Do
Begin
LogInv := InvBox(WayDrop[I]);
If FindDTM(Log, X, Y, LogInv.X1, LogInv.Y1, LogInV.X2, LogInv.Y2) Then
Begin
//all the dropping stuff

The overall procedure works really well…in fact i think it is better then the SRL drop, as it detects whether it was dropped or not, and if that fails, drops any excess items after the rest have been dropped.

E: I accidentally had Case 4 Of instead of Case Random(5) Of, as I was testing the fourth dropping algorithm :p

Sex

2010-01-29 22:01:27

From: IceFire908
True, in-case you feel like being OCD:

Code:
[LEFT]var
WayDrop: array [0..4] of TIntegerArray;
Index, I: Byte;
begin
WayDrop[0] := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28];
WayDrop[1] := [1, 5, 9, 13, 17, 21, 25, 2, 6, 10, 14, 18, 22, 26, 3, 7, 11, 15,
19, 23, 27, 4, 8, 12, 16, 20, 24, 28];
WayDrop[2] := [1, 5, 9, 13, 17, 21, 25, 26, 22, 18, 14, 10, 6, 2, 3, 7, 11, 15,
19, 23, 27, 28, 24, 20, 16, 12, 8, 4];
WayDrop[3] := [4, 3, 8, 2, 7, 12, 1, 6, 11, 16, 5, 10, 15, 20, 9, 14, 19, 24, 13,
18, 23, 28, 17, 22, 27, 21, 26, 25];
WayDrop[4] := [4, 2, 7, 12, 5, 10, 15, 20, 13, 18, 23, 28, 21, 26, 25, 17, 22,
27, 9, 14, 19, 24, 1, 6, 11, 16, 3, 8];
Index := Random(5);
for I := 0 to High(WayDrop[Index]) do
WriteLn(WayDrop[Index]);
end.
[/LEFT]


Or just plain stupid like me:

Code:
[LEFT]function IArr(IA: TIntegerArray): TIntegerArray;
begin
Result := IA;
end;

var
WayDrop: T2DIntegerArray;
Index, I: Byte;
begin
WayDrop := [IArr([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28]), IArr([1, 5, 9, 13, 17, 21, 25, 2,
6, 10, 14, 18, 22, 26, 3, 7, 11, 15, 19, 23, 27, 4, 8, 12, 16, 20, 24,
28]), IArr([1, 5, 9, 13, 17, 21, 25, 26, 22, 18, 14, 10, 6, 2, 3, 7, 11,
15, 19, 23, 27, 28, 24, 20, 16, 12, 8, 4]), IArr([4, 3, 8, 2, 7, 12, 1,
6, 11, 16, 5, 10, 15, 20, 9, 14, 19, 24, 13, 18, 23, 28, 17, 22, 27, 21,
26, 25]), IArr([4, 2, 7, 12, 5, 10, 15, 20, 13, 18, 23, 28, 21, 26, 25,
17, 22, 27, 9, 14, 19, 24, 1, 6, 11, 16, 3, 8])];
Index := Random(Length(WayDrop));
for I := 0 to High(WayDrop[Index]) do
WriteLn(WayDrop[Index]);
end.
[/LEFT]


Maybe some math rhythm?… but I'm too lazy :-P
You do not need the IArr function..you can just use:
var
WayDrop: T2DIntegerArray;
Index, I: Byte;
begin
WayDrop := [TIntegerArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28]), TIntegerArray([1, 5, 9, 13, 17, 21, 25, 2,
6, 10, 14, 18, 22, 26, 3, 7, 11, 15, 19, 23, 27, 4, 8, 12, 16, 20, 24,
28]), TIntegerArray([1, 5, 9, 13, 17, 21, 25, 26, 22, 18, 14, 10, 6, 2, 3, 7, 11,
15, 19, 23, 27, 28, 24, 20, 16, 12, 8, 4]), TIntegerArray([4, 3, 8, 2, 7, 12, 1,
6, 11, 16, 5, 10, 15, 20, 9, 14, 19, 24, 13, 18, 23, 28, 17, 22, 27, 21,
26, 25]), TIntegerArray([4, 2, 7, 12, 5, 10, 15, 20, 13, 18, 23, 28, 21, 26, 25,
17, 22, 27, 9, 14, 19, 24, 1, 6, 11, 16, 3, 8])];
Index := Random(Length(WayDrop));
for I := 0 to High(WayDrop[Index]) do
WriteLn(WayDrop[Index][I]);
end.

Daniel

2010-01-30 06:51:54

From: bionicle1800
Actually i simply did:
Begin
If Not LoggedIn Then
Exit;

If Not GameTab(Tab_Inv) Then
GameTab(Tab_Inv);

Case Random(5) Of
0: WayDrop := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28];
1: WayDrop := [1, 5, 9, 13, 17, 21, 25, 2, 6, 10, 14, 18, 22, 26, 3, 7, 11, 15,
19, 23, 27, 4, 8, 12, 16, 20, 24, 28];
2: WayDrop := [1, 5, 9, 13, 17, 21, 25, 26, 22, 18, 14, 10, 6, 2, 3, 7, 11, 15,
19, 23, 27, 28, 24, 20, 16, 12, 8, 4];
3: WayDrop := [4, 3, 8, 2, 7, 12, 1, 6, 11, 16, 5, 10, 15, 20, 9, 14, 19, 24, 13,
18, 23, 28, 17, 22, 27, 21, 26, 25];
4: WayDrop := [4, 2, 7, 12, 5, 10, 15, 20, 13, 18, 23, 28, 21, 26, 25, 17, 22,
27, 9, 14, 19, 24, 1, 6, 11, 16, 3, 8];
End;

For I := 0 To 27 Do
Begin
LogInv := InvBox(WayDrop[I]);
If FindDTM(Log, X, Y, LogInv.X1, LogInv.Y1, LogInV.X2, LogInv.Y2) Then
Begin
//all the dropping stuff


I never knew the inventory started at 0. :S

Gu3st...

2010-01-30 07:45:23

[QUOTE=Dan's The Man;680310]I never knew the inventory started at 0. :S[/QUOTE]It doesn't, but the array does

Bionicle

2010-01-30 11:36:47

[QUOTE=Dan's The Man;680310]I never knew the inventory started at 0. :S[/QUOTE]

Lets say the random WayDrop was 0, if I := 0 for the first time around, it would use the very first integer in the integer array 'WayDrop', which would be 1.