How do i code so my character moves to a specific area ingame?
Printable View
How do i code so my character moves to a specific area ingame?
There's several different ways to do so. for how long of a distance do you want to walk?
Hmm, not worldwide, basically a few tiles should do the work, draynor - willow trees?
With Simba and SRL, you're going to want to change your mindset. You dont want to walk to a certain tile. You want to walk into that area. Area being, a range. You will almost never be able to walk to an exact point.
If you want to walk to the fishing area in draynor, there are a couple of things youll want to look for.
o The Fishing symbol. Will you be able to see the fishing spot symbol from where you are?
o Will looking for the colour of the trees and walking towards that colour be accurate enough?
o What about the water? What if walk towards certain areas of the water on the minimap. We could do some math to help improve accuracy on this.
o Make a bitmap or a dtm of the area and walk to it?
Not necessarily in that order. Before attempting this, you may want to learn the basics if you havent already. TPA's, DTM's, and all that stuff will be important to the success of your script.
Good luck :)
Check out a tutorial on DDTMs (Dynamic DTMs) they will work nicely. :)
The autocolors are still broken, so if you're planning on using the tree color, FindTreeColor still works.
Simba Code:function FindTreeColor: Integer;
var
TPA, TestTPA: TPointArray;
ATPA: T2DPointArray;
H, S, L: Extended;
i, TestColor, R, G, B, AL: Integer;
BlackListCol: TIntegerArray;
begin
result := -1;
if FindMMColorsSpiralTolerance(TPA, 1528609, 70) then
begin
AL := high(TPA);
For i := 0 to AL do
begin
TestColor := GetColor(TPA[i].x, TPA[i].y);
if not InIntArray(BlackListCol, TestColor) then
begin
ColorToRGB(TestColor, R, G, B);
ColorToHSL(TestColor, H, S, L);
if InRange(R - B, -10, 50) then
if InRange(R - G, -75, -30) then
if InRange(G - B, 50, 88) then
if L < 31.5 then
if GetColor(TPA[i].x - 1, TPA[i].y) = TestColor then
if GetColor(TPA[i].x, TPA[i].y + 1) = TestColor then
if GetColor(TPA[i].x, TPA[i].y - 1) = TestColor then
begin
FindColorsSpiralTolerance(mmcx, mmcy, TestTPA, TestColor, mmx1, mmy1, mmx2, mmy2, 0);
if Length(TestTPA) > 0 then
begin
ATPA := TPAtoATPAEx(TestTPA, 11, 10);
SortATPAFrom(ATPA, Point(mmcx, mmcy));
if not InRange(Length(ATPA[0]), 21, 28) then
if Length(ATPA[0]) < 30 then
if not InRange(Length(ATPA[0]), 8, 10) then
begin
writeln('Tree colour = '+ Inttostr(TestColor));
Result := TestColor;
exit;
end else
begin
ColorToHSL(TestColor, H, S, L);
if L > 24 then
begin
SetArrayLength(BlackListCol, Length(BLackListCol) + 1);
BlackListCol[High(BlackListCol)] := TestColor;
end;
end;
end;
end;
end;
end;
end;
writeln('Couldn''t find tree color!');
Result := -1;
end;
procedure tofish();
var
treetpa, watertpa: tpointarray;
lowest, sym: tpoint;
i, lowy, d, treecol: integer;
begin
if not loggedin then exit;
treecol := findtreecolor;
findcolorstolerance(treetpa, treecol, mmx1, mmy1, mmx2, mmy2, 0);
if (treecol > 0) and (length(treetpa) > 0) then
begin
writeln('Walking to trees via treecolor');
FilterPointsPie(treetpa, 85, 115, 50, 70, mmcx, mmcy);
for i := 0 to high(treetpa) do
if lowest.y < treetpa[i].y then lowest := treetpa[i];
mfnf(lowest.x, lowest.y, 1, 1);
flag;
wait(300+random(300));
end else
begin
writeln('Couldnt find treecolor, attempting to walk to the farthest water spot');
//Hopefully this will do till the autocolors are fixed......
findcolorstolerance(watertpa, 10327174, mmx1, mmy1, mmx2, mmy2, 10);
if length(watertpa) > 0 then
begin
debugtpa(watertpa, 'a');
lowy := 0;
for i := 1 to high(watertpa) do
if watertpa[i].y < watertpa[lowy].y then lowy := i;
mfnf(watertpa[lowy].x-7, watertpa[lowy].y-3, 1, 1);
flag;
wait(300+random(300));
end else
begin
if findsymbol(sym.x, sym.y, 'fish') then
begin
mfnf(sym.x, sym.y-5, 1, 1)
flag;
wait(300+random(300));
end else
begin
writeln('Couldnt get to fishing spot!');
killplayer();
end
end;
end;
end;
That is my walking procedure, please dont copy it, but do learn from it :)
Note: TPA = TPointArray = array of tpoint
tpoint = a set of x and y in one var
var t: tpoint;
t := point(1, 2);
writeln(t.x);
writeln(t.y);
Had exams and haven't been online for a while anyway does autocolour work and some guides tell me to printscreen the item and then make it more viable and then attach the code into Simba, i'm not great but i'm learning :s
DDTMs are an effective way of finding areas on the minimap, there's a great tutorial on it here:
http://villavu.com/forum/showthread.php?t=10008
I made a very efficient MM symbol-finder and I assume there at Draynor you have both a Bank map symbol for the bank and a tree symbol for the willow area. My function will find the correct symbol you're looking for, give you the X/Y coord of the middle of that symbol and tell you your distance to the symbol. That should cover walking to and from the willows/bank and tell you which one you're near.
If you'd like it let me know.
http://villavu.com/forum/showthread.php?t=66266
SPS will walk pretty much anywhere with ease. :)
Here's an example:
Simba Code:program new;
{.include srl/srl.scar}
{.include sps/sps.simba}
// This function will walk you to Draynor willow trees,
// assuming you're only 1 click away
function WalkToWillows: boolean;
begin
Result := SPS_WalkToPos(4155, 3700);
end;
// This function will walk you to Draynor bank,
// assuming you're only 1 click away
function WalkToWillows: boolean;
begin
Result := SPS_WalkToPos(4185, 3670);
end;
{
YOUR OWN PROCEDURES AND FUNCTIONS HERE
}
begin
SetupSRL;
SPS_Setup(RUNESCAPE_SURFACE, ['10_8', '10_9']);
{
YOUR SCRIPTS MAIN EXECUTION HERE
}
end.
You should also learn the concept of DTMs, and make a function that will check if we have arrived at the correct position after walking. If you like, you can also just walk with DTMs, which is prefered over SPS if you're only walking from Draynor bank to Draynor willows, but when you want to write say, an all-locations-in-one-script-woodcutter, SPS makes walking whole lot easier. :)