After reading your posts(thank you very much) I came up with this idea. Or, you guys did. But here is how you could do it.
I could have a number of arrays. And then a void to create an item.
In the parameters sent to the void I can add a couple of properties. Let's say like this:
int objects[][2];
int x = 1;
void(float filename, int useable, int character, int tree){
x++;
if (character == 1){
dbCreateObject(filename, 1);
objects[x][1]=1;
}else{
dbCreateObject(filename, x);
objects[x][1]=x;
}
objects[x][2]= useable;
int useItem(void){
int lowest;
int lowestid;
for (int i = 0; objects[i, 0] != '\0'; ++i){
if (objects[i, 1] == 1){
dist = checkDistance(idofplayer, objects[i, 0]);
if (dist < lowest){
lowest = dist;
if (lowest < 10){
lowestid = objects[i, 0];
}
}
}
}
}
if (lowestid != '\0'){
//code to get angle between 2 objects here
if (angle > -30 && angle < 30){
return lowestid;
}
}else{
return 0;
}
Oh, this code got a little messy and probably a lot of errors. Please, go ahead and ask what is what and come along with improvements, i need to short down on the "if's". This is just a code i wrote now, haven't tested yet. The basic is that it creates an array with the possibility to check if the object is useable. Then it checks for the distance of all useable objects. And when it has got the smallest distance, it checks if the winner is close enough. I put 10, dunno why. Then it checks if the player is facing it. Get it? Please, comment!