[CS2] New hint messages

Aici se discuta doar de scripting dar legat de sourcemod.

Moderators: Moderatori ajutători, Scripteri TheXForce

Post Reply
User avatar
Rainq
Fost administrator
Fost administrator
Posts: 381
Joined: Mon Jan 18, 2021 7:25 am
Status: Citesc forumul TheXForce.RO...!
Detinator Steam: Da
SteamID: mrainq
Gaming experience: Nu spun..
Reputatie: Fost administrator
Nume anterior: Light
Fost detinator zm.thexforce.ro
Fost detinator dr.thexforce.ro
Location: Bucureşti
Has thanked: 2 times
Been thanked: 1 time
Contact:

[CS2] New hint messages

Post by Rainq »

Am găsit o nouă modalitate de a afișa text cu indicii jucătorilor.

Pro:
  • Fontul arată mai frumos decât cel obișnuit
  • Fontul este mai mare în mod implicit
  • Bună animație când este afișată
  • Puteți controla timpul de afișare
  • Puteți schimba culorile
Contra:
  • Nu acceptă etichetele html din ceea ce am testat (în jurul orei 2 dimineața, așa că s-ar putea să mă înșel)
  • În mod implicit, nu puteți suprapune textele cu indicii. Este posibil să trebuiască să creați un eveniment numit „instructor_server_hint_stop” pentru a opri și a afișa un alt text de sugestie. Nu a fost încă testat.

Code: Select all

public void OnPluginStart()
{
    RegConsoleCmd("sm_test", Command_Test);
}

public Action Command_Test(int client, int args)
{
    Event new_event = CreateEvent("instructor_server_hint_create", true);
    new_event.SetString("hint_caption", "Ez New Hint by kRatoss");
    new_event.SetInt("hint_timeout", 5); // how many seconds to hold the hint text?
    new_event.SetString("hint_color", "255,0,0");// it does not support alpha, just "r,g,b" ( this format only);
    new_event.Fire();
} 
Image

Dacă doriți să contribuiți, puteți obține de aici toate datele de care aveți nevoie:

Code: Select all

//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: An entity for creating instructor hints entirely with map logic
//
// $NoKeywords: $
//=============================================================================//

#include "cbase.h"
#include "baseentity.h"
#include "world.h"

#ifdef INFESTED_DLL
    #include "asw_marine.h"
    #include "asw_player.h"
#endif

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
class CEnvInstructorHint : public CPointEntity
{
public:
    DECLARE_CLASS( CEnvInstructorHint, CPointEntity );
    DECLARE_DATADESC();

private:
    void InputShowHint( inputdata_t &inputdata );
    void InputEndHint( inputdata_t &inputdata );
    
    string_t    m_iszReplace_Key;
    string_t    m_iszHintTargetEntity;
    int            m_iTimeout;
    string_t    m_iszIcon_Onscreen;
    string_t    m_iszIcon_Offscreen;
    string_t    m_iszCaption;
    string_t    m_iszActivatorCaption;
    color32        m_Color;
    float        m_fIconOffset;
    float        m_fRange;
    uint8        m_iPulseOption;
    uint8        m_iAlphaOption;
    uint8        m_iShakeOption;
    bool        m_bStatic;
    bool        m_bNoOffscreen;
    bool        m_bForceCaption;
    string_t    m_iszBinding;
    string_t    m_iszGamepadBinding;
    bool        m_bAllowNoDrawTarget;
    bool        m_bLocalPlayerOnly;
};


LINK_ENTITY_TO_CLASS( env_instructor_hint, CEnvInstructorHint );

