-
Notifications
You must be signed in to change notification settings - Fork 0
Virtual functions
All NPCs in the library share a set of common virtual functions. Which allow them to define custom behaviors on a per-class basis. For example, defining custom attack decision code, without having to create your own chase function from scratch, or glue the code on top of existing code.
- None
- None
Used to set the actors' default user variable values, for variables that did not have a custom value passed to them in the editor. GZDoom already has a //$UserDefaultValue editor key. However only works for actors spawned by the map. While this function allows for values to also be set for actors spawned by ACS or the console.
Say your NPC has a User_SpecialAttackChance variable, allowing mappers to define how likely the actor is to do a special attack. The default chance should be 24 out of 255 for every time it attacks. //$UserDefaultValue can set the default value for NPCs placed on the map. But the default value will be kept to 0 for NPCs spawned through ACS, or the console.
//$UserDefaultValue 24
Int User_SpecialAttackChance; //How often does the NPC do its' AOE attack ?
This is where UserVariableDefaults() helps:
Override Void UserVariableDefaults()
{
If (User_SpecialAttackChance == 0) User_SpecialAttackChance = 24; //Default AOE chance.
}
- None
- True or false.
Returns whether or not the NPC can currently attack, by default it just checks if the actor has a missile or melee state, is not dead, and is not in a SECF_NOATTACK sector. More or less vanilla behavior.
- NoStateJump: If true, the actor should not jump to any state even if the function returns true. This needs to manually be obeyed by overrides to this virtual.
- Returns true if the actor should attack, and also makes them actually enter the intended attack state if NoStateJump is off.
This virtual is the attack decision code of KAI NPCs. By default, it is to be used by chase functions to determine what attack the NPC should perform, if any, and make them actually go to that state. Overriding it allows for custom attack decision code on a per-actor basis, without needing to write new chase functions or other hacks.
By default, this virtual is a mostly direct ZScript rip of A_Chase's attack decision code. So naturally, it behaves the same as well.
- None
- None
Allows executing code every time KAI_Wander() is called.
- None
- Returns a Vector3 coordinate to the location at which the NPC is going to attack.
Used to determine where the NPC is going to attack at.
If the NPC has a target, it returns their position, otherwise it returns a null vector[^1].
Note: This is a ClearScope function. So that it can be called from KAI_LOFRaycast as well.
- Other: The actor to check if it is hostile.
- Returns true if Other is hostile, false otherwise
Checks if the Other actor is an enemy to the calling KAI NPC or not. Can be used to give NPCs different conditions for if another actor is an enemy or not. Like for making an enemy NPC that doesn't always consider other NPCs to not be hostile like IsHostile() does.
Just calls IsHostile() by default.
TBD: Maybe try making this into its' own page to include the Baron of Hell example ? Or put more info on using the threat level system on the feature page.
- Other: The actor whose threat level should be assessed.
- CheckPlayers: Should players be returned as THREAT_UNSTOPPABLE if they have buddha or god mode. Or be automatically returned as THREAT_DANGEROUS otherwise ? Default is false.
- Returns a threat level (Integer).
[^1]: A vector with a value of (Double.NaN,Double.NaN,Double.NaN), or -2147483647 on each member. Which is returned as an empty Vector3 by IsEmptyVector3.
- Home
- Features
- Classes
- Functions
- Guides