SRL Archive - OSR Help

Removing points


Element17

2013-06-25 21:23:45

I am trying to make a combat looting procedure. This is what I have so far…


function Loot: Boolean;
var
CTS: Integer;
TPA, Player_TPA: TPointArray;
ATPA: array of TPointArray;
begin
if (not (LoggedIn)) then
Exit;
Player_TPA := TPAFromBox(IntToBox(245, 130, 285, 195));
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.40, 3.26);
if FindColorsSpiralTolerance(MSCX, MSCY, TPA, 13949677, MSX1, MSY1, MSX2, MSY2, 10) then
begin
TPA := ClearTPAFromTPA(TPA, Player_TPA);
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.2, 0.2);
RAaSTPA(TPA, 5);
ATPA := SplitTPAEx(TPA, 10, 10);
SortATPAFromFirstPoint(ATPA, Point(MSCX, MSCY));
DeBugATPABounds(ATPA);
for i := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i], x, y);
HumanMMouse(x, y, 5, 5);
Writeln(GetUpText);
if WaitUpText('Take', 400) then
begin
Writeln('UpText match');
ClickMouse2(False);
if ChooseOption('charm') then
Result := True;
Exit;
end
else
begin
writeln('No charm');
Exit;
end;
end;
end;
end;



The function searches for the bone color and if it finds the bone color it right clicks and searches for option charm.
This works, but after it takes the charm I search again to look for another pile but it searches the same pile. Should I remove that point from the TPA once its been searched or what? This is my first combat script and first try at looting.

Sin

2013-06-25 21:31:59

Yees.

Brandon

2013-06-25 23:57:48

No.. I usually don't disagree with you Sin, but on this I do. Lol.

Here's why. If the TPA is a local TPA. Meaning a local variable (scope is within a function), then there is no need to remove any points (unless you left the bone there -_-). And the reason is because you can simply just call the function again. On the second call, the Local TPA would have already been wiped before the first call even returns from the stack.

Removing points from the TPA may actually be slower than just letting the interpret clean it natively and simply making another function call. Why? Because you might have to search for the point/iterate the array. Then do the removal and removing requires a copy of the array without the old point there unless it's a linked list or other container type (none of which we have in Simba).

It'd be wise to probably do a speed test or efficiency test then but my guess is that there is no need for looting since you can simply just call the function again and save yourself the work (unless you want to).

Ian

2013-06-26 00:01:36

From: Element17

The function searches for the bone color and if it finds the bone color it right clicks and searches for option charm.
This works, but after it takes the charm I search again to look for another pile but it searches the same pile. Should I remove that point from the TPA once its been searched or what? This is my first combat script and first try at looting.


Because you are looking for the bone to find a loot pile, I would recommend picking up the bone and burying it after you have found the pile. This will mean that next time you look for a pile, the looted pile will not appear :)

Nebula

2013-06-26 00:15:15

Well if your player is moving spot-to-spot, wouldn't you not even be able to remove the already searched pile, since its mainscreen position changed when your player moved?