Authoring your first weapon entity

From Valve Developer Community
Revision as of 19:46, 6 May 2017 by Atom (talk | contribs) (Created page with "{{toc-right}} == Overview == 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 sc...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Overview

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.

Getting Started

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.