Page 1 of 1

how does a pawn decide what to attack?

Posted: Thu Apr 05, 2007 6:11 pm
by fps
How does a pawn decide which target to attack if there are two available targets within sight and both are still alive?

does it chose the one closest or the one it saw first?

if the player then enters the field of vision, what changes?

if a pawn is targeting a foe, can it be made to look for a path point at the same time?

is there a way to get the pawn to target a allied pawn to follow and look for a enemy pawn to attack?

what about attaching a point to the allied pawn to follow and targeting an enemy pawn at the same time?

what would i have to do to get a different reaction for a pawn finding the dead body of an ally and an enemy while unalert and what would i have to do to make that different from seeing that the once living pawn it targeted is now killed.


I hope that by asking these questions i will be able to build an efficient combat and survival oriented allied and enemy script set that will keep the action of my game fresh and exciting without to much repitition.

thanks,
fps

Re: how does a pawn decide what to attack?

Posted: Thu Apr 05, 2007 7:12 pm
by Jay
First of all you have to know that a pawn does not Find other Targets when it already has a target.

Also, some answers:

Question 1 + 2:
If this was really to happen (it is not very likely that two pawns enter the range at exact the same time) i think it would choose the one that was created first - the one with the the lowest 'number' in the editor. (you have this Pawn1, Pawn5, Pawn64, remeber? those are what i mean with the 'numbers')

Question 4:
Should be no problem that a a pawn can also look for a path point while targeting a pawn...

Posted: Thu Apr 05, 2007 7:58 pm
by Juutis
These things depend on the script very much.
if the player then enters the field of vision, what changes?
Nothing changes, if you don't tell anything to change - Yeah, that's kinda obvious. :)
What I mean is that you can make the pawn check if the player is visible and then do something! Target the player, for example.
if a pawn is targeting a foe, can it be made to look for a path point at the same time?
As Jay already said, yes. Pawns' attack routines are usually (if not always) executed in low level. There are commands like NextPoint, NewPoint and NearestPoint, which let you modify the pawn's scriptpoint in low level. This has nothing to do with the name of the pawn's target entity, so it's possible to make it look for a scriptpoint.
is there a way to get the pawn to target a allied pawn to follow and look for a enemy pawn to attack?

what about attaching a point to the allied pawn to follow and targeting an enemy pawn at the same time?
I guess it's possible to make a pawn follow another pawn while attacking. I can't figure out the details right now, but I strongly believe that it can be done.
what would i have to do to get a different reaction for a pawn finding the dead body of an ally and an enemy while unalert and what would i have to do to make that different from seeing that the once living pawn it targeted is now killed.
This is fairly easy to do. In theory, at least. You could make the pawns do damage in the area around them when they die. Then you could make the other pawns check if they are damaged and react accordingly.
For example: A pawn "sees" his friend die near him. The 'friend' causes damage to the attribute called 'DYING' around him. The living pawn then checks if it has received damage to the attribute 'DYING' and if so, it goes alert or something.
After playing the death animation, the dead pawn starts to do damage called 'DEAD' around it every 1 seconds. Then a third pawn comes, it checks if it has been damaged to the attribute called 'DEAD' and that way it can "see" the dead pawn.


Hope this helps. I hope you even understood what I'm saying here. :D

Posted: Thu Apr 05, 2007 8:38 pm
by zany_001
ive been wondering if there is any way to get the pawn that is attack ing and\or targeting you,or another pawn?like,put it in a variable,or flag something true?cos for my arena game,it would be veeery useful. :)

Posted: Fri Apr 06, 2007 12:16 am
by darksmaster923
zany_001 wrote:ive been wondering if there is any way to get the pawn that is attack ing and\or targeting you,or another pawn?like,put it in a variable,or flag something true?cos for my arena game,it would be veeery useful. :)
yeah. its in the scripts that came with rf.

Posted: Fri Apr 06, 2007 2:02 am
by zany_001
Whats it cal;led

Posted: Fri Apr 06, 2007 2:13 am
by darksmaster923
robot.s and theres some in the samples folder

Posted: Fri Apr 06, 2007 2:24 am
by zany_001
so theres no command for it,and you have to script it?Sad. :cry:

Posted: Fri Apr 06, 2007 2:40 am
by fps
Why is it that;
if the pawns attack in low level and it causes the frame rate to drop (or errors or somthing) when switching between high and low level to often... then why can a pawn only search for targets by group and/or the player, while in a high level function???? is this not a little odd.


on the checkig for dead bodies subject.
you said that the pawn could simply create a damage area around them when they die for other pawns to check.
A problem i have been working on for years is how to give thee pawns the ability to check for multiple damages to seperate health attributes at the same time. currently it is only possible to check for one health attribute at a time. (as to my knolage and believe me ive checked hard)

there is another way to do this apparently but i was told there would be a distinct delay because the pawn would have to cycle through the order that changed what it was checking for. (again possibly cycleing between high and low level function (see my other post about ai problems))

if i was able to do this it would be great. pawns could give verbal commands based on the damage area effect to those only in the general area around them, thus simplifying the process of looking around them and changing a targeting function to find all allied pawns that are visible. also thus elimination a serries of fliping back and forth between high and low level.

