Class System: Difference between revisions
SirYodaJedi (talk | contribs) mNo edit summary |
SirYodaJedi (talk | contribs) mNo edit summary |
||
Line 6: | Line 6: | ||
}} | }} | ||
{{todo| | In the March 17 2008 beta of the SDK, a flexible class system was added. This page will teach programmers how to work with this system. | ||
{{todo|Explain how to implement into Half Life 2: Deathmatch}} | |||
== | == Starting off == | ||
Open up the SDK, and run the "Create a Mod" wizard. Select "Start a Multiplayer mod from a template." Don't worry about the "advanced users" warning, since Valve has made this extremely easy. Make sure you check "Enable classes" and most likely "Enable teams." | |||
{{Bug| | {{Bug|After starting a mod from a template, compiling the dlls and playing the mod, the mod hangs when you try to quit. The reason for this is unknown. | ||
A fix for this bug is in the Source 2007 Template Fixes page.}} | |||
== | == Scripts == | ||
Now, most of the configuration for the class itself is done with simple text files. The files that control this are located in {{path|<moddir>\scripts}}, under the names {{file|playerclass_blue_class1|txt}} and such. | |||
While most of it is relatively self-explanatory, certain things might be obscure, or not listed. | |||
== | == Variables (on the C++ side) == | ||
<source lang=cpp> | <source lang=cpp> | ||
int m_iTeam; // 0 | int m_iTeam; // 0 is unassigned, 1 is spectator, 2 is team 1 (BLUE), 3 is team 2 (RED), etc. | ||
int m_iPrimaryWeapon; // | int m_iPrimaryWeapon; // Index of the weapon, as defined in sdk_shareddefs.h (default is NONE, MP5, SHOTGUN, GRENADE, PISTOL, and CROWBAR | ||
int m_iSecondaryWeapon; | int m_iSecondaryWeapon; // Same as primary, but for secondary, and allowed to be WEAPON_NONE | ||
int m_iMeleeWeapon; // | int m_iMeleeWeapon; // Same as secondary, but for melee | ||
int m_iNumGrensType1; // | int m_iNumGrensType1; // Number of Type 1 Grenades | ||
int m_iGrenType1; // | int m_iGrenType1; // Same as secondary, but for Type 1 Grenades | ||
int m_iNumGrensType2; // | int m_iNumGrensType2; // Number of Type 2 Grenades | ||
int m_iGrenType2; // | int m_iGrenType2; // Same as secondary, but for Type 2 Grenades | ||
char m_szLimitCvar[64]; | char m_szLimitCvar[64]; // Name of the cvar that controls the class limit for this class | ||
float m_flRunSpeed; // | float m_flRunSpeed; // Run (normal) speed, in units/second. SDK Default is 220, HL2 uses 190 | ||
float m_flSprintSpeed; // | float m_flSprintSpeed; // Sprint speed, in units/second. Is usually 150% run speed. SDK default is 330, HL2 uses 327.5 | ||
float m_flProneSpeed; // | float m_flProneSpeed; // Prone speed, in units/second. SDK defaults to 50 | ||
int m_iArmor; // | int m_iArmor; // Amount of extra armor. It will absorb 80% of the damage (to change that, go to player.cpp) | ||
char m_szClassImage[SDK_PLAYERCLASS_IMAGE_LENGTH]; // | char m_szClassImage[SDK_PLAYERCLASS_IMAGE_LENGTH]; // According to comments, this is "HUD player status health images (when the player is hurt)" | ||
char m_szClassImageBG[SDK_PLAYERCLASS_IMAGE_LENGTH]; // | char m_szClassImageBG[SDK_PLAYERCLASS_IMAGE_LENGTH]; // However, I can't seem to trace the code for it. | ||
</source> | </source> | ||
== | == Variables (on the .txt side) == | ||
<pre> | <pre> | ||
// | // Mandatory / Strongly Recommended keyvalues | ||
"printname" "#class_red_class1" | "printname" "#class_red_class1" // the name of the class, usually as a localization string. Not used in sdk_playerclass_info_parse.cpp, but it's used in other places in .res files | ||
"playermodel" "models/player/red_player.mdl" // | "playermodel" "models/player/red_player.mdl" // the model of the class | ||
"selectcmd" "cls_red_class1" | "selectcmd" "cls_red_class1" // from what the author can tell, the name of the console command used to switch to this class | ||
"team" "RED" | "team" "RED" // The team it goes with. Default code only accepts "BLUE" or "RED" | ||
"primaryweapon" "pistol" // | "primaryweapon" "pistol" // The name of the primary weapon. Cannot be "none" | ||
"limitcvar" "mp_limit_red_class1" | "limitcvar" "mp_limit_red_class1" // The console variable that controls the maximum amount of this class allowed | ||
"classimage" "cls_red_class1_active" | "classimage" "cls_red_class1_active" // An image name, apparently for the HUD | ||
"classimagebg" "cls_red_class1_active_bg" // | "classimagebg" "cls_red_class1_active_bg" // Same | ||
// | // Optional keyvalues | ||
"secondaryweapon" "none" | "secondaryweapon" "none" // Defaults to none | ||
"meleeweapon" "crowbar" | "meleeweapon" "crowbar" // Defaults to none | ||
"grenadetype" "grenade" | "grenadetype" "grenade" // Defaults to none | ||
"numgrens" "1" | "numgrens" "1" // Defaults to 0 | ||
"grenadetype2" "grenade" | "grenadetype2" "grenade" // Defaults to none | ||
"numgrens2" "1" | "numgrens2" "1" // Defaults to 0 | ||
"armor" "50" // | "armor" "50" // Defaults to 0 | ||
"RunSpeed" "240" | "RunSpeed" "240" // Defaults to SDK_DEFAULT_PLAYER_RUNSPEED, which defaults to 220 | ||
"SprintSpeed" "360" | "SprintSpeed" "360" // Defaults to SDK_DEFAULT_PLAYER_SPRINTSPEED, which defaults to 330 | ||
"ProneSpeed" "70" | "ProneSpeed" "70" // Defaults to SDK_DEFAULT_PLAYER_PRONESPEED, which defaults to 50 | ||
</pre> | </pre> | ||
== | == How it glues together == | ||
<pre> | <pre> | ||
void unused | void unused = "printname" | ||
int m_iTeam; | int m_iTeam; = "team" | ||
int m_iPrimaryWeapon; = "primaryweapon" | int m_iPrimaryWeapon; = "primaryweapon" | ||
int m_iSecondaryWeapon; = "secondaryweapon" | int m_iSecondaryWeapon; = "secondaryweapon" | ||
int m_iMeleeWeapon; = "meleeweapon" | int m_iMeleeWeapon; = "meleeweapon" | ||
int m_iNumGrensType1; = "numgrens" | int m_iNumGrensType1; = "numgrens" | ||
int m_iGrenType1; = "grenadetype" | int m_iGrenType1; = "grenadetype" | ||
int m_iNumGrensType2; = "numgrens2" | int m_iNumGrensType2; = "numgrens2" | ||
int m_iGrenType2; = "grenadetype2" | int m_iGrenType2; = "grenadetype2" | ||
char m_szLimitCvar[64]; = "limitcvar" | char m_szLimitCvar[64]; = "limitcvar" | ||
float m_flRunSpeed; = "RunSpeed" | float m_flRunSpeed; = "RunSpeed" | ||
float m_flSprintSpeed; = "SprintSpeed" | float m_flSprintSpeed; = "SprintSpeed" | ||
float m_flProneSpeed; = "ProneSpeed" | float m_flProneSpeed; = "ProneSpeed" | ||
int m_iArmor; | int m_iArmor; = "armor" | ||
char m_szClassImage[SDK_PLAYERCLASS_IMAGE_LENGTH]; = "classimage" | char m_szClassImage[SDK_PLAYERCLASS_IMAGE_LENGTH]; = "classimage" |
Revision as of 18:04, 28 January 2024

This page either contains information that is only partially or incorrectly translated, or there isn't a translation yet.
If this page cannot be translated for some reason, or is left untranslated for an extended period of time after this notice is posted, the page should be requested to be deleted.
Also, please make sure the article complies with the alternate languages guide.
The following content or section specifically needs to be translated:





January 2024

You can help by

January 2024
In the March 17 2008 beta of the SDK, a flexible class system was added. This page will teach programmers how to work with this system.
Starting off
Open up the SDK, and run the "Create a Mod" wizard. Select "Start a Multiplayer mod from a template." Don't worry about the "advanced users" warning, since Valve has made this extremely easy. Make sure you check "Enable classes" and most likely "Enable teams."

Scripts
Now, most of the configuration for the class itself is done with simple text files. The files that control this are located in <moddir>\scripts
, under the names playerclass_blue_class1.txt
and such.
While most of it is relatively self-explanatory, certain things might be obscure, or not listed.
Variables (on the C++ side)
int m_iTeam; // 0 is unassigned, 1 is spectator, 2 is team 1 (BLUE), 3 is team 2 (RED), etc.
int m_iPrimaryWeapon; // Index of the weapon, as defined in sdk_shareddefs.h (default is NONE, MP5, SHOTGUN, GRENADE, PISTOL, and CROWBAR
int m_iSecondaryWeapon; // Same as primary, but for secondary, and allowed to be WEAPON_NONE
int m_iMeleeWeapon; // Same as secondary, but for melee
int m_iNumGrensType1; // Number of Type 1 Grenades
int m_iGrenType1; // Same as secondary, but for Type 1 Grenades
int m_iNumGrensType2; // Number of Type 2 Grenades
int m_iGrenType2; // Same as secondary, but for Type 2 Grenades
char m_szLimitCvar[64]; // Name of the cvar that controls the class limit for this class
float m_flRunSpeed; // Run (normal) speed, in units/second. SDK Default is 220, HL2 uses 190
float m_flSprintSpeed; // Sprint speed, in units/second. Is usually 150% run speed. SDK default is 330, HL2 uses 327.5
float m_flProneSpeed; // Prone speed, in units/second. SDK defaults to 50
int m_iArmor; // Amount of extra armor. It will absorb 80% of the damage (to change that, go to player.cpp)
char m_szClassImage[SDK_PLAYERCLASS_IMAGE_LENGTH]; // According to comments, this is "HUD player status health images (when the player is hurt)"
char m_szClassImageBG[SDK_PLAYERCLASS_IMAGE_LENGTH]; // However, I can't seem to trace the code for it.
Variables (on the .txt side)
// Mandatory / Strongly Recommended keyvalues "printname" "#class_red_class1" // the name of the class, usually as a localization string. Not used in sdk_playerclass_info_parse.cpp, but it's used in other places in .res files "playermodel" "models/player/red_player.mdl" // the model of the class "selectcmd" "cls_red_class1" // from what the author can tell, the name of the console command used to switch to this class "team" "RED" // The team it goes with. Default code only accepts "BLUE" or "RED" "primaryweapon" "pistol" // The name of the primary weapon. Cannot be "none" "limitcvar" "mp_limit_red_class1" // The console variable that controls the maximum amount of this class allowed "classimage" "cls_red_class1_active" // An image name, apparently for the HUD "classimagebg" "cls_red_class1_active_bg" // Same // Optional keyvalues "secondaryweapon" "none" // Defaults to none "meleeweapon" "crowbar" // Defaults to none "grenadetype" "grenade" // Defaults to none "numgrens" "1" // Defaults to 0 "grenadetype2" "grenade" // Defaults to none "numgrens2" "1" // Defaults to 0 "armor" "50" // Defaults to 0 "RunSpeed" "240" // Defaults to SDK_DEFAULT_PLAYER_RUNSPEED, which defaults to 220 "SprintSpeed" "360" // Defaults to SDK_DEFAULT_PLAYER_SPRINTSPEED, which defaults to 330 "ProneSpeed" "70" // Defaults to SDK_DEFAULT_PLAYER_PRONESPEED, which defaults to 50
How it glues together
void unused = "printname" int m_iTeam; = "team" int m_iPrimaryWeapon; = "primaryweapon" int m_iSecondaryWeapon; = "secondaryweapon" int m_iMeleeWeapon; = "meleeweapon" int m_iNumGrensType1; = "numgrens" int m_iGrenType1; = "grenadetype" int m_iNumGrensType2; = "numgrens2" int m_iGrenType2; = "grenadetype2" char m_szLimitCvar[64]; = "limitcvar" float m_flRunSpeed; = "RunSpeed" float m_flSprintSpeed; = "SprintSpeed" float m_flProneSpeed; = "ProneSpeed" int m_iArmor; = "armor" char m_szClassImage[SDK_PLAYERCLASS_IMAGE_LENGTH]; = "classimage" char m_szClassImageBG[SDK_PLAYERCLASS_IMAGE_LENGTH]; = "classimagebg"
Система классов читает .txt файлы в папке "scripts/" по названию "классигрока_<красный/синий>_класс<номер>.txt".
Пример:
PlayerClassDatafile
{
// Члены FilePLayerClassInfo_t
"printname" "#class_blue_class1"
"playermodel" "models/player/blue_player.mdl"
"selectcmd" "cls_blue_class1"
// Члены CSDKPlayerClassInfo
// Принадлежность класса к команде (для проверки)
"team" "BLUE"
// Оружие класса
"primaryweapon" "pistol"
"secondaryweapon" "none"
"meleeweapon" "crowbar"
"grenadetype" "grenade"
"numgrens" "1"
"limitcvar" "mp_limit_blue_class1"
"classimage" "cls_blue_class1_active"
"classimagebg" "cls_blue_class1_active_bg"
"armor" "50"
// Передвижение
"RunSpeed" "240"
"SprintSpeed" "360"
"ProneSpeed" "70"
}