First quake c question
Moderator: InsideQC Admins
5 posts
• Page 1 of 1
First quake c question
Hey Inside3d first post here i go
Ive been looking all over the qc files but to not avail. Can someone please point me in the direction of which function is used by the Ai to set the player as the enemy?
Im specificaly trying to get the Ai to target another entity and only the player if that entity cant be found.
Ive been looking all over the qc files but to not avail. Can someone please point me in the direction of which function is used by the Ai to set the player as the enemy?
Im specificaly trying to get the Ai to target another entity and only the player if that entity cant be found.
- scramble
- Posts: 3
- Joined: Fri Feb 06, 2009 11:09 pm
That's slightly trickier than you'd expect. The QC uses an inbuilt engine function called checkclient(), which returns a client entity each frame for the monsters to check if they can see. It only returns client entities, i.e. players, which means searching for other types of enemies is harder.
You need to do a findradius, check visibility and range and pick an enemy from that. Check out the bot_find_enemy function in the tutor bot over at the AI Cafe as an example.
You need to do a findradius, check visibility and range and pick an enemy from that. Check out the bot_find_enemy function in the tutor bot over at the AI Cafe as an example.
Apathy Now!
-

MauveBib - Posts: 634
- Joined: Thu Nov 04, 2004 1:22 am
hey MauveBib thanks heaps for the help. Your not wrong about it being trickier than i thought.
so far ive got a function like this (ripped from The Ai Cafe tutorials already one step ahead in that sense)
// ------------------------------------------------
void() SearchForItems =
// ------------------------------------------------
{
local entity item;
item = findradius(self.origin, 1500);
while(item)
{
if ( (item.classname == "NormalFruit") || (item.classname == "PoisonFruit") )
{
self.goalentity = item;
}
item = item.chain;
}
};
which works fine the ai walks towards the entity while it exists.
I also took your advice and converted the bot_look_for_enemy function to look like this
// ------------------------------------------------
void() SearchForPlayer =
// ------------------------------------------------
{
local entity found, foe;
// bots aren't clients, so we have to check fo them manually
// we just see if any of the bots in the entity list are visible
if (self.enemy)
return;
found = world;
foe = find(world, classname, "player");
while(foe)
{
if (visible(foe) && foe != self && foe.health > 0)
found = foe;
foe = find(foe, classname, "player");
}
if (found != world)
{
self.enemy = found;
self.goalentity = found;
}
};
which works fine also the Ai move towards the player.
But i cant firgure out how i would check if SearchForItem finds nothing so it can then call SearchForPlayer.
Ive tried a few different things but im kinda stumped again.
basicaly just trying to tell the Ai no matter what if there is an entity with the classname "NormalFruit" or "PoisonFruit" to always target it, if there are no items present with that classname target the player
Any help is greatly appreciated.
so far ive got a function like this (ripped from The Ai Cafe tutorials already one step ahead in that sense)
// ------------------------------------------------
void() SearchForItems =
// ------------------------------------------------
{
local entity item;
item = findradius(self.origin, 1500);
while(item)
{
if ( (item.classname == "NormalFruit") || (item.classname == "PoisonFruit") )
{
self.goalentity = item;
}
item = item.chain;
}
};
which works fine the ai walks towards the entity while it exists.
I also took your advice and converted the bot_look_for_enemy function to look like this
// ------------------------------------------------
void() SearchForPlayer =
// ------------------------------------------------
{
local entity found, foe;
// bots aren't clients, so we have to check fo them manually
// we just see if any of the bots in the entity list are visible
if (self.enemy)
return;
found = world;
foe = find(world, classname, "player");
while(foe)
{
if (visible(foe) && foe != self && foe.health > 0)
found = foe;
foe = find(foe, classname, "player");
}
if (found != world)
{
self.enemy = found;
self.goalentity = found;
}
};
which works fine also the Ai move towards the player.
But i cant firgure out how i would check if SearchForItem finds nothing so it can then call SearchForPlayer.
Ive tried a few different things but im kinda stumped again.
basicaly just trying to tell the Ai no matter what if there is an entity with the classname "NormalFruit" or "PoisonFruit" to always target it, if there are no items present with that classname target the player
Any help is greatly appreciated.
- scramble
- Posts: 3
- Joined: Fri Feb 06, 2009 11:09 pm
But i cant firgure out how i would check if SearchForItem finds nothing so it can then call SearchForPlayer.
That shouldn't be a big deal. You could do something like, at the top of SearchForItem set self.goalentity = world. Then at the end of the function if self.goalentity is still == world then, logically, it couldn't find an item.
- Willem
- Posts: 73
- Joined: Wed Jan 23, 2008 10:58 am
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest