Aller au contenu

Photo

Bad AI when npc chases pc.


  • Veuillez vous connecter pour répondre
17 réponses à ce sujet

#1
Uther78

Uther78
  • Members
  • 18 messages
I have noticed that when the PC escapes from enemies following a
straight line, the enemies with melee weapon can't hit him, even if they
are more fast.I have tried to fix this, but I have not found a solution. Any idea?

#2
ffbj

ffbj
  • Members
  • 593 messages
You could try something like if the PC is farther than 2 meters from the npc the npc will switch to their missile weapon and use that to attack the PC. I use a little more complexity than that for some creatures, such as scouts, who will go into stealth and sometimes track the PC. That has been quite a surprise to some people.

#3
Genisys

Genisys
  • Members
  • 525 messages
Missle weapons = Lag though right?

#4
Uther78

Uther78
  • Members
  • 18 messages

Genisys wrote...

Missle weapons = Lag though right?


Really?

#5
Terrorble

Terrorble
  • Members
  • 194 messages

Uther78 wrote...

Genisys wrote...

Missle weapons = Lag though right?


Really?


I thought I actually got around lag by giving some of my NPCs ranged weapons.  Instead of having to pathfind their way across a bridge or around buildings, they just start shooting.  Seems simple.

#6
Daybringer

Daybringer
  • Members
  • 14 messages
Actually this guy posted such not too long ago on nwvault...



http://nwvault.ign.c....Detail&id=3761



Might help ^^;

#7
Uther78

Uther78
  • Members
  • 18 messages

Daybringer wrote...

Actually this guy posted such not too long ago on nwvault...

http://nwvault.ign.c....Detail&id=3761

Might help ^^;



That guy is myself, I have tried to fix the problem with a speed penalty for the PC, but I dont like that solution, i prefer a fix for the npc A.I.

#8
Uther78

Uther78
  • Members
  • 18 messages
I have made this script: it seems work



#include "x0_i0_position"



void main()





{

object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);



ClearAllActions();



if (GetDistanceToObject(oPC) < 8.0f)



if (GetDistanceToObject(oPC) > 3.0f)

{

ActionMoveToLocation(GetAheadLocation(oPC), TRUE);

ActionMoveToLocation(GetAheadLocation(oPC), TRUE);



ActionMoveToLocation(GetAheadLocation(oPC), TRUE);

}









ActionAttack(oPC);

}




#9
Uther78

Uther78
  • Members
  • 18 messages
Nobody has an opinion?

#10
ffbj

ffbj
  • Members
  • 593 messages
There are a number of problems with that script. So there you have an opinion.  Here is a little doctoring off the top of my head with some hopefully helpful comments or additions:

#include "x0_i0_position"
void main()
{
object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);
//effect eSpeed = EffectMovementSpeedIncrease(125);
//change number to change speed.  added for possible temporary speed increase.

ClearAllActions();
// you probably want to use the TRUE parameter here as this is likely to occur
// in combat otherwise the ClearAllActions call will have no effect.

if (GetDistanceToObject(oPC) < 8.0f)
//so do what if this condition exists, do nothing?  Maybe you wanted a return
//here or better switch to a ranged weapon if creature has one. If not just
// go into stealth and move away.
//Or maybe you are saying if the PC is within a certain range >3 and <8 meters
// do the following.  If so then write it as one statement:
//if ((GetDistanceToObject(oPC) >= 3.0f) && (GetDistanceToObject(oPC) <= 8.0f))
// do this the chase stuff, else do something else.  Condition not met PC is not
// between 3.0 and 8.0 meters, changed to or equal too.
if (GetDistanceToObject(oPC) > 3.0f)
{
ActionMoveToLocation(GetAheadLocation(oPC), TRUE);
//not sure that you need to keep repeating this.
//maybe use a delay command of a few seconds if the chasing
//npc seems to be losing it's target
ActionMoveToLocation(GetAheadLocation(oPC), TRUE);
ActionMoveToLocation(GetAheadLocation(oPC), TRUE);
}
//if (GetDistanceToObject(oPC) < 1.0f)
// added this in. So no point attacking unless you are actually there in contact

