How does a pawn know when is damaged and when it's health attribute has reached zero?
For basic needs RF has a great system. The one that also PerfectAI uses. You can add a health attribute for the pawn with the high level command AttributeOrder(). The health system works a bit differently depending on if the pawn is executing high or low level orders.
High level: When the health attribute goes to 0 the order, which you gave to AttributeOrder() as a parameter, is executed. That's usually an order for the pawn's death. Additionally, you can add a pain order with the AddPainOrder() command. Then, every time the pawn is damaged that order is executed automatically.
Low level: There's a built-in variable called self.health that tells how much health the pawn has. In low level you have to check manually if the health has been reduced to 0. The low level equivalent for AddPainOrder() is the variable self.in_pain which tells if the pawn has been damaged. That's also something you have to check manually.
This system that should work most of the time. If you don't need special health attributes (for different damage types etc.) then this is what you should use. Also, if you have high level orders that take a long time to execute (moving, playing animations etc.) this is your only option since there's no way to break out of a high level command other than AttributeOrder() and AddPainOrder(): Let's say your pawn is moving between two scriptpoints and you shoot it. If you don't use the default health system you can't break out of the move-command to check if the pawn has been damaged and so you have to wait for the pawn to reach the scriptpoint before it receives any damage.
The biggest downside of the whole AddAttributeOrder() thing is that you can't have multiple health attributes for different damage types. And that's what I wanted when I wrote the AI for Nirhis so I used normal attributes. I just gave each pawn a health attribute with the AddAttribute() command and checked manually if it has been damaged. And that's where the check_damage() method steps in. With the AddAttributeOrder()-system it's easy to check if a pawn is damaged with the self.in_pain variable. I wanted something similar. I didn't wanna write
if(GetAttribute(HEALTHATTRIBUTE) < lasthp) everywhere, so I wrote a method to check if the pawn has been damaged, then bleed, and ultimately if the health reached zero, kill the pawn.
I hope that clears the whole pawns' health stuff.
And now on to your problems.
First off, there's a syntax error in your check_damage() method. You're missing one closing bracket
}. Also, there's no splatter() method in your script. It's another method I wrote to spill blood on the walls around the pawn whenever it is hit.
Secondly...
Code: Select all
if (self.health < lasthp)
{
self.think = "check_damage";
return 0;
}
That's not how you should use it.
The check_damage() method always checks if the pawn has been damaged so there's no need to do it twice. In addition, self.think is used to jump between orders. You only need to execute check_damage() once and then return back to the original order. So you should simply call the method:
And finally, you should decide if you wanna do it the AddAttributeOrder()-way (AddPainOrder(), self.health, self.in_pain) or the AddAttribute()-way (SetAttribute(), GetAttribute() etc.). I think the SetAttribute(), GetAttribute() and ModifyAttribute() commands work on attributes given to the pawn with the AddAttributeOrder() as well. But self.health and self.in_pain won't work with attributes given with AddAttribute(). I hope I'm not confusing you too much.
This is the topic, where I needed a hjelp on how to make perfectai search for the nearest pawn from another group and then attack it. Everything's fine there, but when the hostile pawns detect the player in their range, they forget about the other pawns that they are fighting with, and start attacking the player (only) . It's like the player is more important to the enemy pawns than the other pawns (normal.. ), but is it possible to make the pawns detect the player... I dunno, as another pawn, so they all don't don't forget the other pawns?
Dunno, judging from the piece of script I posted in that thread they shouldn't do that.
I'll test it when I got time.
When the pawn is chasing the player and the player goes through a doocase, sometimes collides with the wall (it can't aim properly at the doorcase) and than starts it's avoidance order, which is just looking rediculus (you know it, whith the backing up than strafing left, then going forward on adn on and on) would it be possible to make the pawn...somehow be aware of the walls and be aware of the doorcases and others like them, I need the pawn to know where it can go and where it cannot. I know there are commands for calculating the distances of the walls and stuff, but I don't know if they could be useful for this.
I actually managed to pull this off with a very basic pathfinding. But the thing is my level is very linear: It only has two directions, north and south and the pawns are able to navigate through the level using predefined paths. But in more complex levels it gets really complicated. Especially since RF lacks built-in pathfinding. I guess you could somehow try to guess where the door is by comparing the distances to nearby walls or something. Or maybe even have an invisible pawn to act as a marker of some sort. I'll have to think about this and get back to you if I come up with something.
Phew, another wall of text. You all love to read these, don't ya?
Pain is only psychological.