PDA

View Full Version : StrangePlant handler



Flight
07-27-2013, 08:18 AM
While it's not easy to determine if a strange plant is ours or not (this can actually be accomplished in the script but not universally) we can still make a detection & handling system if one comes within distance of our player. So here's a basic Strangeplant finder & handler that will work in all scripts.

-Global declaration-
Declare this as a global variable:

Var
SP_coolDownTimer: Integer;


-Finding the plant-

Function foundStrangePlant(out Pnt: TPoint): Boolean;
var
cts: Integer;
tpa: TPointArray;
begin
cts := getToleranceSpeed;

ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.34, 1.17);
FindColorsSpiralTolerance(MSCX, MSCY, tpa, 612431, MSCx-100, MSCy-100, MSCx+100, MSCy+100, 4);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);

result := (length(tpa) > 50);
if Result then
Pnt := Point(MedianTPA(tpa).x, MedianTPA(tpa).y);
end;

As you can tell it's pretty primitive, searching just within a 200x200 size box of the middle of the screen (presumed where our player is located) for a unique color to the strange plant. Then simply the amount of color is counted, if the size is high enough it's considered a strange plant.

-Handling the plant-

Function HandleStrangePlant: Boolean;
var
t: Integer;
Pnt: TPoint;
begin
// To prevent spam-clicking a strange plant
if (GetTimeRunning-SP_coolDownTimer) < 20000 then // 20 seconds
Exit;
if not foundStrangePlant(Pnt) then
Exit;

t := getTimeRunning;
repeat
if not LoggedIn then
Exit;

//FindCustomRandoms;
FindNormalRandoms;
if not foundStrangePlant(Pnt) then
break;

if (FindBlackChatMessage('ou pick') or FindBlackChatMessage('unable to')) then
begin
Result := True;
break;
end;

MMouse(Pnt.X, Pnt.Y, 5, 5);
if waitUptextMulti(['Pick','ick St'], 200) then
begin
Clickmouse2(mouse_right);
chooseOptionMulti(['Pick','ck St']);
Flag;
Wait(RandomRange(1500,2400));
end else if waitUptextMulti(['ttack','ack Str'], 200) then
begin
Result := True;
break;
end;
until((getTimeRunning-t) > 15000)

if Result then
SP_coolDownTimer := GetTimeRunning;
end;


If we successfully interacted with the plant (either pick the fruit or determine it's not after our player) then the global "SP_coolDownTimer" is, once again, reset, so we won't start looking for a strange plant until 20 seconds after the previous one.

Chris!
07-27-2013, 08:34 AM
Great work Flight!

loragnor
07-28-2013, 12:55 AM
Flight, please explain the purpose of the "out" in the function declaration:

Function foundStrangePlant(out Pnt: TPoint): Boolean;

What is the difference between 'var Pnt' and 'out Pnt' since both need to be declared variables passed to the the function? Is an 'out' parameter a pointer? I've seen 'out' used in FindDTMRotated in the form of out aFound: Extended, even though I cannot seem to make any use of it there.

Sjoe
07-28-2013, 01:27 AM
Flight, please explain the purpose of the "out" in the function declaration:

Function foundStrangePlant(out Pnt: TPoint): Boolean;

What is the difference between 'var Pnt' and 'out Pnt' since both need to be declared variables passed to the the function? Is an 'out' parameter a pointer? I've seen 'out' used in FindDTMRotated in the form of out aFound: Extended, even though I cannot seem to make any use of it there.

if it's found at for example: Point(156,78); then Pnt will be stored as Pnt := Point(156,78);

edit: nvm didn't read your question properly :)

Flight
07-28-2013, 01:28 AM
Flight, please explain the purpose of the "out" in the function declaration:

Function foundStrangePlant(out Pnt: TPoint): Boolean;

What is the difference between 'var Pnt' and 'out Pnt' since both need to be declared variables passed to the the function? Is an 'out' parameter a pointer? I've seen 'out' used in FindDTMRotated in the form of out aFound: Extended, even though I cannot seem to make any use of it there.

Honestly I'm not sure what the difference between the two would be. If I really had to guess I'd say that if it was was set up as "Var Pnt" then whatever variable was used to catch that returned variable could have still been <> 0, while maybe if you're catching an out (for lack of better terminology) it would have to be empty. But chances are I'm completely wrong in this theory. If you want to replace it with "Var Pnt: TPoint" then I don't see any problem with that. As far as I'm concerned the same thing is accomplished.

Chris!: Thank you. :)

Daniel
07-28-2013, 05:47 AM
Flight, please explain the purpose of the "out" in the function declaration:

Function foundStrangePlant(out Pnt: TPoint): Boolean;

What is the difference between 'var Pnt' and 'out Pnt' since both need to be declared variables passed to the the function? Is an 'out' parameter a pointer? I've seen 'out' used in FindDTMRotated in the form of out aFound: Extended, even though I cannot seem to make any use of it there.

There are several argument keywords you can use in Simba's PascalScript/Lape:

const - Indicates that the argument passed to the method is read-only and cannot be modified (i.e. a value can be passed into the method and it can be read).
out - Indicates that the argument passed to the method is write-only at first and can be modified (i.e. an empty/nil variable is passed into the method so it can be changed by the method).
var - Indicates that the argument passed to the method is read/write and can be modified (i.e. its initial value can be read, and be modified by the method).
default (i.e. nothing) - assume const.

loragnor
07-28-2013, 11:14 AM
There are several argument keywords you can use in Simba's PascalScript/Lape:

const - Indicates that the argument passed to the method is read-only and cannot be modified (i.e. a value can be passed into the method and it can be read).
out - Indicates that the argument passed to the method is write-only at first and can be modified (i.e. an empty/nil variable is passed into the method so it can be changed by the method).
var - Indicates that the argument passed to the method is read/write and can be modified (i.e. its initial value can be read, and be modified by the method).
default (i.e. nothing) - assume const.


Thank you. I'm glad to finally have an explanation about this.