Authoring your first weapon entity
It should not come as a surprise that the Source engine has a very robust weapon system. This article will cover creating a weapon entity from scratch. Various topics on creating a weapon will be discussed.
To get started, create a new .cpp file in the server project and call it weapon_myfirstweapon. Type this into your newly created file
#include "cbase.h" #include "npcevent.h" #include "in_buttons.h" #ifdef CLIENT_DLL #include "c_hl2mp_player.h" #else #include "hl2mp_player.h" #endif #include "weapon_hl2mpbasehlmpcombatweapon.h"
Just to note something here, this tutorial expects you are using the Source SDK Multiplayer, but if you wanted singleplayer, it should be an easy fix.
Creating The Class
Now we will create the class that contains all the functions, so we can put the code in later. To start, make a new class, and define it like this
class CWeaponMyFirstWeapon : public CBaseHL2MPCombatWeapon
Now, open it up with some curly braces, and type this
public: DECLARE_CLASS(CWeaponMyFirstWeapon, CBaseHL2MPCombatWeapon); CWeaponMyFirstWeapon(void); DECLARE_NETWORKCLASS(); DECLARE_PREDICTABLE();
The code above just starts off the file, makes so it works with the server, and creates the base for the constructor.