plr_9mm_bullet
. You'll find the references to the "9mm" glock cvars - let's change them to "45acp" cvars:
// Glock Round
cvar_t sk_plr_9mm_bullet1 = {"sk_plr_9mm_bullet1", "0"};
cvar_t sk_plr_9mm_bullet2 = {"sk_plr_9mm_bullet2", "0"};
cvar_t sk_plr_9mm_bullet3 = {"sk_plr_9mm_bullet3", "0"};
// Glock Round
cvar_t sk_plr_45acp_bullet1 = {"sk_plr_45acp_bullet1", "0"};
cvar_t sk_plr_45acp_bullet2 = {"sk_plr_45acp_bullet2", "0"};
cvar_t sk_plr_45acp_bullet3 = {"sk_plr_45acp_bullet3", "0"};
CVAR_REGISTER
calls. Change these too:
// Glock Round
CVAR_REGISTER(&sk_plr_9mm_bullet1); // {"sk_plr_9mm_bullet1","0"};
CVAR_REGISTER(&sk_plr_9mm_bullet2); // {"sk_plr_9mm_bullet2","0"};
CVAR_REGISTER(&sk_plr_9mm_bullet3); // {"sk_plr_9mm_bullet3","0"};
// Glock Round
CVAR_REGISTER(&sk_plr_45acp_bullet1); // {"sk_plr_45acp_bullet1","0"};
CVAR_REGISTER(&sk_plr_45acp_bullet2); // {"sk_plr_45acp_bullet2","0"};
CVAR_REGISTER(&sk_plr_45acp_bullet3); // {"sk_plr_45acp_bullet3","0"};
gSkillData
struct. There's only a one-line change you need to do here:
// Glock Round
gSkillData.plrDmg9MM = GetSkillCvar("sk_plr_9mm_bullet");
// Glock Round
gSkillData.plrDmg45Acp = GetSkillCvar("sk_plr_45acp_bullet");
gSkillData
struct is. Change the variable name here as well. While we're at it, we'll bump up the damage from 12 to, say, 18.
// Glock Round
gSkillData.plrDmg9MM = 12;
// Glock Round
gSkillData.plrDmg45Acp = 18;
plrDmg45Acp
field doesn't exist in gSkillData
yet, so that's next.
skilldata_t
struct, you'll find the plrDmg9MM
field. Just update the field name here:
// Player Weapons
float plrDmgCrowbar;
float plrDmg9MM;
float plrDmg357;
// Player Weapons
float plrDmgCrowbar;
float plrDmg45Acp;
float plrDmg357;
plrDmg9MM
value is only used in one other place: combat.cpp, in the FireBulletsPlayer
method. Find it, and rename it:
case BULLET_PLAYER_9MM:
pEntity->TraceAttack(pevAttacker, gSkillData.plrDmg9MM, vecDir, &tr, DMG_BULLET);
break;
case BULLET_PLAYER_9MM:
pEntity->TraceAttack(pevAttacker, gSkillData.plrDmg45Acp, vecDir, &tr, DMG_BULLET);
break;
BULLET_PLAYER_9MM
label? We should change that as well. You'll find references to it in the following files, just change it to BULLET_PLAYER_45ACP
in each case:
// 9mmhandgun Round
sk_plr_9mm_bullet1 "8"
sk_plr_9mm_bullet2 "8"
sk_plr_9mm_bullet3 "8"
// 45acphandgun Round
sk_plr_45acp_bullet1 "12"
sk_plr_45acp_bullet2 "12"
sk_plr_45acp_bullet3 "12"
#define
blocks near the top. We'll be defining a new ammo type, so we'll need some new ammo constants to match.MAX_CARRY
value:
// weapon clip/carry ammo capacities
#define URANIUM_MAX_CARRY 100
#define _9MM_MAX_CARRY 250
#define _357_MAX_CARRY 36
// weapon clip/carry ammo capacities
#define URANIUM_MAX_CARRY 100
#define _9MM_MAX_CARRY 250
#define _45ACP_MAX_CARRY 78
#define _357_MAX_CARRY 36
#define GLOCK_MAX_CLIP 17
// ... several lines
#define GLOCK_DEFAULT_GIVE 17
#define GLOCK_MAX_CLIP 13
// ... several lines
#define GLOCK_MAX_CLIP 13
AMMO_GLOCKCLIP_GIVE
, because it's already defined to be the same as GLOCK_MAX_CLIP
. Depending on your use case, you might want to change this, or add a new one, for your new ammo type.
LINK_ENTITY_TO_CLASS( weapon_glock, CGlock );
LINK_ENTITY_TO_CLASS( weapon_9mmhandgun, CGlock );
These two lines simply link the weapon_glock
and weapon_9mmhandgun
classnames to the CGlock
class. There's a couple of things you can choose to do here:
weapon_9mmhandgun
will be inaccurateweapon_9mmhandgun
and only use weapon_glock
in your modweapon_9mmhandgun
in there for compatibility reasons, and also add a weapon_45acphandgun
classnameweapon_9mmhandgun
is actually used in a number of other files and would require a bunch of changes that aren't particularly important. (For example, barney drops one on death, it can be included in a func_breakable, the player is given one on spawn in HLDM, and so on.)weapon_glock
is the classname that gets exposed in the FGD, so mappers don't get confused. Changing classnames is not the focus of this article, so it won't be mentioned again.
Spawn
function:
m_iDefaultAmmo = GLOCK_DEFAULT_GIVE;
Since the code is using the GLOCK_DEFAULT_GIVE
constant, you don't need to change anything here.
GetItemInfo
, you need to update the ammo name and maximum carry values.
p->pszAmmo1 = "9mm";
p->iMaxAmmo1 = _9MM_MAX_CARRY;
p->pszAmmo1 = "45acp";
p->iMaxAmmo1 = _45ACP_MAX_CARRY;
GLOCK_MAX_CLIP
constant. So you need to make a small change to this method:
if (m_iClip == 0)
iResult = DefaultReload(17, GLOCK_RELOAD, 1.5);
else
iResult = DefaultReload(17, GLOCK_RELOAD_NOT_EMPTY, 1.5);
if (m_iClip == 0)
iResult = DefaultReload(GLOCK_MAX_CLIP, GLOCK_RELOAD, 1.5);
else
iResult = DefaultReload(GLOCK_MAX_CLIP, GLOCK_RELOAD_NOT_EMPTY, 1.5);
CGlockAmmo
class. Simply change the ammo type given by the AddAmmo
function to our new ammo type:
bool AddAmmo(CBaseEntity* pOther) override
{
if (pOther->GiveAmmo(AMMO_GLOCKCLIP_GIVE, "9mm", _9MM_MAX_CARRY) != -1)
{
EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM);
return true;
}
return false;
}
bool AddAmmo(CBaseEntity* pOther) override
{
if (pOther->GiveAmmo(AMMO_GLOCKCLIP_GIVE, "45acp", _45ACP_MAX_CARRY) != -1)
{
EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM);
return true;
}
return false;
}
PlayerSpawn
function:
if (addDefault)
{
pPlayer->GiveNamedItem("weapon_crowbar");
pPlayer->GiveNamedItem("weapon_9mmhandgun");
pPlayer->GiveAmmo(68, "9mm", _9MM_MAX_CARRY); // 4 full reloads
}
if (addDefault)
{
pPlayer->GiveNamedItem("weapon_crowbar");
pPlayer->GiveNamedItem("weapon_9mmhandgun");
pPlayer->GiveAmmo(GLOCK_MAX_CLIP * 4, "45acp", _45ACP_MAX_CARRY); // 4 full reloads
}
CBaseEntity
class for your new ammo count:
//We use this variables to store each ammo count.
int ammo_9mm;
int ammo_357;
//We use this variables to store each ammo count.
int ammo_9mm;
int ammo_45acp;
int ammo_357;
TabulateAmmo
function. Add a new line to populate the new ammo value using the AmmoInventory
method:
ammo_9mm = AmmoInventory(GetAmmoIndex("9mm"));
ammo_357 = AmmoInventory(GetAmmoIndex("357"));
ammo_9mm = AmmoInventory(GetAmmoIndex("9mm"));
ammo_45acp = AmmoInventory(GetAmmoIndex("45acp"));
ammo_357 = AmmoInventory(GetAmmoIndex("357"));
clientdata_s
structure. We have to make do with using one of the unused variables in order to get our new ammo counter sent across the network. In client.cpp, find the UpdateClientData
function and scroll down to the section marked out by a #if defined( CLIENT_WEAPONS )
block.clientdata_s
isn't being used here, you're free to use it yourself. As you might expect, this could be quite problematic if you want to add a lot of new ammo types, or other bits of data that need to be sent here. You'll need to be very careful about how you use these values. The "safe" variables in the unmodified SDK that aren't used elsewhere in UpdateClientData
are:
vuser3.x
to transfer the .45 ACP ammo value:
cd->ammo_cells = pl->ammo_uranium;
cd->vuser2.x = pl->ammo_hornets;
cd->ammo_cells = pl->ammo_uranium;
cd->vuser2.x = pl->ammo_hornets;
cd->vuser3.x = pl->ammo_45acp;
HUD_WeaponsPostThink
method. Search for a reference to ammo_rockets
, and add some code after it:
player.ammo_hornets = (int)from->client.vuser2[0];
player.ammo_rockets = (int)from->client.ammo_rockets;
player.ammo_hornets = (int)from->client.vuser2[0];
player.ammo_rockets = (int)from->client.ammo_rockets;
player.ammo_45acp = (int)from->client.vuser3[0];
to->client.vuser2[0] = player.ammo_hornets;
to->client.ammo_rockets = player.ammo_rockets;
to->client.vuser2[0] = player.ammo_hornets;
to->client.ammo_rockets = player.ammo_rockets;
to->client.vuser3[0] = player.ammo_45acp;
10
weapon 320 320hud1 0 40 80 20
weapon_s 320 320hud1 0 60 80 20
ammo 320 320hud2 0 16 18 18
crosshair 320 crosshairs 24 0 24 24
autoaim 320 crosshairs 0 72 24 24
weapon 640 640hud1 0 45 170 45
weapon_s 640 640hud4 0 45 170 45
ammo 640 640hud7 144 72 24 24
crosshair 640 crosshairs 24 0 24 24
autoaim 640 crosshairs 0 72 24 24
The important lines here are the ones starting with ammo
. You can either edit the existing sprites (320hud2 and 640hud7) to add your new icons, or simply create new sprites and update this text file. Either way, you'll need to also update the X and Y coordinates in the text file as well, to point to the new images.ammo 640 640hud7 144 72 24 24
The process is much the same for the 320 HUD sprite.
You must log in to post a comment. You can login or register a new account.