ActionAttack(oPC);

//else ActionMoveToLocation(GetAheadLocation(oPC), TRUE);
//ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSpeed, OBJECT_SELF, 3.0);
ActionAttack(oPC);
}
 

Modifié par ffbj, 29 août 2010 - 04:42 .


#11
Uther78

Uther78
  • Members
  • 18 messages

ffbj wrote...

There are a number of problems with that script. So there you have an opinion.Etc...
 


Thank you very much.

Yes, I want the NPC charges the PC when is distance is between 3 and 8 meters. Your advice are helpful.

Your idea of a speed improvement during the charge is good.

I have repeated the ActionMoveToLocation because in this way the npc's charge seems more accurate and for the PC is more difficult to escape. I dont think that a delay will be useful.

The clearallactions without the TRUE attribute are uneffective, but the script worked all the same: then maybe is unnecessary to clear the actions.

here are the last part you added:

(//if (GetDistanceToObject(oPC) < 1.0f)
// added this in. So no point attacking unless you are actually there in contact

ActionAttack(oPC);)

that part seems now unnecessary because if the npc is already fighting null part of my script stop him (if we remove the clearallactions command).

Modifié par Uther78, 30 août 2010 - 12:20 .


#12
Uther78

Uther78
  • Members
  • 18 messages
Errata corrige:

the clearallactions is necessary. It works even without "TRUE" because when the enemy chase NPC is not consedered "combat"

#13
ffbj

ffbj
  • Members
  • 593 messages
It's just good practice to do a Clear All Actions call before you proceed to other activities. I recommend using the TRUE parameter since these actions are likely to occur around combat, thus the combatant being directed by them may still be flagged as being in combat. But, that is along the lines of what I would do. Just play with it and find out what works most closely to the sort of effects you are going for. Clear All Actions presuppose that there is something to clear. Not really knowing what these npc might be doing otherwise. For instance I have many monsters, creatures that will be just going about their busy, so following some activity. Then if they spot an enemy there is a Clear All Action before going into combat, and also vice-versa. The other way around when a creature has ended combat and goes back to doing some activity. Of course you don't have to use it at all and may still get what you want. This is just the approach I use, along a number of others who have advocated this use of the function.

#14
Uther78

Uther78
  • Members
  • 18 messages
Thx, if someone has an idea for improving the script, please post here.

#15
Uther78

Uther78
  • Members
  • 18 messages
Here is the updated script:



#include "x0_i0_position"







void main()







{





object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);



if (oPC != OBJECT_INVALID && GetIsEnemy(oPC))



if ((GetDistanceToObject(oPC) >= 3.0f) && (GetDistanceToObject(oPC) <= 8.0f))



{

ClearAllActions(TRUE);

ActionMoveToLocation(GetAheadLocation(oPC), TRUE);

ActionMoveToLocation(GetAheadLocation(oPC), TRUE);

ActionMoveToLocation(GetAheadLocation(oPC), TRUE);

ActionMoveToLocation(GetAheadLocation(oPC), TRUE);

}









ActionAttack(oPC);

}



Note that the command "clearallactions" are applied only if the npc-PC distance is between 3 and 8: then if the npc is already fighting with a near PC the script dont stop him.






#16
Uther78

Uther78
  • Members
  • 18 messages
How i can make the script applies twice per round?

#17
Uther78

Uther78
  • Members
  • 18 messages
I can make that the script dont applies if PC and npc are facing opposite directions?

#18
Uther78

Uther78
  • Members
  • 18 messages
I have found another solution:
If the PC escapes, the melee weaponed enemy npc uses ranged weapons without losing the chase:
http://nwvault.ign.c....Detail&id=3779

But it is not good for animals....