(I appoligize for not citing my sources-- I will edit this post in the morning when I'm not on my iOS)
Unless otherwise noted, I am not the owner of the algorithms/concepts. I am simply trying to compile a helpful and yet non-spoon-fed manuscript (or list rather) for those embracing the "next step".
As noted by streppel, If you don't understand math, hold off on making a bot for now and come back when you've learned something in math class.
I'm going to dump more later, but let's start with the easy stuff.
Target nearest NPC using Euclidian Distance
(Euclidean distance - Wikipedia, the free encyclopedia)
Your going to need the Non-dynamic (static?) X,Y,Z addresses for the player. I would dump mine, but I'm not using windows and such addresses differ.
From that point, compute the difference between X,Y,Z of the target object and the X,Y,Z of the player.
The result that you should compare Amongst other objects is sqrt(xdif*xdif + ydif*ydif + zdif*zdif)
Now compare all results for every target object, and get the result that holds the lowest value.
Personally I do the brute force method which is about n^2 processor speed (being the worst and longest)
Plug the GUID low and GUID high into the non-dynamic (static?) last target address spaces.
Use the macro "/targetlasttarget" or the hotkey for target las target, and presto-- the nearest target is targeted!
If you really want the Objective-C dumped (a Mac lang. and not windows), then here they are.
How I handle getting the closest Object's position
Code:
- (DSObject*)closestDSObjectFromList:(NSArray*)theObjectList DSObjectType:(NSString*)aObjectType{
NSMutableArray* distanceFromArray = [[NSMutableArray alloc] init];
float distanceFrom = INFINITY;
float selfX = [DSMemory readFloat:0x11F8FF4 withSize:sizeof(float)];
float selfY = [DSMemory readFloat:0x11F8FF8 withSize:sizeof(float)];
float selfZ = [DSMemory readFloat:0x11F8FFC withSize:sizeof(float)];
for (DSObject* targetObject in theObjectList)
{
float xDif = [[targetObject objectXPos] floatValue]-selfX;
float yDif = [[targetObject objectYPos] floatValue]-selfY;
float zDif = [[targetObject objectZPos] floatValue]-selfZ;
distanceFrom = sqrt(xDif*xDif + yDif*yDif + zDif*zDif);
if (distanceFrom == 0) {distanceFrom = INFINITY;}
[distanceFromArray addObject:[NSNumber numberWithFloat:distanceFrom]];
}
NSLog(@"Distance Array (UNSORTED): %@",distanceFromArray);
if (aObjectType != nil)
{
NSUInteger possibleValueIndex = [distanceFromArray indexOfObject:[distanceFromArray valueForKeyPath:@"@min.floatValue"]];
int i = 0;
while (![aObjectType isEqualToString:[[theObjectList objectAtIndex:possibleValueIndex] objectType]])
{
NSLog(@"Trying Index: %lu which holds Object: %@",possibleValueIndex,[distanceFromArray valueForKeyPath:@"@min.floatValue"]);
NSLog(@"Trying object # %d/%lu",i,[distanceFromArray count]-1);
[distanceFromArray removeObjectAtIndex:possibleValueIndex];
possibleValueIndex = [distanceFromArray indexOfObject:[distanceFromArray valueForKeyPath:@"@min.floatValue"]];
i++;
}
return [theObjectList objectAtIndex:possibleValueIndex];
}
else
{
return [theObjectList objectAtIndex:[distanceFromArray indexOfObject:[distanceFromArray valueForKeyPath:@"@min.floatValue"]]];
}
}
How Tarnias4 handles distance and then getting the closest node (He has a function for each separate game object whereas I can just enter my own criteria)
(Thanks to Tarnais4 for his source obviously!)
Code:
- (float)distanceToPosition: (Position*)position { float distance = INFINITY;
if(position && ([self xPosition] != INFINITY && [self yPosition] != INFINITY && [self zPosition] != INFINITY)) {
float xDiff = [position xPosition] - [self xPosition];
float yDiff = [position yPosition] - [self yPosition];
float zDiff = [position zPosition] - [self zPosition];
distance = sqrt(xDiff*xDiff + yDiff*yDiff + zDiff*zDiff);
}
return distance;
}
- (Node*)closestNode:(UInt32)entryID {
Position *playerPosition = [(PlayerDataController*)playerData position];
Node *closestNode = nil;
float closestDistance = INFINITY;
float distance = 0.0f;
// add gas clouds
NSMutableArray *nodes = [NSMutableArray arrayWithArray:_objectList];
[nodes addObjectsFromArray:[self allGasClouds]];
for(Node* node in nodes) {
distance = [playerPosition distanceToPosition: [node position]];
if( [node isValid] && [node entryID]==entryID && (distance <= closestDistance) ) {
closestDistance = distance;
closestNode = node;
}
}
return closestNode;
}
Get a position on the screen for an in-game position
(Thanks to Tarnais4!)
Coming soon..