Source Modding - Part 2 - Everything Is Essence

In the previous part of the tutorial, we learned the basic work with the VPC and how to print messages to the developer console.



In this part of the tutorial, we will break down the entity system, learn how to create classes, and create our first logical entity.





Again terms



(entity) — .

I/O — , "" .

(input) — , . .

(output) — , .



, ?



Source — .



, worldspawn. — "" , :



  • a.k.a. — , , , etc.
  • displacements (, ) — , ( CS:GO !) . , "" .
  • (prop_static). prop_dynamic, .


( !) .



:





  • — , .
  • — , .


/Hammer: displacement , (vbsp)!





— , . !



, logic_auto .



logic_5 —



, .



  1. logic_5.cpp.

    , : src/game/server/logic_5.cpp.



  2. :



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


  3. CLogicFive CLogicEntity:



    class CLogicFive : public CLogicEntity {
        DECLARE_CLASS( CLogicFive, CLogicEntity );
    public:
        // ...
    private:
        // ...
    };


    -! DECLARE_CLASS()? , . — ThisClass BaseClass ( ...).



  4. public:



    public:
        DECLARE_DATADESC();
        void Input_Tick( inputdata_t &id );


    ?



    • DECLARE_DATADESC() , .
    • void Input_Tick( inputdata_t &id ) , tick.


  5. private:



    private:
        int m_iTicks = 0;


  6. " " logic_5.

    ( !) — LINK_ENTITY_TO_CLASS()!

    :



        // ...
        int m_iTicks = 0;
    };
    LINK_ENTITY_TO_CLASS( logic_5, CLogicFive );


  7. , 4:



    BEGIN_DATADESC( CLogicFive )
        DEFINE_FIELD( m_iTicks, FIELD_INTEGER ), //   
        DEFINE_INPUTFUNC( FIELD_VOID, "tick", Input_Tick ), //  
    END_DATADESC();


    • BEGIN_DATADESC() — , .
    • DEFINE_FIELD() — , . , !
    • DEFINE_INPUTFUNC() — , . (FIELD_VOID), tick Input_Tick.
    • END_DATADESC() — , .


  8. Input_Tick:



    //   tick()
    void CLogicFive::Input_Tick( inputdata_t &id )
    {
        m_iTicks++;
        if( m_iTicks % 5 == 0 )
            //       ,   !
            ConColorMsg( Color( 255, 255, 0 ), "logic_five: Another fifth tick!\n" );
    }


  9. [] VPC :



    // src/game/server/server_episodic.vpc
    // -  $Folder "Source Files"
    $File "$SRCDIR/game/server/logic_5.cpp


    , , .





logic_5 —



  1. (sdk_vehicles dm_lockdown, )
  2. :



    ent_create logic_5
  3. tick :



    ent_fire logic_5 tick
  4. ( ) !




?



[ , ] :



  • -


?



Valve Hammer Editor FGD .

, , .








All Articles