SRL Archive - Research & Development Lounge

Random Drop


smithsps

2008-03-31 21:52:47

My SRL or Scar isn't working correctly so I can't test this yet.
But it does compile. ;)

Test please.

It random drops the MinPos inventory slot to the MaxPos inventory slot.
It makes it more…. human like :)

program RandDrop;
{.include SRL/SRL.scar}
procedure RandDrop(MinPos, MaxPos: integer);
var
Done : array of boolean;
A : integer;
begin
SetArrayLength(Done, 28);
while ((MaxPos - MinPos) >= A) do
begin
case RandomRange(MinPos, MaxPos) of
1: begin if (Done[1] = False) then DropItem(1); Done[1] := True; A := A + 1; end;
2: begin if (Done[2] = False) then DropItem(2); Done[2] := True; A := A + 1; end;
3: begin if (Done[3] = False) then DropItem(3); Done[3] := True; A := A + 1; end;
4: begin if (Done[4] = False) then DropItem(4); Done[4] := True; A := A + 1; end;
5: begin if (Done[5] = False) then DropItem(5); Done[5] := True; A := A + 1; end;
6: begin if (Done[6] = False) then DropItem(6); Done[6] := True; A := A + 1; end;
7: begin if (Done[7] = False) then DropItem(7); Done[7] := True; A := A + 1; end;
8: begin if (Done[8] = False) then DropItem(8); Done[8] := True; A := A + 1; end;
9: begin if (Done[9] = False) then DropItem(9); Done[9] := True; A := A + 1; end;
10: begin if (Done[10] = False) then DropItem(10); Done[10] := True; A := A + 1; end;
11: begin if (Done[11] = False) then DropItem(11); Done[11] := True; A := A + 1; end;
12: begin if (Done[12] = False) then DropItem(12); Done[12] := True; A := A + 1; end;
13: begin if (Done[13] = False) then DropItem(13); Done[13] := True; A := A + 1; end;
14: begin if (Done[14] = False) then DropItem(14); Done[14] := True; A := A + 1; end;
15: begin if (Done[15] = False) then DropItem(15); Done[15] := True; A := A + 1; end;
16: begin if (Done[16] = False) then DropItem(16); Done[16] := True; A := A + 1; end;
17: begin if (Done[17] = False) then DropItem(17); Done[17] := True; A := A + 1; end;
18: begin if (Done[18] = False) then DropItem(18); Done[18] := True; A := A + 1; end;
19: begin if (Done[19] = False) then DropItem(19); Done[19] := True; A := A + 1; end;
20: begin if (Done[20] = False) then DropItem(20); Done[20] := True; A := A + 1; end;
21: begin if (Done[21] = False) then DropItem(21); Done[21] := True; A := A + 1; end;
22: begin if (Done[22] = False) then DropItem(22); Done[22] := True; A := A + 1; end;
23: begin if (Done[23] = False) then DropItem(23); Done[23] := True; A := A + 1; end;
24: begin if (Done[24] = False) then DropItem(24); Done[24] := True; A := A + 1; end;
25: begin if (Done[25] = False) then DropItem(25); Done[25] := True; A := A + 1; end;
26: begin if (Done[26] = False) then DropItem(26); Done[26] := True; A := A + 1; end;
27: begin if (Done[27] = False) then DropItem(27); Done[27] := True; A := A + 1; end;
28: begin if (Done[28] = False) then DropItem(28); Done[28] := True; A := A + 1; end;
end;
end;
end;


begin
SetupSRL;
RandDrop(2, 3); //Drops Slots 2 to 3
end.

mixster

2008-04-01 03:51:53

You double posted it ;)
Also, I've never known anyone who randomly drops items. They always drop via going along then up a line or down then across a line. Also, this is actually quite a peculiar method as it does actually have the possibility to get into an endless loop thus seriously delaying the script as if RandomRange keeps generating similar numbers, then it will continually run the 'if' statement without anything happening. A better run time random dropping procedure would be something resembling this:

procedure RandomDrop(sPos, ePos: Integer);
var
uPosA: array of Integer;
i: Integer;
begin
SetLength(uPosA, ePos - sPos);
for i := 0 to (ePos - sPos) do
uPosA[i] := sPos + i;
i := 0;
while GetArrayLength(uPosA) > 0 do
begin
i := Random(GetArrayLength(uPosA));
Drop(i);
uPosA := uPosA[High(uPosA)];
SetArrayLength(uPosA, High(uPosA));
end;
end;
And that should work fine and won't run into a possible endless loop :)

smithsps

2008-04-01 17:37:14

Questions:
1. Where did you find:
Drop(i);
I couldn't find it.

2. What does the
High(uPosA)
do?

Got Rid of second post. (I was lagging)

Edit: Maybe ill make it so it will drop like in lines or rows. More Human like… :)

mixster

2008-04-02 09:27:20

1. I meant to put DropItem, I usually code inside FF so I don't normally double check it except for spelling based mistakes.
2. High = GetArrayKength or Length then minus 1, so basically the highest index of an array for example, if an array was from [0] to [5], GetArrayLength returns 6 as 0 -> 5 is 6 numbers, while High returns 5.

n3ss3s

2008-04-02 11:23:25

ehm… Anyone even considered about looking into SRL?


{*******************************************************************************
procedure DropAll;
By: Lorax
Description: Drops all items
*******************************************************************************}

procedure DropAll;
var
i: Integer;
arr:array of Integer;
begin
arr :=[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];

for i := 1 to 28 - 4 do
Swap(arr[RandomRange(i - 1, i + 4)], arr[RandomRange(i - 1, i + 4)] );

for i := 0 to 27 do
DropItem(arr[i]);
end;

mixster

2008-04-02 13:03:57

But 'DropAll' doesn't drop a range of items, only all of them, and if you did convert it to, it would only be a bit shorter than mine. Also, DropAll doesn't use ExistItem, so it can't be that good :p (I know mine doesn't, but mine sucks ^^).