Skip to content

Commit 7472aac

Browse files
committed
additionalequipment kv can now load custom script
1 parent e6f41d0 commit 7472aac

3 files changed

Lines changed: 41 additions & 5 deletions

File tree

sp/src/game/server/ai_basenpc.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8051,7 +8051,30 @@ void CAI_BaseNPC::NPCInit ( void )
80518051
{ // Does this npc spawn with a weapon
80528052
if ( m_spawnEquipment != NULL_STRING && strcmp(STRING(m_spawnEquipment), "0"))
80538053
{
8054-
CBaseCombatWeapon *pWeapon = Weapon_Create( STRING(m_spawnEquipment) );
8054+
CBaseCombatWeapon *pWeapon;
8055+
#ifdef MAPBASE
8056+
char szWeaponName[MAX_WEAPON_STRING] = "";
8057+
char szScriptName[MAX_WEAPON_STRING] = "";
8058+
8059+
//we can have a custom script name for the weapon on npc spawn, split by a comma
8060+
const char* pComma = strchr(m_spawnEquipment.ToCStr(), ',');
8061+
if (pComma)
8062+
{
8063+
size_t weaponLen = pComma - m_spawnEquipment.ToCStr();
8064+
if (weaponLen > 0 && weaponLen < sizeof(szWeaponName))
8065+
{
8066+
V_strncpy(szWeaponName, m_spawnEquipment.ToCStr(), weaponLen + 1);
8067+
}
8068+
V_strncpy(szScriptName, pComma + 1, sizeof(szScriptName));
8069+
Msg("Script %s\n", szScriptName);
8070+
8071+
m_spawnEquipment = MAKE_STRING(szWeaponName);
8072+
pWeapon = CBaseEntity::Create(szWeaponName, Vector(0, 0, 0), QAngle(0, 0, 0), this);
8073+
}
8074+
else
8075+
#endif // MAPBASE
8076+
pWeapon = Weapon_Create( STRING(m_spawnEquipment) );
8077+
80558078
if ( pWeapon )
80568079
{
80578080
// If I have a name, make my weapon match it with "_weapon" appended
@@ -8066,6 +8089,12 @@ void CAI_BaseNPC::NPCInit ( void )
80668089
pWeapon->AddEffects( EF_NOSHADOW );
80678090
}
80688091

8092+
#ifdef MAPBASE
8093+
//load script if not empty
8094+
if (szScriptName[0] != '\0')
8095+
pCombatWeapon->SetCustomWeaponScriptName(szScriptName);
8096+
#endif // MAPBASE
8097+
80698098
Weapon_Equip( pWeapon );
80708099
}
80718100
}

sp/src/game/shared/basecombatweapon_shared.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,12 +2041,18 @@ void CBaseCombatWeapon::InputForceSecondaryFire( inputdata_t &inputdata )
20412041
}
20422042

20432043
//-----------------------------------------------------------------------------
2044-
// Purpose: Input to change the weapon script.
2044+
// Purpose: Input to change the weapon script name and re-Precache
20452045
//-----------------------------------------------------------------------------
20462046
void CBaseCombatWeapon::InputChangeScript(inputdata_t& inputdata)
20472047
{
2048-
const char* pszNewScript = inputdata.value.String();
2048+
SetCustomWeaponScriptName(inputdata.value.String());
2049+
}
20492050

2051+
//-----------------------------------------------------------------------------
2052+
// Purpose: Changes weapon script by name
2053+
//-----------------------------------------------------------------------------
2054+
void CBaseCombatWeapon::SetCustomWeaponScriptName(const char* pszNewScript)
2055+
{
20502056
//don't update if empty or already used this script
20512057
if (!pszNewScript || !pszNewScript[0] || FClassnameIs(this, pszNewScript))
20522058
return;
@@ -2145,7 +2151,7 @@ void CBaseCombatWeapon::InputChangeScript(inputdata_t& inputdata)
21452151

21462152
if (UsesClipsForAmmo2())
21472153
m_iClip2 = GetMaxClip2();
2148-
2154+
21492155
return;
21502156
}
21512157

@@ -2157,7 +2163,7 @@ void CBaseCombatWeapon::InputChangeScript(inputdata_t& inputdata)
21572163

21582164
if (UsesClipsForAmmo2() && m_iClip2 > GetMaxClip2())
21592165
m_iClip2 = GetMaxClip2();
2160-
2166+
21612167
return;
21622168
}
21632169
}

sp/src/game/shared/basecombatweapon_shared.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ class CBaseCombatWeapon : public BASECOMBATWEAPON_DERIVED_FROM
220220
virtual const char* GetClassname();
221221
#if !defined( CLIENT_DLL )
222222
virtual bool ClassMatches( string_t nameStr );
223+
void SetCustomWeaponScriptName(const char* pszNewScript);
223224
#endif
224225
virtual bool ClassMatches( const char* pszClassOrWildcard );
225226
#endif

0 commit comments

Comments
 (0)