I dont think that in this facet of the pawns "personality" that i would mind a slight delay in time given to "comprehend" a verbal order or the body of a killed commrad/foe/target.
HOWEVER!!!!
The script i have in mind will be a complex one as is and switching between (or even starting with a transition between) high and low level has caused me so much trouble in the past that i have been forced to simply abandon scripts or postpone ai work till a later date. (some time past doomsday)

the pawns will already be jumping between high and low level and will have many many special functions to preform. meaning that if i go with the latter approach every few secconds the script will have to stop whatt it is doing (i believe) and jump form one order to check for the special attribute. pause againg and jump back to its previous order. rinse, repeat.
this could cause lots of difficulty.

if you can see a way to check for multile health style attributes or otherwise check for area born forms of simplistic communication i would absolutely love it!

if the pawn however could simply check for multiple health attributes at the same time, when one of them became damaged it would have its own specific pain order to got to and would automatically simplify the process to defining seperate pain oreders.

ex. (death order is simply what is executed the the damaged attribute = 0)
HealthAttribute = health
PainOrder = injury
DeathOrder = death

HealthAttribute2 = fire
PainOrder2 = burned
DeathAttribute2 = burndie

HealthAttribute3 = dyingfriend
PainOrder3 = startled
DeathOrder3 = runtohelp (restore "dyingfriend" to 5 or such to match the anim time)
(pawn would remain in shock until the allied pawn was done dying then it would run to help)(obviously too late :roll: )

HealthAttribute4 = deadfriend
PainOrder4 = foundbody
DeathOrder4 = alert

HealthAttribute5 = comandGetDown
PainOrder5 = hitthedeck
DeathOrder5 = (this would be unnessacary unless i used it to set attribute "commandGetDown" = 99999 again)


This would be a great feature for this program and would greatly improve the game i am making and probably add a lot of functionality at the same time. :D

How quick of a fix would this be?
I heard some time in the past that sombody had fixed this problem but then they left the fourm and never returned. :(

Thank you for all of your help and suggestions so far.
I am glad to see that people are willing to help me with this.

thanks,
fps

Posted: Fri Apr 06, 2007 8:48 am
by Juutis
I actually used the damaging idea in my Nirhis demo. The enemies start looking at the player instead of just walking around randomly when they spot a dead body. My AI scripts are a lot simpler, though. There's a download link in my signature, in case you want to take a look.

Anyway, in the newest RF version the AddAttribute command works like it's supposed to. So you can add as many attributes as you want to a pawn. They are not 'health attributes', however, so checking if they have decreased will have to be done manually. Basically giving them an initial value of 1000 and then checking if(ATTRIBUTE < 1000) should do it. In low level this is not a problem, since all the commands are executed every time the order is executed. But in high level you must wait for the current command to finish before you can do the check. That's why the scripts in my demo run in low level only. I don't have a good solution to this problem, other than don't use high level. :)


And yeah, target searching in low level and multiple health attributes would be a nice little feature, indeed.

Posted: Wed Apr 11, 2007 11:19 pm
by fps
don't have a good solution to this problem, other than don't use high level.
do you know if there is a simple way to get pawns to target the standard player and the scripted pawns while keeping the script all in low level?


I want it to check targets by either a group or a pawn name prefex/suffex.


Can you also show me an example of sucessful use of the multiple attributes thing like you described. i am not sure how to setup what you are describing.


thanks,
fps

Posted: Thu Apr 12, 2007 12:10 pm
by Juutis
In theory, it would be possible to make a pawn look for targets in low level.
The manual:
char* TraceToActor(char *BoneName, float OffsetX, float OffsetY, float OffsetZ );

Traces a line from the specified bone to a point defined by a specified offset and returns the szEntityName of any pawn actor that it intersects. If it does not intersect with a pawn, it returns the string FALSE. The offset is relative to the direction the pawn is facing. If the bone does not exist it returns FALSE.
Basically you could somehow scan the area with this command and then use SetTarget() to target an entity. I believe this would be very complicated, though, and a lot more ineffective than the high level target searching.



And about the multiattribute thing...
Here's a piece of one of my enemy AI scripts:

Code: Select all

		AddAttribute(HEALTHATTRIBUTE,-1000,HEALTH);
		SetAttribute(HEALTHATTRIBUTE,HEALTH);

		AddAttribute("alertdamage",-1000,1000);
		SetAttribute("alertdamage",1000);

		AddAttribute("playersound",-1000,1000);
		SetAttribute("playersound",1000);
As you can see, I have different attributes for the actual health, "alertdamage" (which gets damaged if there is a dead body near the pawn) and "playersound" (which is damaged if the player makes sounds near the pawn).

Later on the pawn checks the last two attributes with lines:

Code: Select all

if(GetAttribute("alertdamage") < 1000)

if(GetAttribute("playersound") < 1000)

Posted: Fri Apr 13, 2007 9:56 pm
by fps
thanks for the information. :D
I will try to put it to good use.


thanks,
fps