SRL Archive - Outdated Tutorials

[#46 / #527] WaitInvCount


Sir R. M8gic1an

2010-06-08 14:01:54

[php]
{*******************************************************************************
function WaitInvCount(Count, MaxTime: Integer; CountType: (MaxCT, MinCT, ExactCT)): boolean;
By: Rasta Magician
Description: Waits for a maximum inv count. Returns true if InvCount <= Count
*******************************************************************************}
function WaitInvCount(Count, MaxTime: Integer; CountType: (MaxCT, MinCT, ExactCT)): boolean;
var
T: integer;
begin
if not GameTab(tab_Inv) then exit;

Result := false;
T := GetSystemTime + MaxTime;

while GetSystemTime < T do
begin
wait(10);
case CountType of
MaxCT : if InvCount <= Count then Result := true;
MinCT : if InvCount >= Count then Result := true;
ExactCT : if InvCount = Count then Result := true;
end;

if Result then break;

end;
end;

{*******************************************************************************
function WaitInvMaxCount(Count, MaxTime: integer): boolean;
By: Rasta Magician
Description: Waits for a maximum inv count. Returns true if InvCount <= Count
*******************************************************************************}
function WaitInvMaxCount(Count, MaxTime: integer): boolean;
begin
Result := WaitInvCount(Count, MaxTime, MaxCT);
end;

{*******************************************************************************
function WaitInvMinCount(Count, MaxTime: integer): boolean;
By: Rasta Magician
Description: Waits for a minimum inv count. Returns true if InvCount >= Count
*******************************************************************************}
function WaitInvMinCount(Count, MaxTime: integer): boolean;
begin
Result := WaitInvCount(Count, MaxTime, MinCT);
end;
[/php]

WaitInvMinCount & WaitInvMaxCount will be gone in SRL 5.
If you wish to make the transition smoother, switch to WaitInvCount now :)


eg
WaitInvCount(InvCount + 1, 10000, ExactCT)

~RM

Ogre

2010-06-08 14:14:21

Looks cool, but why do we even need WaitInvMaxCount? or even a MaxCount option in WaitInvCount? I don't think you would need to wait for that, it will just be true or false?

Sir R. M8gic1an

2010-06-08 14:19:29

I use it in many of my WaitWhileDoingX functions.

[php]
Procedure Mine;
var
IC: integer;
begin
IC := InvCount;
if ClickRock then
WaitInvCount(IC + 1, 10000, MinCT);

if GotGem then
begin
IC := InvCount;
WaitInvCount(IC + 1, 10000, ExactCT)
end;
end;
[/php]

MinCount is extremely useful while fishing. I check when was the last time I got a fish, and if it was too long ago then I assume it is not fishing. ExactCount might not work, because you might have caught two fishes since you last checked.

~RM

Ogre

2010-06-08 14:28:20

Umm, you're not using MaxCT

Sir R. M8gic1an

2010-06-08 14:55:53

From: Ogre
Umm, you're not using MaxCT


Doesn't hurt to have it.

InvMaxCount Scenario:

Your smelting steel bars. You took out 10 iron and 18 coal

WaitInvCount(10, 20000, MaxCT);

This will work whether you have 10 or 9 iron.

MinCount wouldn't work
ExactCount might fail.

~RM

Sabzi

2010-06-08 15:26:35

Now that school and my exams are almost over I have started to think about scripting again. And ^ this is what I use in my smelter(not with this cool new functions ofc). I may rewrite it(smelter) in MSI standards as I want to do something with MSI too. I wanted always, but sadly I don't got that time thing that Hermione got. And future life > fun…, erm what? I mean …, you know.