Skip to content

Script: Other things

poVoq edited this page Jun 19, 2013 · 2 revisions

Here are some misc. details on scripting taken from the Warsow wiki.


1. Game Object Classes

1.1. cBot

Object properties
    Const float skill:
    const int currentNode:
    const int nextNode:
    uint moveTypesMask:
    const float reactionTime:
    const float offensiveness:
    const float campiness:
    const float firerate:

Object behaviors
    cBot @f():

Object methods
    void clearGoalWeights():
    void resetGoalWeights():
    void setGoalWeights(int i, float weight):
    cEntity @ getGoalEnt(int i):
    float getItemWeight(cItem @item):

http://www.warsow.net/dev/machinemessiah/AS_API/cBot.h

to do: Make this more readable, and explain each of them

1.2. cClient

to do: Make this readable, and explain each of them
http://www.warsow.net/dev/machinemessiah/AS_API/cClient.h

1.3. cEntity

to do: Make this readable, and explain each of them
http://www.warsow.net/dev/machinemessiah/AS_API/cEntity.h

1.4. cGametypeDesc

cGametypeDesc is a class with a single object which is globaly declared. The script coder won't need to declare it nor retrieve it. It's just there to be accessed under the object name "gametype". It is used to set up the game code options in the way we want the gameplay to work, and to define the gametype's name and author. http://www.warsow.net/dev/machinemessiah/AS_API/cGametypeDesc.h

1.5. cItem

to do: Make this readable, and explain each of them
http://www.warsow.net/dev/machinemessiah/AS_API/cItem.h

1.6. cMatch

cMatch is a class with a single object which is globaly declared. It is used by the script coder to manage the match states, and it can be accessed under the object name "match".

to do: Make this readable, and explain each of them
http://www.warsow.net/dev/machinemessiah/AS_API/cMatch.h

1.7. cStats

to do: Make this readable, and explain each of them
http://www.warsow.net/dev/machinemessiah/AS_API/cStats.h

1.8. cString

to do: Make this readable, and explain each of them
http://www.warsow.net/dev/machinemessiah/AS_API/cString.h

1.9. cTeam

to do: Make this readable, and explain each of them
http://www.warsow.net/dev/machinemessiah/AS_API/cTeam.h

1.10. cTime

to do: Make this readable, and explain each of them
http://www.warsow.net/dev/machinemessiah/AS_API/cTime.h

1.11. cTrace

to do: Make this readable, and explain each of them
http://www.warsow.net/dev/machinemessiah/AS_API/cTrace.h
Example of quick use
cTrace tr;
if ( !tr.doTrace( ent.getOrigin(), mins, maxs, center, target.entNum(), MASK_SOLID ) )
{
ent.use( ent, target );
}

1.12. cVar

to do: Make this readable, and explain each of them
http://www.warsow.net/dev/machinemessiah/AS_API/cVar.h

1.13. cVec3

properties
    float x; //x coordinate
    float y; //y coordinate
    float z; //z coordinate

object behaviors
    cVec3 @ f(); /* factory */
    cVec3 @ f(float x, float y, float z); /* factory */
    cVec3 @ f(float v); /* factory */
    cVec3 & f(cVec3 &in); /* = */
    cVec3 & f(int); /* = */
    cVec3 & f(float); /* = */
    cVec3 & f(double); /* = */
    cVec3 & f(cVec3 &in); /* += */
    cVec3 & f(cVec3 &in); /* -= */
    cVec3 & f(cVec3 &in); /* *= */
    cVec3 & f(cVec3 &in); /* ^| */
    cVec3 & f(int); /* *= */
    cVec3 & f(float); /* *= */
    cVec3 & f(double); /* *= */

factory
cVec3 v1(); //creates an empty vector
cVec3 v2(x,y,z); //creates a vector and assigns the coordinates (x,y,z)
cVec3 v3(v); //creates a vector and assigns the coordinates (v,v,v)
assignments
int i;
float f;
double d;
v1 = v2; //assigns a vector to a vector
v1 = i; //assigns an int to a vector
v1 = f; //assigns a float to a vector
v1 = d; //assigns a double to a vector
operator assignments
v1 += v2; //adds v1 and v2 and assigns the result to v1
v1 -= v2; //subtracts v2 from v1 and assigns the result to v1
v1 *= v2; //??? dot product
v1 ^= v2; //cross product
v1 *= i; //scalar multiplication
v1 *= f; //scalar multiplication
v1 *= d; //scalar multiplication

global behaviors
    cVec3 @ f(const cVec3 &in, const cVec3 &in); /* + */
    cVec3 @ f(const cVec3 &in, const cVec3 &in); /* - */
    float f(const cVec3 &in, const cVec3 &in); /* * */
    cVec3 @ f(const cVec3 &in, double); /* * */
    cVec3 @ f(double, const cVec3 &in); /* * */
    cVec3 @ f(const cVec3 &in, float); /* * */
    cVec3 @ f(float, const cVec3 &in); /* * */
    cVec3 @ f(const cVec3 &in, int); /* * */
    cVec3 @ f(int, const cVec3 &in); /* * */
    cVec3 @ f(const cVec3 &in, const cVec3 &in); /* ^ */
    bool f(const cVec3 &in, const cVec3 &in); /* == */
    bool f(const cVec3 &in, const cVec3 &in); /* != */

