Well, i needed this for my script and i thought maybe someone would like it
. It is so complicated because you can also let it rotate between like 270 and 20.
I will give a example of how this works:
RandomCompass(50,300,10,'n')
This will make the compass a random degree between 50 and 300. It will stop rotating if the Compass is in a range of -5 or +5 of the new degree. If messes up somehow it will make the compass North.
Another example:
RandomCompass(280,20,20,'s')
This will make the compass a random degree between 280 and 20, BUT it chooses a value like 340,300,12,288,8 etc. So basicly it will start from MinAngle and stop at MaxAngle
. This one stops rotating if the Compass is in a range of +10 or -10 of the new degree and if it messes up it will make the compass South.
P.S. if you fill in 0 range it will change it to 10. You really need a range value because the Compass detection isn't 100% perfect. I think you need like 8-14 more is always possible
. Sometimes it will turns the wrong side, but this is because lag or because it doesn't return the right degree of the compass
If anyone can make this more clear in proper English please do it
. Or if you know a faster way, tell me.
~Raymond
Oh and fix this, found it while i was playing with compass functions!: http://www.srl-forums.com/forum/show...hlight=compass
SCAR Code:
{*******************************************************************************
Procedure RandomCompass(MinAngle,MaxAngle,Range:integer;AltAngle:char);
By: Mastaraymond
Description: It changes the compass to a random degree value between MinAngle and MaxAngle.
Valid Arguments:
MinAngle = This must be the starting degree, fill in something between 360
MaxAngle = This must be the maximum degree, fill in something between 360
Range = It will stop turning if the current compass degree is in the of the random one range.
AltAngle = If it messes up it will make the compass North, South, East or West. 'n','s','e' or 'w'.
*******************************************************************************}
Procedure RandomCompass(MinAngle,MaxAngle,Range:integer;AltAngle:char);
var
I,II,K,Duration,TheKey,MaxAngleNew:integer;
IsOverNull,Checker:Boolean;
begin;
if Range = 0 then Range := 10;
Range:= Round(Range div 2);
If MinAngle > MaxAngle then
begin;
MaxAngleNew := MaxAngle + 360;
IsOverNull:=True;
end else
begin;
MaxAngleNew:=MaxAngle;
IsOverNull:=false;
end;
I:= RandomRange(MinAngle,MaxAngleNew);
If I >= 360 then II:= I - 360
else II := I;
K:= trunc(rs_GetCompassAngleDegrees);
if ((Abs(II-K)) < 10) then
repeat
I:= RandomRange(MinAngle,MaxAngleNew);
If I >= 360 then II:= I - 360
else II:=I;
Wait(10);
until not((Abs(II-K)) < 10)
if IsOverNull then if ((K <= 360) and (K >= MinAngle)) or ((K>=0) and (K <=MaxAngle)) then Checker:=true;
if Checker then
Begin;
if ((MaxAngle - I) < 5) then I:= I-(5+Random(30));
If ((I - MinAngle) < 5) then I:= I+(5+random(30));
if (I>=360) then I:= I - 360;
if (K=I) then
begin;
MakeCompass(AltAngle);
Exit;
end;
if (I>= MinAngle) and ( I<=360) then
begin;
if ( K >= MinAngle ) and ( K <= 360 ) then
begin;
if K > I then TheKey:= VK_left
else if K < I then TheKey:= VK_right;
end else TheKey:=VK_left;
end else if ( I>= 0) and ( I<=MaxAngle) then
begin;
if ( K >= 0 ) and ( K <= MaxAngle ) then
begin;
if K > I then TheKey:= VK_left
else if K < I then TheKey:= VK_right;
end else TheKey:=VK_right;
end else
begin;
MakeCompass(altAngle);
Exit;
end;
Duration:=GetSystemTime;
KeyDown(TheKey);
Repeat
Wait(50);
if ((GetSystemTime - Duration) >= 10*1000) then
begin
KeyUp(TheKey);
MakeCompass(AltAngle);
exit;
end;
until (InRange((trunc(rs_GetCompassAngleDegrees)),II-range,II+range))
KeyUp(TheKey);
end else
begin;
if K > I then TheKey := VK_Left
else if K < I then TheKey := VK_Right
else begin;
MakeCompass(AltAngle);
exit;
end;
Duration:=GetSystemTime;
KeyDown(TheKey);
Repeat
Wait(50);
if ((GetSystemTime - Duration) >= 10*1000) then
begin
KeyUp(TheKey);
MakeCompass(AltAngle);
exit;
end;
until (InRange((trunc(rs_GetCompassAngleDegrees)),I-range,I+range))
KeyUp(TheKey);
end;
end;