BEGIN_DATADESC( CEnvInstructorHint )

    DEFINE_KEYFIELD( m_iszReplace_Key, FIELD_STRING, "hint_replace_key" ),
    DEFINE_KEYFIELD( m_iszHintTargetEntity, FIELD_STRING, "hint_target" ),
    DEFINE_KEYFIELD( m_iTimeout, FIELD_INTEGER, "hint_timeout" ),
    DEFINE_KEYFIELD( m_iszIcon_Onscreen, FIELD_STRING, "hint_icon_onscreen" ),
    DEFINE_KEYFIELD( m_iszIcon_Offscreen, FIELD_STRING, "hint_icon_offscreen" ),
    DEFINE_KEYFIELD( m_iszCaption, FIELD_STRING, "hint_caption" ),
    DEFINE_KEYFIELD( m_iszActivatorCaption, FIELD_STRING, "hint_activator_caption" ),
    DEFINE_KEYFIELD( m_Color, FIELD_COLOR32, "hint_color" ),
    DEFINE_KEYFIELD( m_fIconOffset, FIELD_FLOAT, "hint_icon_offset" ),
    DEFINE_KEYFIELD( m_fRange, FIELD_FLOAT, "hint_range" ),
    DEFINE_KEYFIELD( m_iPulseOption, FIELD_CHARACTER, "hint_pulseoption" ),
    DEFINE_KEYFIELD( m_iAlphaOption, FIELD_CHARACTER, "hint_alphaoption" ),
    DEFINE_KEYFIELD( m_iShakeOption, FIELD_CHARACTER, "hint_shakeoption" ),
    DEFINE_KEYFIELD( m_bStatic, FIELD_BOOLEAN, "hint_static" ),
    DEFINE_KEYFIELD( m_bNoOffscreen, FIELD_BOOLEAN, "hint_nooffscreen" ),
    DEFINE_KEYFIELD( m_bForceCaption, FIELD_BOOLEAN, "hint_forcecaption" ),
    DEFINE_KEYFIELD( m_iszBinding, FIELD_STRING, "hint_binding" ),
    DEFINE_KEYFIELD( m_iszGamepadBinding, FIELD_STRING, "hint_gamepad_binding" ),
    DEFINE_KEYFIELD( m_bAllowNoDrawTarget, FIELD_BOOLEAN, "hint_allow_nodraw_target" ),    
    DEFINE_KEYFIELD( m_bLocalPlayerOnly, FIELD_BOOLEAN, "hint_local_player_only" ),
    
    DEFINE_INPUTFUNC( FIELD_STRING,    "ShowHint",    InputShowHint ),
    DEFINE_INPUTFUNC( FIELD_VOID,    "EndHint",    InputEndHint ),

END_DATADESC()


#define LOCATOR_ICON_FX_PULSE_SLOW        0x00000001
#define LOCATOR_ICON_FX_ALPHA_SLOW        0x00000008
#define LOCATOR_ICON_FX_SHAKE_NARROW    0x00000040
#define LOCATOR_ICON_FX_STATIC            0x00000100    // This icon draws at a fixed location on the HUD.