operators
v1 = v2 + v3; //adds v1 and v2
v1 = v2 - v3; //subtracts v3 from v2
f = v1 * v2; //dot product
v1 = v2 * d; //scalar multiplication
v1 = d * v2; //scalar multiplication
v1 = v2 * f; //scalar multiplication
v1 = f * v2; //scalar multiplication
v1 = v2 * i; //scalar multiplication
v1 = i * v2; //scalar multiplication
v1 = v2 ^ v3; //cross product
comparison operators
v1 == v2; //check for equality
v1 != v2; //check for equality and negate
methods
{|
|void set( float x, float y, float z );
|sets vector coordinates to given values
|-
|float length();
|return the vectors length
|-
|float normalize();
|normalizes the vector ("sets" its length to 1) and returns its length
|-
|cString @ toString();
|return the coordinates as a string
|-
|float distance(const cVec3 &in);
|returns the distance between to vectors (length of the vector difference)
|-
|void angleVectors(cVec3 @+, cVec3 @+, cVec3 @+);
|??? converts an angle vector into 3 vectors; v.angleVectors( forward, right, up );
|-
|void toAngles(cVec3 &);
|converts a vector into angles; v.toAngles( anglevector );
|-
|void perpendicular(cVec3 &);
|???
|-
|void makeNormalVectors(cVec3 &, cVec3 &);
|creates two vectors orthogonal to a vector
|}
http://www.warsow.net/dev/machinemessiah/AS_API/cVec3.h

2. Global Properties & Global Functions

Global properties are built in accesses to game module fields which can be used from anywhere in the gametype scripts.

http://www.warsow.net/dev/machinemessiah/AS_API/globals.h

Global functions are built in calls to game module functions which can be used from the gametype scripts.

http://www.warsow.net/dev/machinemessiah/AS_API/globals.h

3. Gametype Script Calls

These functions are the main script functions and are called at determined game events. They are the core of gametype scripts.

3.1. void GT_InitGametype( cGametypeDesc @gametypeDescriptor )

Gametype Initialization function. Called each time the gametype is started, including server initialization, map loads and match restarts. This function sets up the game code for the gametype by defining the cGametypeDesc object. It's also recommended to do files precache and cVar registration in this function.
Notice: Spawning entities inside this function is not allowed

3.2. void GT_SpawnGametype()

After gametype initialization the map entities are spawned by the game code. Every entity is ready to go at this point, but nothing has yet started. The gametype has, in this function, a chance to spawn it's own entities. Note that this isn't in reference to map entities, those have their own spawn functions.
A example could be a gametype which spawns a few runes at random places.

3.3. bool GT_MatchStateFinished( int incomingMatchState )

The game has detected the end of the match state, but it doesn't advance it before calling this function. This function must give permission to move into the next state by returning true.

3.4. void GT_MatchStateStarted()

A new match state is launched. The gametype gets in this function a chance to set up everything for the new state.

3.5. void GT_ThinkRules()

This function is called very game frame. It's used for anything that requires continuous thinking. This is the equivalent of a game server tik.

3.6. void GT_playerRespawn( cEntity @ent, int old_team, int new_team )

This function is called each time is respawned. It is called right after the player is set up, but before it's assigned solid state.
Note that Respawning happens as much for being made not-solid (ghosting) as for being put in the game. For example, when a player changes team he is respawned twice. Once is moved to ghost, and then again is moved to the world as part of the new team.
Respawning, of course, also happens after a death, to be put back in the game.
The most usual activity to perform in this function is giving spawn items to the player.

3.7. void GT_scoreEvent( cClient @client, cString &score_event, cString &args )

This function is called by the game code when any of the events considered relevant to scores happen. At this point those events are:

"enterGame" - A client has finished connecting and enters a new level
"connect" - A client just connected
"disconnect" - A client just disconnected
"dmg" - A client has inflicted some damage
"kill" - A client has killed some other entity
"award" - A client receives an award
"pickup" - A client picked up an item (use args.getToken( 0 ) to get the item's classname)
"projectilehit"

3.8. cString @GT_ScoreboardMessage( int maxlen )

The game code requests the scoreboard to be updated. More about this at http://www.warsow.net/wiki/index.php?title=Gametype_scripting#Creating_New_Gametype_Scoreboards

3.9. cEntity @GT_SelectSpawnPoint( cEntity @self )

a player is about to spawn. Select an spawnpoint for him. Returning null makes the game code select a random "info_player_deathmatch".

3.10. bool GT_UpdateBotStatus( cEntity @self )

When this function is called the weights of items have been reset to their default values, this means, the weights *are set*, and what this function does is scaling them depending on the current bot status. Player, and non-item entities don't have any weight set. So they will be ignored by the bot unless a weight is assigned here.

3.11. bool GT_Command( cClient @client, cString @cmdString, cString @argsString, int argc )

A client has sent a command.
Clone this wiki locally