AI Relations (Scripting)

From The DarkMod Wiki
Jump to navigationJump to search

Originally written by Ishtvan on http://forums.thedarkmod.com/topic/1636

Background: AI in D3 have a "team" integer. The team of the player is always "0". You can set the team of any other AI in the editor, just set "team" key to some integer value.

The relationships between teams are stored in a matrix, and for now the relationship is an integer (I can make it a float later if there is great demand). To see how team A feels about team B, you run $sys::getRelNum( A, B ). This will return the integer value for the relationship. Negative values are enemy relations, zero is neutral, positive is friendly.

Scripts that can be run from Actor Entities

// get the relationship number for how this actor feels about the other actor (gives an error if the entity argument is not an actor)

float entity::AI_GetRelationEnt( entity ent)

// returns 1 if friendly, enemy, neutral, etc, 0 otherwise.

Scripts that run from the global sys object

// like getRelNumEnt, except it takes two team numbers to return how team1 feels about team2
float sys::getRelNum( float team1, float team2 )

// directly set how team1 feels about team2
void sys::setRelation( float team1, float team2, float val )

// adds the offset value to the current relationship value 
// (useful for doing stuff like having AI get incrementally less friendly towards you 
// as you do more and more suspicious stuff. When the relationship value goes negative they snap and attack)
float sys::OffsetRelation( float team1, float team2, float offset )

NOTE: Because in scripting no ints are used, just floats, these all take float arguments. However, be aware that whatever number you put in will be converted to an int in the SDK code.

See also