View previous topic :: View next topic |
Author |
Message |
scramble
Joined: 06 Feb 2009 Posts: 3
|
Posted: Sat Feb 07, 2009 1:46 am Post subject: 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. |
|
Back to top |
|
 |
MauveBib

Joined: 04 Nov 2004 Posts: 602
|
Posted: Sat Feb 07, 2009 2:11 am Post subject: |
|
|
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. _________________ Apathy Now! |
|
Back to top |
|
 |
scramble
Joined: 06 Feb 2009 Posts: 3
|
Posted: Sun Feb 08, 2009 6:31 am Post subject: |
|
|
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. |
|
Back to top |
|
 |
Willem
Joined: 23 Jan 2008 Posts: 73
|
Posted: Sun Feb 08, 2009 10:15 am Post subject: |
|
|
Quote: | 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. _________________ www.wantonhubris.com |
|
Back to top |
|
 |
scramble
Joined: 06 Feb 2009 Posts: 3
|
Posted: Mon Feb 09, 2009 11:33 am Post subject: |
|
|
Hey Willem Thanks heaps! I cant believe that after everything ive tried it came down to 3 lines of code |
|
Back to top |
|
 |
|