//-----------------------------------------------------------------------------
// Purpose: Input handler for showing the message and/or playing the sound.
//-----------------------------------------------------------------------------
void CEnvInstructorHint::InputShowHint( inputdata_t &inputdata )
{
    static int s_InstructorServerHintEventCreate = 0;
    IGameEvent * event = gameeventmanager->CreateEvent( "instructor_server_hint_create", false, &s_InstructorServerHintEventCreate );
    if ( event )
    {
        CBaseEntity *pTargetEntity = gEntList.FindEntityByName( NULL, m_iszHintTargetEntity );
        if( pTargetEntity == NULL )
            pTargetEntity = inputdata.pActivator;

        if( pTargetEntity == NULL )
            pTargetEntity = GetWorldEntity();

        char szColorString[128];
        Q_snprintf( szColorString, sizeof( szColorString ), "%.3d,%.3d,%.3d", m_Color.r, m_Color.g, m_Color.b );

        int iFlags = 0;
        
        iFlags |= (m_iPulseOption == 0) ? 0 : (LOCATOR_ICON_FX_PULSE_SLOW << (m_iPulseOption - 1));
        iFlags |= (m_iAlphaOption == 0) ? 0 : (LOCATOR_ICON_FX_ALPHA_SLOW << (m_iAlphaOption - 1));
        iFlags |= (m_iShakeOption == 0) ? 0 : (LOCATOR_ICON_FX_SHAKE_NARROW << (m_iShakeOption - 1));
        iFlags |= m_bStatic ? LOCATOR_ICON_FX_STATIC : 0;

        CBasePlayer *pActivator = NULL;
        bool bFilterByActivator = m_bLocalPlayerOnly;
        if ( bFilterByActivator )
            pActivator = dynamic_cast<CBasePlayer*>( inputdata.pActivator );

#ifdef INFESTED_DLL
        CASW_Marine *pMarine = dynamic_cast<CASW_Marine*>( inputdata.pActivator );
        if ( pMarine )
        {
            pActivator = pMarine->GetCommander();
        }
#else
        if ( inputdata.value.StringID() != NULL_STRING )
        {
            CBaseEntity *pTarget = gEntList.FindEntityByName( NULL, inputdata.value.String() );
            pActivator = dynamic_cast<CBasePlayer*>( pTarget );
            if ( pActivator )
            {
                bFilterByActivator = true;
            }
        }
        else
        {
            if ( GameRules()->IsMultiplayer() == false )
            {
                pActivator = UTIL_GetLocalPlayer(); 
            }
            else
            {
                if ( !pTargetEntity )
                {
                    Warning( "Failed to play server side instructor hint: no player specified for hint\n" );
                    Assert( 0 );
                }
            }
        }
#endif

        const char *pActivatorCaption = m_iszActivatorCaption.ToCStr();
        if ( !pActivatorCaption || pActivatorCaption[ 0 ] == '\0' )
        {
            pActivatorCaption = m_iszCaption.ToCStr();
        }

        event->SetString( "hint_name", GetEntityName().ToCStr() );
        event->SetString( "hint_replace_key", m_iszReplace_Key.ToCStr() );
        event->SetInt( "hint_target", pTargetEntity->entindex() );
        event->SetInt( "hint_activator_userid", ( pActivator ? pActivator->GetUserID() : 0 ) );
        event->SetInt( "hint_timeout", m_iTimeout );
        event->SetString( "hint_icon_onscreen", m_iszIcon_Onscreen.ToCStr() );
        event->SetString( "hint_icon_offscreen", m_iszIcon_Offscreen.ToCStr() );
        event->SetString( "hint_caption", m_iszCaption.ToCStr() );
        event->SetString( "hint_activator_caption", pActivatorCaption );
        event->SetString( "hint_color", szColorString );
        event->SetFloat( "hint_icon_offset", m_fIconOffset );
        event->SetFloat( "hint_range", m_fRange );
        event->SetInt( "hint_flags", iFlags );
        event->SetString( "hint_binding", m_iszBinding.ToCStr() );
        event->SetString( "hint_gamepad_binding", m_iszGamepadBinding.ToCStr() );
        event->SetBool( "hint_allow_nodraw_target", m_bAllowNoDrawTarget );
        event->SetBool( "hint_nooffscreen", m_bNoOffscreen );
        event->SetBool( "hint_forcecaption", m_bForceCaption );
        event->SetBool( "hint_local_player_only", bFilterByActivator );

        gameeventmanager->FireEvent( event );
    }
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CEnvInstructorHint::InputEndHint( inputdata_t &inputdata )
{
    static int s_InstructorServerHintEventStop = 0;
    IGameEvent * event = gameeventmanager->CreateEvent( "instructor_server_hint_stop", false, &s_InstructorServerHintEventStop );
    if ( event )
    {
        event->SetString( "hint_name", GetEntityName().ToCStr() );

        gameeventmanager->FireEvent( event );
    }
}

//-----------------------------------------------------------------------------
// Purpose: A generic target entity that gets replicated to the client for instructor hint targetting
//-----------------------------------------------------------------------------
class CInfoInstructorHintTarget : public CPointEntity
{
public:
    DECLARE_CLASS( CInfoInstructorHintTarget, CPointEntity );

    virtual int UpdateTransmitState( void )    // set transmit filter to transmit always
    {
        return SetTransmitState( FL_EDICT_ALWAYS );
    }

    DECLARE_DATADESC();
};

LINK_ENTITY_TO_CLASS( info_target_instructor_hint, CInfoInstructorHintTarget );

BEGIN_DATADESC( CInfoInstructorHintTarget )

END_DATADESC() 
Image
Post Reply

Return to “Scripting”