Reputation Activity
-
AnIdioticMonkey got a reaction from Stealth22 in Getting the closest set location? [SOLVED]Great, thanks! That's much easier!
-
@AnIdioticMonkey
Add your three locations to a List. Then...
Vector3 closestPoint = myLocationList.OrderBy(x => x.DistanceTo(Game.LocalPlayer.Character.Position)).FirstOrDefault();
It'll return the closest Vector3, or null if nothing was found.
Edit: I think that's the syntax. I normally code in VB.NET, so my C# is a bit rusty if I don't have Visual Studio in front of me.
-
How are you checking the distance? There's a method which takes a vector3 and gives you the travel distance
-
AnIdioticMonkey reacted to khorio in Getting the closest set location? [SOLVED]Vector3.traveldistanceto()
-
That's one of the common ways to do it. I would test what results you get with Vector3.TravelDistance()
http://docs.ragepluginhook.net/html/C1AEA24D.htm
http://docs.ragepluginhook.net/html/FF036733.htm
I've used it plenty of times and it's always been accurate for me. I had a list of spawn points that I would loop through and check their distance to the LocalPlayer
-
Vector3 pos1 = Game.LocalPlayer.Character.Position.GetOffsetPositionFront(50f); Vector3 pos2 = Game.LocalPlayer.Character.Position.GetOffsetPositionFront(65f); Vector3 pos3 = Game.LocalPlayer.Character.Position.GetOffsetPositionFront(80f); float pos1travel = Game.LocalPlayer.Character.Position.TravelDistanceTo(pos1); float pos2travel = Game.LocalPlayer.Character.Position.TravelDistanceTo(pos2); float pos3travel = Game.LocalPlayer.Character.Position.TravelDistanceTo(pos3); if(pos1travel <= pos2travel && pos1travel <= pos3travel) { //pos1 } else if(pos2travel <= pos1travel && pos2travel <= pos3travel) { //pos2 } else { //pos3 }
When you're checking the first distance, you should check it against all available distances (eg, pos2 and pos3). I'd check less than or equal to because if they're equal. Obviously if you have more than a few values to check, this solution wouldn't be the best as it would become very messy to maintain as you add values.
-
I highly recommend not using TravelDistance in these kind of checks as it takes into account various path nodes.
DistanceTo is highly preferred here and is standard.
-
blip = new Blip(Entity);
blip.Color = Color.Whatever;
blip.EnableRoute(Color.Whatever);
-
AnIdioticMonkey reacted to LtFlash in Key Detection ProblemsTry to insert "break;" after "toAcceptTimer.Enabled = false;" It will stop the while(true) loop so the control will return where it should be.
-
AnIdioticMonkey reacted to LtFlash in Key Detection ProblemsGreat to hear it worked!
-
AnIdioticMonkey reacted to LtFlash in Key Detection ProblemsDefinitely, it should not happen but I don't see a reason why it is so. You can put the while(true) into new fiber like that:
GameFiber.StartNew(delegate
{
while (true)
{
//
GameFiber.Yield();
}
}
);
and see what happens.