There are currently 4 players online.
 
Warsow

 
 

Gametype Scripting

1. BETA TEST VERSION QUICK INFO back to top


This information is placed here to help people meanwhile we get a better one
This is the C file which registers the gametype plugins in Warsow.
EVERY little bit of information regarding the gametype plugins is here, but it will be hard to extract.
Angelscript registration C file

2. What is Angelscript back to top


Angelscript is a scripting language with strong similarities to C++.
Angelscript script writer reference manual
The complete manual about the scripting languagehttp://www.angelcode.com/angelscript/sdk/docs/manual/doc_script.html

3. Game Object Classes back to top


3.1. Bot back to top


  • 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
    • Bot @f():
  • Object methods
    • void clearGoalWeights():
    • void resetGoalWeights():
    • void setGoalWeights(int i, float weight):
    • cEntity @ getGoalEnt(int i):
    • float getItemWeight(cItem @item):

3.2. Client back to top


3.3. Entity back to top


3.4. GametypeDesc back to top


GametypeDesc 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

3.5. Item back to top


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

3.6. Match back to top


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

3.7. Stats back to top


3.8. String back to top


3.9. Team back to top


3.10. Time back to top


3.11. Trace back to top


  • Example of quick use
  • Trace tr;
    if ( !tr.doTrace( ent.getOrigin(), mins, maxs, center, target.entNum(), MASK_SOLID ) )
    {
    ent.use( ent, target );
    }

3.12. Cvar back to top


3.13. Vec3 back to top


  • properties
    • float x; //x coordinate
    • float y; //y coordinate
    • float z; //z coordinate
  • object behaviors
    • Vec3 @ f(); /* factory */
    • Vec3 @ f(float x, float y, float z); /* factory */
    • Vec3 @ f(float v); /* factory */
    • Vec3 & f(cVec3 &in); /* = */
    • Vec3 & f(int); /* = */
    • Vec3 & f(float); /* = */
    • Vec3 & f(double); /* = */
    • Vec3 & f(cVec3 &in); /* += */
    • Vec3 & f(cVec3 &in); /* -= */
    • Vec3 & f(cVec3 &in); /* *= */
    • Vec3 & f(cVec3 &in); /* ^| */
    • Vec3 & f(int); /* *= */
    • Vec3 & f(float); /* *= */
    • ' Vec3 & f(double); /* *= */
  • factory
  • Vec3 v1(); //creates an empty vector
    Vec3 v2(x,y,z); //creates a vector and assigns the coordinates (x,y,z)
    Vec3 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
    • Vec3 @ f(const Vec3 &in, const Vec3 &in); /* + */
    • Vec3 @ f(const Vec3 &in, const Vec3 &in); /* - */
    • loat f(const Vec3 &in, const Vec3 &in); /* * */
    • Vec3 @ f(const Vec3 &in, double); /* * */
    • Vec3 @ f(double, const Vec3 &in); /* * */
    • Vec3 @ f(const Vec3 &in, float); /* * */
    • Vec3 @ f(float, const Vec3 &in); /* * */
    • Vec3 @ f(const Vec3 &in, int); /* * */
    • Vec3 @ f(int, const Vec3 &in); /* * */
    • Vec3 @ f(const Vec3 &in, const Vec3 &in); /* ^ */
    • bool f(const Vec3 &in, const Vec3 &in); /* == */
    • bool f(const Vec3 &in, const Vec3 &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
    |-
    |
    String @ toString();
    |return the coordinates as a string
    |-
    |
    float distance(const Vec3 &in);
    |returns the distance between to vectors (length of the vector difference)
    |-
    |
    void angleVectors(Vec3 @+, Vec3 @+, Vec3 @+);
    |??? converts an angle vector into 3 vectors; v.angleVectors( forward, right, up );
    |-
    |
    void toAngles(Vec3 &);
    |converts a vector into angles; v.toAngles( anglevector );
    |-
    |
    void perpendicular(Vec3 &);
    |???
    |-
    |
    void makeNormalVectors(Vec3 &, Vec3 &);
    |creates two vectors orthogonal to a vector
    |}

4. Global Properties back to top


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

5. Global Functions back to top


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

6. Gametype Script Calls back to top


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

6.1. void GT_InitGametype( GametypeDesc @gametypeDescriptor ) back to top


  • 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

6.2. void GT_SpawnGametype() back to top


  • 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.

6.3. bool GT_MatchStateFinished( int incomingMatchState ) back to top


  • 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.

6.4. void GT_MatchStateStarted() back to top


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

6.5. void GT_ThinkRules() back to top


  • 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.

6.6. void GT_playerRespawn( Entity @ent, int old_team, int new_team ) back to top


  • 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.

6.7. void GT_scoreEvent( Client @client, String &score_event, String &args ) back to top


  • 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"

6.8. String @GT_ScoreboardMessage( int maxlen ) back to top


  • 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

6.9. cEntity @GT_SelectSpawnPoint( Entity @self ) back to top


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

6.10. bool GT_UpdateBotStatus( Entity @self ) back to top


  • 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.

6.11. bool GT_Command( Client @client, String @cmdString, String @argsString, int argc ) back to top


  • A client has sent a command.

7. Creating New Map Entities back to top


