
Originally Posted by
Boreas
I don't see it in there. I've improved my function a bit too:
Simba Code:
Function SetCamera(CompassDirection: Variant; HighestAngle: Variant): Boolean;
var
StartAngle, Angle, DirectionDeg, i: Extended;
Left, SetCompass, SetHeight, Highest, Set0, Set1: Boolean;
Mark, TimeOut, k: Integer;
Begin
Result := False;
if not LoggedIn then
Exit;
if varType(HighestAngle) = varBoolean then
begin
SetHeight := true;
Highest := HighestAngle;
end;
case VarType(CompassDirection) of
varInteger, varDouble: begin
StartAngle := (rs_GetCompassAngleDegrees);
DirectionDeg := FixD(CompassDirection + 0.0);
end;
varString: begin
StartAngle := (rs_GetCompassAngleDegrees);
i := StrToFloatDef(CompassDirection,-1337);
if i = -1337 then
begin
case LowerCase(CompassDirection) of
'n': DirectionDeg := 0;
'w': DirectionDeg := 270;
's': DirectionDeg := 180;
'e': DirectionDeg := 90;
'random', 'rand': DirectionDeg := RandomRange(0, 360);
end;
end else
DirectionDeg := FixD(i);
end;
end;
SetCompass := (StartAngle > -1) and (DirectionDeg > -1);
if SetCompass then
if (MinE(Abs(StartAngle - DirectionDeg), MinE(Abs(StartAngle - (DirectionDeg + 360)), Abs((StartAngle + 360) - DirectionDeg)))) <= 8.0 then
SetCompass := False;
if SetCompass then
begin
i := 0.0;
Left := (Round((360 - StartAngle) + DirectionDeg) mod 360 <= Round((StartAngle + 360) - DirectionDeg) mod 360);
KeyDown((Integer(not Left) * 2) + 37);
end else
Set0 := true;//to break out of loop
if SetHeight then
begin
KeyDown((Integer(not Highest) * 2) + 38);
TimeOut := 1000 + Random(300);
end else
Set1 := true;
MarkTime(Mark);
repeat
wait(1);
if SetCompass and (not Set0) then
begin
Angle:= rs_GetCompassAngleDegrees;
if ((TimeFromMark(Mark) > 6000) and (i < 1.0)) or
((TimeFromMark(Mark) > 10000) and (i < 2.0)) or
((TimeFromMark(Mark) > 14000) and (i < 3.0)) then
i := i + 1.0;
if ((MinE(Abs(Angle - DirectionDeg), MinE(Abs(Angle - (DirectionDeg + 360)), Abs((Angle + 360) - DirectionDeg)))) <= (7.0 + i))
or (TimeFromMark(Mark) > 14000)
or (Angle < 0) then
begin
KeyUp(Integer(not Left)*2+37);
Set0 := true;
end;
end;
if SetHeight and (not Set1) then
if (TimeFromMark(Mark) >= TimeOut) then
begin
KeyUp((Integer(not Highest) * 2) + 38);
Set1 := true;
end;
until (Set0 and Set1) or (TimeFromMark(Mark) > 14000);
for k := 37 to 40 do
begin
KeyDown(k);
KeyUp(k);
end;//sometimes doesn't release keys, this makes sure they are all reset
if SetCompass then
Result := ((MinE(Abs(Angle - DirectionDeg), MinE(Abs(Angle - (DirectionDeg + 360)), Abs((Angle + 360) - DirectionDeg)))) <= (7.0 + i))
else
Result := not SetCompass;
end;
Edit: Updated it again. For some reason the keys will stick randomly, so I added a loop to push and release them all at the end, this seems to solve it.