SRL Archive - RS3 Help

rotating to find objects


Dynamo

2015-03-02 17:34:16

Hey, I am new to simba but not programming, I was just wondering if there are any helpful SRL functions/procedures for searching a certain radius around the player by panning the camera for an object such as a tree. I was thinking of something like

Pseudocode
rotate camera left
search for tree
if not found
rotate camera left
if not found
rotate camera right x 3
if not found
restart search

KeepBotting

2015-03-02 18:28:29

There's no inbuilt function to search for an object whilst spinning the camera, but there are routines to do each of those actions individually.

So first you could declare this custom function which isn't mandatory but prevents unnecessary micro-adjustment of the camera by .setAngle()


function TRSMinimap.isAngle(deg:extended; turnTo:boolean = false):boolean;
//Returns true if the current compass angle
var //is within a few degrees of "deg"
a:extended; //Will also turn to "deg" if turnTo is true.
begin
a := self.getAngleDegrees();

result := inRange(round(a), (deg - 5), (deg + 5));
writeLn('isAngle(): angle is currently ' + toStr(a) + ', threshold was ' + toStr(deg) + ', returning ' + lowercase(toStr(result)) + '');

if (not (result)) then
if (turnTo) then
begin
writeLn('isAngle(): altering angle to ' + toStr(deg));
self.setAngle(deg);
end;
end;

And then this one which I cooked up specifically for the purposes of this post (untested but should work fine)


function TRSMinimap.turnTo(min, max:extended):boolean; //Turns the camera a random amount of degrees from "min" to "max" away from its starting point.
//It adds degrees, thus is going to turn from north to east to south to west (clockwise)
var
startDeg, endDeg:extended;
begin
startDeg := self.getAngleDegrees();
writeLn('turnTo(): starting at ' + toStr(startDeg) + ' degrees');

endDeg := (startDeg + randomRange(round(min), round(max)));

if (endDeg > 360) then
endDeg := (0 + randomRange(round(min), round(max))); //a circle is only 360 degrees so if we go over,
//we'll have to start back at 0 (north)
writeLn('turnTo(): altering angle to ' + toStr(endDeg));

result := self.setAngle(endDeg); //could possibly use .isAngle() here but I don't think it's needed
end; //as we're always going to be moving the camera regardless

So then, wrapping this up, you could do:


if (not ({found and clicked tree})) then
minimap.turnTo(30, 50); //will turn a random amount between 30 and 50 degrees

Again, I wrote .turnTo() just now and haven't tested it, it compiles but if it behaves unexpectedly let me know and I'll fix it

E: just realized that "turnTo" is a horrible name for the function lol, that kinda implies that it turns somewhere specific (which it doesn't really)

"adjust" is probably better

Dynamo

2015-03-03 09:14:09

Cool cool, will implement and tweak and let you know how it goes :)