Gametype plugins allow to create new entities to be spawned from map files, and to manage their thinking, touching, using, pain and die events.
The way of doing it is quite simple. All the gametype creator has to do is add a new entity to his map. This new entity will have a new entity classname (otherwise it wouldn't be new) which normally wouldn't be recognized by Warsow.
When Warsow is spawning a map and finds a entity with a unknown classname, it will ask the gametype plugin to execute the entity's spawning function. If the script doesn't have it, the entity will be ignored.
The way of creating the spawn function for a new entity type from a gametype script is very simple, all the coder has to do is use the entity's classname as function name. For example, to a new entity with classname "misc_custom" a spawn function would look like this:
void misc_custom( Entity @ent )
{
// Do the spawning
}
That's just the spawning, tho. You normally want your entity to execute some actions when touched or damaged. They can be created by adding a function with the event as sufix. Notice that, the only required function to have the entity supported is the spawning one, and all the event functions are optional.
These are the events you can create function callbacks for:
  • think : Each game frame the entity gets a chance to think. Notice that physics are not handled by the thinking function. The physics are handled by the game code and a gametype scripter changes the entity movetype to choose between the different movement sets. Also note that the thinking process is managed by the entity itself, and it will be called based on the time value assigned into cEntity::nextThink
  • Example of "misc_custom" entity thinking function:
    void misc_custom_think( Entity @ent )
    {
    // Do the thinking
    }
  • touch : The entity has touched some other entity.
  • Example of "misc_custom" entity touch function:
    void misc_custom_touch( Entity @ent, Entity @other, const Vec3 @planeNormal, int surfFlags )
    {
    // Apply the results of being touched
    }
  • use : The entity is being used. This happens when some other entity is triggered and has this entity as target. Activator is the entity which triggered the entity which uses our entity. As example: A player touches a buttom that uses our misc_custom entity. The player is the "activator", the button is the "other" and misc_custom is the "ent".
  • Example of "misc_custom" entity use function:
    void misc_custom_use( Entity @ent, Entity @other, Entity @activator )
    {
    // Execute the actions of being used
    }
  • pain : The entity has received damage. Notice that the damage is already applied to the entity, it's not pain's function mission to add the damage, but to add entity reactions to being damaged. As example, Warsow's func_door entities are activated not only by using, but also by their pain function (so they open when being shot).
  • Example of "misc_custom" entity pain function:
    void misc_custom_pain( Entity @ent, Entity @other, float kick, float damage )
    {
    // Apply the results of being damaged
    }
  • die : The entity has received damage enough to not have any remaining health. The game code will do nothing, if you want it to die, it must be handled by this function. As example, a brush entity can be made to explode in this function.
  • Example of "misc_custom" entity die function:
    void misc_custom_die( Entity @ent, Entity @inflicter, Entity @attacker )
    {
    // Apply the results of being killed
    }
  • stop : The entity has stopped moving.
  • Example of "misc_custom" entity die function:
    void misc_custom_stop( Entity @ent )
    {
    // Apply the results of having stop
    }

8. Spawning Game Entities back to top


  • to do

9. Creating New Gametype Scoreboards back to top


9.1. Defining a new scoreboard back to top


As mentioned above, Warsow allows to gametype creator to design his own scoreboard. For this, a layout must be defined first at the gametype initialization (
GT_InitGametype script function), so later the scoreboard updates are understood by the client.
A scoreboard layout is nothing else than a string defining the type and width of each field at each player information tab. We refer them as scoreboard columns just because they are aligned in columns when all players are shown together.
The layout definition is made by writing a string with all the columns (type + width) into the CS_SCB_PLAYERTAB_LAYOUT configstring.
A second configstring is writen containing a list with the titles to each column. This configstring is CS_SCB_PLAYERTAB_TITLES.
This may seem a bit complex, but it's actually extremely simple once you see an example (from the tdm scoreboard initialization):
G_ConfigString( CS_SCB_PLAYERTAB_LAYOUT, "%n 130 %i 42 %i 40 %i 40 %l 40 %p 18 %p 18" );
G_ConfigString( CS_SCB_PLAYERTAB_TITLES, "Name Score Frags TKs Ping C R" );
The tokens starting with % are column types, the other ones are the width in pixels the scoreboard will dedicate to that column.
The list of colunm types are the following:
  • %s : The content will be a string
  • %n : The content will be a player number and will draw in the scoreboard the player name of the given id. The %n type can also operate in a special way which allows to draw the players name with transparency. This is used for dead players in some gametypes, and it's achieved by sending the player id as itself + 1 and made negative. So, like this: id = -( playerNum + 1 ).
  • %i : The content will be a integer. Negative values will be drawn in red color.
  • %f : The content will be a float. It will draw with the format "%.2f", so there's no point in sending more decimals than those either. But that's up to you.
  • %l : The content will be a integer and will draw colored in "latency style". This is, low (as in for ping) values green, bigger orange, bad values red.
  • %b : The content will be a 0 or 1 number. It will draw "YES" or "NO" string.
  • %p : The content will be a image index. It will draw a picture.
  • %t : The content will be a race time value. It will draw a race-style clock.''

9.2. Updating the scoreboard back to top


  • to do

10. How to back to top


  • to do : Please, help others by adding the things you learn how to do.

10.1. How to add a new callvote back to top


  • to do

10.2. How to add a new command back to top


  • to do

10.3. How to assign player models to clients back to top


  • to do




RSSRSSRSSRSS

Copyright © 2016 warsow.gg

Warsow in social media