Boreas
2006-10-24 21:16:55
Cliffnotes version: I made this procedure that creates a grid of points in a box and monitors them for color changes. Good for attacking monsters/getting drops/getting rocks/trees as sson as they appear. Tell me what you think.
History: I was fighting a monster and spent a while trying to find a world where no one else was doing the same. A few minutes after I finally did, someone else came and was right clicking it and choosing attack faster than me, so I didn't get my kill, and more importantly the drops. So I made a script to do it for me (just the right clicking it and choosing attack when it appears, I didn't leave it alone). I tried findcolor and popup, and about 4 other methods, but they either didn't work properly or were too slow(even after changing mousespeed in srl.scar). Then I realised, I don't need to find the monster when it appears, I know the general area where it will appear, I jsut need to know when it appears. So I wrote a script that created 5 points (1 was the mouse point, the other 4 created a square around it with the mouse point being in the center) and checked when the color changed (not to any specific color of the monster, just a color different to what it started as). Then it right clicked at the point that changed and choose attack (by going 50 or so pixels lower instead of popup etc but that's not the point). This worked very well. I expanded on the checking points for color changes instead of looking at every pixel and created FindColorChangeGrid.
Info: FindColorChangeGrid(x1, y1, x2, y2, d, giveuptime, WhichEx: integer) sets up a box with the top left point being x1,y1 and the bottom right being x2,y2. It then sets up a grid of points d distance apart (NOTE: in case of having a width of say 100 and having a d of 26 you would have a left over of 22 which is not enough for another point, so it put another point at the end anyway so that 22 is not wasted, same goes for height). It will then remember the color at each of these points and then continuely check each one to see if the color changes. Once it finds a change, it checks whether it should ignore the change (see next paragraph) and if it should ignore it, it continues checking, otherwise it sets srl global x and y to the point where it found the change, and heracles2 global FCCGfound to true (to be used in failsafes to let the script it didn't work). If it doesn't find a change after giveuptime ms it will set FCCGfound to false and exit. The script can now do an action (such as right click and attack) at x,y (or if it didn't work change the parameters and try again etc).
FindColorChangeGridEx(xposex,yposex,which:integer):boolean defines what changes FindColorChangeGrid (FCCG) should ignore. It is put in the script and lets the scripter make custom exceptions. It allows for multiple exceptions which can be choosen in WhichEx in FCCG. The parameters all come from FCCG and are not changed. What the scripter can change is adding branches to the case of, each branch being an exception. For FCCG to ignore a change at a point FindColorChangeGridEx must return false at that point.
It is pretty fast at finding things that move or appear/spawn. A drawback is the hassle of putting FindColorChangeGridEx in the top of the script. Also, the include that it is contained in can only be included if you are going to use it, (therefore no other procs/funcs can be in the same include) due to the forward of FindColorChangeGridEx. Also, it probably has more false positives than other methods (this depends on how good your exceptions are). Trees and mining rocks coming back, enemies and drops respawning come to mind as uses. Walking etc obviously not. Perhaps for randoms but probably not.
So how can I improve it?
Also I know the instructions aren't great, it's hard for me to write because I already know it in my head and I don't want to write a whole tutorial on 1 procedure. So any tips on that would be great too.
Questions/comments/suggestions?
Sorry for the long post, thanks for reading.
A demo.
History: I was fighting a monster and spent a while trying to find a world where no one else was doing the same. A few minutes after I finally did, someone else came and was right clicking it and choosing attack faster than me, so I didn't get my kill, and more importantly the drops. So I made a script to do it for me (just the right clicking it and choosing attack when it appears, I didn't leave it alone). I tried findcolor and popup, and about 4 other methods, but they either didn't work properly or were too slow(even after changing mousespeed in srl.scar). Then I realised, I don't need to find the monster when it appears, I know the general area where it will appear, I jsut need to know when it appears. So I wrote a script that created 5 points (1 was the mouse point, the other 4 created a square around it with the mouse point being in the center) and checked when the color changed (not to any specific color of the monster, just a color different to what it started as). Then it right clicked at the point that changed and choose attack (by going 50 or so pixels lower instead of popup etc but that's not the point). This worked very well. I expanded on the checking points for color changes instead of looking at every pixel and created FindColorChangeGrid.
Info: FindColorChangeGrid(x1, y1, x2, y2, d, giveuptime, WhichEx: integer) sets up a box with the top left point being x1,y1 and the bottom right being x2,y2. It then sets up a grid of points d distance apart (NOTE: in case of having a width of say 100 and having a d of 26 you would have a left over of 22 which is not enough for another point, so it put another point at the end anyway so that 22 is not wasted, same goes for height). It will then remember the color at each of these points and then continuely check each one to see if the color changes. Once it finds a change, it checks whether it should ignore the change (see next paragraph) and if it should ignore it, it continues checking, otherwise it sets srl global x and y to the point where it found the change, and heracles2 global FCCGfound to true (to be used in failsafes to let the script it didn't work). If it doesn't find a change after giveuptime ms it will set FCCGfound to false and exit. The script can now do an action (such as right click and attack) at x,y (or if it didn't work change the parameters and try again etc).
FindColorChangeGridEx(xposex,yposex,which:integer):boolean defines what changes FindColorChangeGrid (FCCG) should ignore. It is put in the script and lets the scripter make custom exceptions. It allows for multiple exceptions which can be choosen in WhichEx in FCCG. The parameters all come from FCCG and are not changed. What the scripter can change is adding branches to the case of, each branch being an exception. For FCCG to ignore a change at a point FindColorChangeGridEx must return false at that point.
It is pretty fast at finding things that move or appear/spawn. A drawback is the hassle of putting FindColorChangeGridEx in the top of the script. Also, the include that it is contained in can only be included if you are going to use it, (therefore no other procs/funcs can be in the same include) due to the forward of FindColorChangeGridEx. Also, it probably has more false positives than other methods (this depends on how good your exceptions are). Trees and mining rocks coming back, enemies and drops respawning come to mind as uses. Walking etc obviously not. Perhaps for randoms but probably not.
So how can I improve it?
Also I know the instructions aren't great, it's hard for me to write because I already know it in my head and I don't want to write a whole tutorial on 1 procedure. So any tips on that would be great too.
Questions/comments/suggestions?
Sorry for the long post, thanks for reading.
A demo.
program FCCGTest;
{.include heracles2.scar}
// use it in paint
//unblank the test section in the heracles2.scar to actually where the points
//are. select the paintbrush and a color. run. it will make the points in
//that color. then change colors and move the mouse across the screen
function FindColorChangeGridEx(xposex,yposex,which:integer):boolean;
begin
case which of
//This is for when you want no exceptions in the box //
1: //
begin //
if (xposex = xposex) and (yposex=yposex) then //
result:=true; //
end; //
//add more exceptions here
else writeln('Error in detector exceptions');
end;
end;
begin
cleardebug;
FindColorChangeGrid(15, 15, 516, 338, 20, 10000,1);
clickmouse(x,y,true);
end.