AI Relations (Scripting): Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
No edit summary
 
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Original_Reference|Ishtvan|1636}}
{{Original_Reference|Ishtvan|1636}}
The most recent CVS distribution includes the following new script functions that make use of the AI team relations code.


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.
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.
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 <tt>$sys::getRelNum( A, B )</tt>. 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 ==
== Scripts that can be run from Actor Entities ==
Line 11: Line 9:
  // get the relationship number for how this actor feels about the other actor (gives an error if the entity argument is not an actor)
  // 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::getRelNumEnt( entity ent)
ai bobAI = $Bob;
  float relation = bobAI.getRelationEnt( $Bill );
   
   
  // returns 1 if friendly, enemy, neutral, etc, 0 otherwise.
  // returns 1 if friendly, enemy, neutral, etc, 0 otherwise.
float entity::isFriend( entity ent )
float entity::isEnemy( entity ent )
float entity::isNeutral( entity ent )
Example:
$imp.isEnemy( player )


== Scripts that run from the global $sys object ==
== Scripts that run from the global sys object ==
  // like getRelNumEnt, except it takes two team numbers to return how team1 feels about team2
  // like getRelNumEnt, except it takes two team numbers to return how team1 feels about team2
  float sys::getRelNum( float team1, float team2 )
  float sys::getRelNum( float team1, float team2 )
Line 36: Line 28:
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.
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.


[[Category:Scripting]]
== See also ==
[[Category:AI]]
* [[AI Relations (Editing)]]
 
{{scripting}} {{ai}}

Latest revision as of 14:32, 6 July 2018

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)

ai bobAI = $Bob;
float relation = bobAI.getRelationEnt( $Bill );

// 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