SRL Archive - News and General

Distance to The Middle Tile?


Brandon

2011-07-11 15:04:32

K this may be my last question before my script is finished..

[ATTACH]11396[/ATTACH]

In the picture attached above, I want to find the distance from two or more objects.. Inorder to Find which Door I need to Open.. See object finding finds more than one door that is 6 tiles away from the K-portal..

So the script can't find which door to open and does nothing..

I want to Find the Tile that the green object is on.. Using the purple ones.. Like Distance from All three purple portals to the middle.. or from the purple portals to the door so that I find the door tile and I know which door to open.. Basically find which door is blocking me from reaching the portal? How do I go about doing that?

Same problem for the altar.. I want to Find which door if any, is blocking me from reaching the altar..

TomTuff

2011-07-11 15:10:07

Find the teleport focus's tile. Sort the door object tiles by the distance from the teleport focus. The first door in the sorted array is the door your after (Doors[0]).

Brandon

2011-07-11 16:40:31

From: TomTuff
Find the teleport focus's tile. Sort the door object tiles by the distance from the teleport focus. The first door in the sorted array is the door your after (Doors[0]).


Thanks I got it:


//Sorts Objects By Distance From Another..
//Objects = Multiple Objects To Sort.
//SingleObject = Object To Sort From.
//SingleObjectType = Type Of Object To Sort From.
//Distance = Distance from you to the SingleObject Object to Search.

function R_SortObjects(Objects: TRSOBJECTARRAY; SingleObject, SingleObjectType, Distance: Integer): TRSOBJECTARRAY;
var
i,i2, L: integer;
tpa: TPointArray;
Obj, AltarDoor: TRSOBJECT;
begin

Obj:= R_GetObject(SingleObject, SingleObjectType, Distance);
if(R_FindObject(SingleObject, SingleObjectType, Distance, Obj)) then
Repeat
wait(RandomRange(500, 1000));
Until(R_FindObject(SingleObject, SingleObjectType, Distance, Obj));

L := GetArrayLength(Objects);
if L < 1 then Exit;
SetArrayLength(TPA, L);
SetArrayLength(Result, L);
for i := 0 to L-1 do
TPA[i] := Objects[i].Tile;
SortTPAFrom(TPA, Obj.Tile);
for i := 0 to L-1 do
for i2 := 0 to L-1 do
if (TPA[i].x=Objects[i2].Tile.x) and (TPA[i].y=Objects[i2].Tile.y) then
Result[i] := Objects[i2];
end;

TomTuff

2011-07-11 18:23:26

I advise against using SetArrayLength over SetLength.

Bonfield

2011-07-11 18:47:21

Me to, I think setarraylength acts strange sometimes, not sure what causes it I will try to find some posts, setlength is the correct way to do it

mormonman

2011-07-11 19:40:04

Also, Length() over GetArrayLength()

Brandon

2011-07-11 19:43:27

Hmmm Thats odd because I Learned how to Do the Sorting from the: SortNPCs function..

And it used SetArrayLength and GetArrayLength so thats how I always used it :S So does that mean the SortNPCs is bad? Actually What is bad about it? Im just curious. I'll change it but I really wanna know now.

Bonfield

2011-07-11 20:43:55

I'm pretty sure wizzup? And zytex both posted in a thread about this, but I can't remember correctly i am going to have a guess and say it might be the same reason you shouldn't really use byte, they just behave odd every now and then

Brandon

2011-07-11 23:49:08

Umm I didn't wanna make a new thread because I have three on the first page already -_____-
My script is finished and compiled well before I added the code below..
I get Exception in Script: Access violation. And it doesn't highlight what is causing it..

can you guys tell me why I get access violation doing this:


const
Logs1 = false; //Walk To the First log (No Ghasts attack here, Only one log per bloom = One Mushroom per bloom)
Logs2 = true; //Walk To the Second Log (Ghasts Can Attack here, Two logs Per bloom = Two mushrooms per bloom)
FoodToEat = 385; //385 = shark..
HPToEatAt = 500; //Eats when HP Gets Below this Number..
DisableSwampWarning = true; //Disables the Warning About the swamp being dangerous..

Procedure EnterSwamp;
var
MyPos: TTile;
begin
MyPos:= R_GetMyPos;
If(R_ValidInterface(SwampWarningInterface)) then
begin
if(DisableSwampWarning = true) then
begin
Repeat
debug('Disabling Swamp Warning');
R_ClickInterface(R_GetInterfaceChild(SwampWarningInterface, SwampWarningCheckBox), 1);
wait(500 + Random(500));
Until(R_GetInterfaceChild(SwampWarningInterface, SwampWarningCheckBox).TextureID = CheckBoxCheckedTexture);
end else
begin
debug('Entering The Swamp.. SwampWarningDisable = false.');
Repeat
R_ClickInterface(R_GetInterfaceChild(SwampWarningInterface, SwampWarningText, 1));
wait(500 + Random(500));
Until((MyPos = Point(3444, 3457)) or (MyPos = Point(3443, 3457)) or (R_ValidInterface(SwampWarningInterface) = false));
end;
end;
end;