Class System: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{lang}}
{{lang}}
{{translate|{{todo|restore from [https://web.archive.org/web/20160803181635/https://developer.valvesoftware.com/wiki/Class_System 2016 archived backup], then crosscheck for up-to-date content with the [[Class System:ru|russian version]].}} }}
{{Multiple issues|
{{Multiple issues|
{{Underlinked|date=January 2024}}
{{Underlinked|date=January 2024}}
{{Orphan|date=January 2024}}
{{Orphan|date=January 2024}}
{{update}}
}}
}}


{{todo|Объяснить как реализовать это в Half-Life 2: Deathmatch}}
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 ==


Откройте SDK и запустите "Мастер создания мода" ("Create a Mod" wizard). Выберите пункт "Начать с шаблона" ("Start a Multiplayer mod from a template"). Не беспокойтесь на счет предупреждения о "продвинутых пользователях", так как Valve упростила процесс до невозможности. Убедитесь что вы установили флажок на "Включить классы", а ещё лучше "Включить команды".
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|Начав мод с шаблона, скомпилировав dll файлы и поиграв, мод виснет когда вы пытаетесь выйти. Фикс можно найти на странице [[Source_2007_Template_Fixes:ru|Исправление шаблона Source 2007]].}}
{{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 ==


На текущий момент настройки классов можно совершить при помощи простых текстовых файлов. Это файлы, которые находятся в папке "$moddir\scripts", под именем класса (например, playerclass_blue_class1.txt)
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 - не привязан (нет команды), 1 - наблюдатель, 2 - первая команда (BLUE), 3 - вторая команда (RED), и так далее
int m_iTeam; // 0 is unassigned, 1 is spectator, 2 is team 1 (BLUE), 3 is team 2 (RED), etc.
int m_iPrimaryWeapon; // Первичное оружие, которое определено в sdk_shareddefs.h (по-умолчанию это NONE, MP5, SHOTGUN, GRENADE, PISTOL, и CROWBAR)
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; // Вторичное оружие, может быть WEAPON_NONE
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]; // CVar для лимита классов
char m_szLimitCvar[64]; // Name of the cvar that controls the class limit for this class
float m_flRunSpeed; // Нормальная скорость бега, в юнитах/секунду. В SDK по-умолчанию 220, HL2 использует 190
float m_flRunSpeed; // Run (normal) speed, in units/second. SDK Default is 220, HL2 uses 190
float m_flSprintSpeed; // Скорость в спринте, в юнитах/секунду. Обычно это 150% от скорости бега. В SDK по-умолчанию 330, HL2 использует 327.5
float m_flSprintSpeed; // Sprint speed, in units/second. Is usually 150% run speed. SDK default is 330, HL2 uses 327.5
float m_flProneSpeed; // Скорость передвижения в положении лежа, в юнитах/секунду. В SDK по-умолчанию 50 (в HL2 не используется)
float m_flProneSpeed; // Prone speed, in units/second. SDK defaults to 50
int m_iArmor; // Броня. Поглощает 80% повреждений (настраивается в player.cpp)
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>


== Переменные (на стороне .txt) ==
== Variables (on the .txt side) ==


<pre>
<pre>
// Обязательные настройки
// Mandatory / Strongly Recommended keyvalues
"printname" "#class_red_class1" // Имя класса, обычно строка с указанием на локализацию. Не используется в sdk_playerclass_info_parse.cpp, но используется в других местах .res файлов
"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" // Команда класса. Базовый код принимает "BLUE" или "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" // Изображение в HUD
"classimage" "cls_red_class1_active" // An image name, apparently for the HUD
"classimagebg" "cls_red_class1_active_bg" // Задний фон изображения HUD
"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" // По-умолчанию 0
"numgrens" "1" // Defaults to 0
"grenadetype2" "grenade" // По-умолчанию ничего
"grenadetype2" "grenade" // Defaults to none
"numgrens2" "1" // По-умолчанию 0
"numgrens2" "1" // Defaults to 0
"armor" "50" // По-умолчанию 0
"armor" "50" // Defaults to 0
"RunSpeed" "240" // По-умолчанию SDK_DEFAULT_PLAYER_RUNSPEED, равная 220
"RunSpeed" "240" // Defaults to SDK_DEFAULT_PLAYER_RUNSPEED, which defaults to 220
"SprintSpeed" "360" // По-умолчанию SDK_DEFAULT_PLAYER_SPRINTSPEED, равная 330
"SprintSpeed" "360" // Defaults to SDK_DEFAULT_PLAYER_SPRINTSPEED, which defaults to 330
"ProneSpeed" "70" // По-умолчанию SDK_DEFAULT_PLAYER_PRONESPEED, равная 50
"ProneSpeed" "70" // Defaults to SDK_DEFAULT_PLAYER_PRONESPEED, which defaults to 50
</pre>
</pre>


== Как это выглядит вместе ==
== How it glues together ==


<pre>
<pre>
void unused = "printname"
void unused = "printname"
int m_iTeam; = "team"
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; = "armor"
int m_iArmor; = "armor"


char m_szClassImage[SDK_PLAYERCLASS_IMAGE_LENGTH]; = "classimage"
char m_szClassImage[SDK_PLAYERCLASS_IMAGE_LENGTH]; = "classimage"
Line 89: Line 91:
</pre>
</pre>


{{Todo|Возможность добавить специальную способность для конкретного класса (например, дать двойной прыжок)}}
{{Todo|Cover adding a special ability to just one class (ex. give one class double-jumping)}}


Система классов читает .txt файлы в папке "scripts/" по названию "классигрока_<красный/синий>_класс<номер>.txt".
The class system reads from txt files in the {{path|scripts/}} directory named as {{file|playerclass_<red/blue>_class<number>|txt}}


'''Пример:'''
'''Example Text File:'''
<syntaxhighlight lang="text">PlayerClassDatafile
<syntaxhighlight lang="text">PlayerClassDatafile
{
{
// Члены FilePLayerClassInfo_t
// FilePLayerClassInfo_t members
"printname" "#class_blue_class1"
"printname" "#class_blue_class1"
"playermodel" "models/player/blue_player.mdl"
"playermodel" "models/player/blue_player.mdl"
"selectcmd" "cls_blue_class1"
"selectcmd" "cls_blue_class1"
 
// Члены CSDKPlayerClassInfo
// CSDKPlayerClassInfo members
 
// Принадлежность класса к команде (для проверки)
// What team has this class, for verification
"team" "BLUE"
"team" "BLUE"
 
// Оружие класса
// Weapon Info
"primaryweapon" "pistol"
"primaryweapon" "pistol"
"secondaryweapon" "none"
"secondaryweapon" "none"
"meleeweapon" "crowbar"
"meleeweapon" "crowbar"
 
"grenadetype" "grenade"
"grenadetype" "grenade"
"numgrens" "1"
"numgrens" "1"
"limitcvar" "mp_limit_blue_class1"
"limitcvar" "mp_limit_blue_class1"
 
"classimage" "cls_blue_class1_active"
"classimage" "cls_blue_class1_active"
"classimagebg" "cls_blue_class1_active_bg"
"classimagebg" "cls_blue_class1_active_bg"
 
"armor" "50"
"armor" "50"
 
// Передвижение
// Movement
"RunSpeed" "240"
"RunSpeed" "240"
"SprintSpeed" "360"
"SprintSpeed" "360"

Latest revision as of 18:08, 28 January 2024

English (en)Русский (ru)Translate (Translate)
Wikipedia - Letter.png
This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages)
Underlinked - Logo.png
This article needs more Wikipedia icon links to other articles to help Wikipedia icon integrate it into the encyclopedia. Please help improve this article by adding links Wikipedia icon that are relevant to the context within the existing text.
January 2024
Broom icon.png
This article or section needs to be updated to include current information regarding the subject.
Remember to check for any notes left by the tagger at this article's talk page.

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

Icon-Bug.pngBug: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.  [todo tested in ?]

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"
Todo: Cover adding a special ability to just one class (ex. give one class double-jumping)

The class system reads from txt files in the 🖿scripts/ directory named as 🖿playerclass_<red/blue>_class<number>.txt

Example Text File:

PlayerClassDatafile
{
	// FilePLayerClassInfo_t members
	"printname"			"#class_blue_class1"
	"playermodel"			"models/player/blue_player.mdl"
	"selectcmd"			"cls_blue_class1"
 
	// CSDKPlayerClassInfo members
 
	// What team has this class, for verification
	"team"				"BLUE"
 
	// Weapon Info
	"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"
 
	// Movement
	"RunSpeed"		"240"
	"SprintSpeed"		"360"
	"ProneSpeed"		"70"
}