Hello there, I’m trying to figure out how to get some specific keyvalues from game_text.
I’ve already used this to sorta setup a fake entity to assign the values to;
for _, ent in pairs(ents.FindByClass("game_text")) do
local newent = ents.Create("game_text_v2")
if newent:IsValid() then
newent:SetName( ent:GetName() )
for key, values in pairs(ent:GetKeyValues()) do
--print( key.." "..values )
if key == "message" then
newent:SetKeyValue( "message", values )
end
end
--print(newent:GetName())
newent:SetPos(ent:GetPos())
newent:SetAngles(ent:GetAngles())
newent:Spawn()
end
ent:Remove()
end
However when I print all the values a few do NOT show up such as; “color” and “color2”.
Here is the source code for game_text found in Source SDK 2013.
// CGameText / game_text -- NON-Localized HUD Message (use env_message to display a titles.txt message)
// Flag: All players SF_ENVTEXT_ALLPLAYERS
//
#define SF_ENVTEXT_ALLPLAYERS 0x0001
class CGameText : public CRulePointEntity
{
public:
DECLARE_CLASS( CGameText, CRulePointEntity );
bool KeyValue( const char *szKeyName, const char *szValue );
DECLARE_DATADESC();
inline bool MessageToAll( void ) { return (m_spawnflags & SF_ENVTEXT_ALLPLAYERS); }
inline void MessageSet( const char *pMessage ) { m_iszMessage = AllocPooledString(pMessage); }
inline const char *MessageGet( void ) { return STRING( m_iszMessage ); }
void InputDisplay( inputdata_t &inputdata );
void Display( CBaseEntity *pActivator );
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
Display( pActivator );
}
private:
string_t m_iszMessage;
hudtextparms_t m_textParms;
};
LINK_ENTITY_TO_CLASS( game_text, CGameText );
// Save parms as a block. Will break save/restore if the structure changes, but this entity didn't ship with Half-Life, so
// it can't impact saved Half-Life games.
BEGIN_DATADESC( CGameText )
DEFINE_KEYFIELD( m_iszMessage, FIELD_STRING, "message" ),
DEFINE_KEYFIELD( m_textParms.channel, FIELD_INTEGER, "channel" ),
DEFINE_KEYFIELD( m_textParms.x, FIELD_FLOAT, "x" ),
DEFINE_KEYFIELD( m_textParms.y, FIELD_FLOAT, "y" ),
DEFINE_KEYFIELD( m_textParms.effect, FIELD_INTEGER, "effect" ),
DEFINE_KEYFIELD( m_textParms.fadeinTime, FIELD_FLOAT, "fadein" ),
DEFINE_KEYFIELD( m_textParms.fadeoutTime, FIELD_FLOAT, "fadeout" ),
DEFINE_KEYFIELD( m_textParms.holdTime, FIELD_FLOAT, "holdtime" ),
DEFINE_KEYFIELD( m_textParms.fxTime, FIELD_FLOAT, "fxtime" ),
DEFINE_ARRAY( m_textParms, FIELD_CHARACTER, sizeof(hudtextparms_t) ),
// Inputs
DEFINE_INPUTFUNC( FIELD_VOID, "Display", InputDisplay ),
END_DATADESC()
bool CGameText::KeyValue( const char *szKeyName, const char *szValue )
{
if (FStrEq(szKeyName, "color"))
{
int color[4];
UTIL_StringToIntArray( color, 4, szValue );
m_textParms.r1 = color[0];
m_textParms.g1 = color[1];
m_textParms.b1 = color[2];
m_textParms.a1 = color[3];
}
else if (FStrEq(szKeyName, "color2"))
{
int color[4];
UTIL_StringToIntArray( color, 4, szValue );
m_textParms.r2 = color[0];
m_textParms.g2 = color[1];
m_textParms.b2 = color[2];
m_textParms.a2 = color[3];
}
else
return BaseClass::KeyValue( szKeyName, szValue );
return true;
}
void CGameText::InputDisplay( inputdata_t &inputdata )
{
Display( inputdata.pActivator );
}
void CGameText::Display( CBaseEntity *pActivator )
{
if ( !CanFireForActivator( pActivator ) )
return;
if ( MessageToAll() )
{
UTIL_HudMessageAll( m_textParms, MessageGet() );
}
else
{
// If we're in singleplayer, show the message to the player.
if ( gpGlobals->maxClients == 1 )
{
CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
UTIL_HudMessage( pPlayer, m_textParms, MessageGet() );
}
// Otherwise show the message to the player that triggered us.
else if ( pActivator && pActivator->IsNetClient() )
{
UTIL_HudMessage( ToBasePlayer( pActivator ), m_textParms, MessageGet() );
}
}
}
Any help would be appreciated, also here is the source code for the game_text entity.