Forum Thread
  Posts  
Half Life coding tutorial, [simple] (Forums : Coding & Scripting : Half Life coding tutorial, [simple]) Locked
Thread Options
ian502
ian502 [C][M] clan-master
Apr 15 2010 Anchor

For those that want to be coders of half life mods, i will give you my knowing.

Contents of the tutorial :

What are scripts?
Make a weapon in half life (simple tutorial)
Make an experimental weapon in half life (like gauss, egon, etc)

What are scripts?

Scripts are single piece of codes that could make a game with the Knowings of the language. it could depend of what are you coding if is c++, java, pascal, etc.

Making a weapon in half life.

To start a weapon, open the notepad

and copy this in the note pad

Someone wrote:
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "player.h"


That is to define the "headers" written in the language C++ . if you delete something here on the list, your weapon won´t work very good.

lets proceed with the animations :

Someone wrote:
enum WEAPON_e {
WEAPON_IDLE1 = 0,
WEAPON_IDLE2,
WEAPON_IDLE3,
WEAPON_SHOOT,
WEAPON_SHOOT_EMPTY,
WEAPON_RELOAD,
WEAPON_RELOAD_NOT_EMPTY,
WEAPON_DRAW,
WEAPON_HOLSTER,
WEAPON_ADD_SILENCER

};


Please note the "WEAPON" at the start of the animations change that "WEAPON" for the name of your pistol. for example "FSEVEN" (five seven) or "USP" (you cant put glock because the "GLOCK" is used by the original pistol of the hl)
Instead of "GLOCK" you could use "GLOCK18" or "GLOCK19"

Seeya later, ill be doing this tutorial until i finish this.

Apr 15 2010 Anchor

What, notepad?

I realize that you haven't finished this yet, but it would probably be more useful for some if you'd explain some simple weapon that already exists (and its baseclasses to some extent) instead of showing some includes and an enumeration without any purpose.

After that you could still show how to change the model, add some fancy effects or change it so it's not a hitscan weapon anymore.

Edited by: biohazardger

MrTambourineMan
MrTambourineMan Working on Maggie's Farm
Apr 15 2010 Anchor

ian502 wrote: That is to define the "headers" written in the language C++ .

Actually this is to include headers, headers are defined in a header file...

Edited by: MrTambourineMan

ian502
ian502 [C][M] clan-master
Apr 15 2010 Anchor

MrTambourine : >You are right i forgot about the "include part" XD

biohazardger : Yes, in notepad, because then you save it as "weapon.cpp" (or any name) into the folder named DLLS. I will be finishing it soon.

--

You can´t escape from my coding abilities !!! MUAHHAHAHAHAHAHAHAH

Apr 15 2010 Anchor

And what about using some editor with syntax highlighting at least? I dunno what you're using to compile it, but chances are that your compiler has a built-in editor.
If you want to use notepad for yourself, fine then, but it's a bad idea to suggest it to newcomers.

Edited by: biohazardger

ian502
ian502 [C][M] clan-master
Apr 16 2010 Anchor

well to compile you need a c++ 6.0 Compiler because thats the project file it´s a c++6.0 project.

Im using the : Microsoft Visual C++ 6.0 Standard Edition. Very recommended
Lets follow with the tutorial here comes the interesting part

Someone wrote:
class CWeapon : public CBasePlayerWeapon
{
public:
void Spawn( void );
void Precache( void );
int iItemSlot( void ) { return 2; }
int GetItemInfo(ItemInfo *p);

void PrimaryAttack( void );
void SecondaryAttack( void );
void WeaponFire( float flSpread, float flCycleTime, BOOL fUseAutoAim );
BOOL Deploy( void );
void Reload( void );
void WeaponIdle( void );

private:
int m_iShell;

unsigned short m_usWeapon1;
unsigned short m_usWeapon2;
};
LINK_ENTITY_TO_CLASS( weapon_weapon, CWeapon);
LINK_ENTITY_TO_CLASS( weapon_weaponname2, CWeapon );

void CGlock::Spawn( )
{
pev->classname = MAKE_STRING("weapon_weapon"); // hack to allow for old names
Precache( );
m_iId = WEAPON_GLOCK;
SET_MODEL(ENT(pev), "models/w_model.mdl");

m_iDefaultAmmo = WEAPON_DEFAULT_GIVE;

FallInit();// get ready to fall down.
}

void CGlock::Precache( void )
{
PRECACHE_MODEL("models/v_model.mdl");
PRECACHE_MODEL("models/w_model.mdl");
PRECACHE_MODEL("models/p_model.mdl");

m_iShell = PRECACHE_MODEL ("models/shell.mdl");// brass shell

PRECACHE_SOUND("items/9mmclip1.wav");
PRECACHE_SOUND("items/9mmclip2.wav");

PRECACHE_SOUND ("weapons/pl_gun1.wav");//silenced handgun
PRECACHE_SOUND ("weapons/pl_gun2.wav");//silenced handgun
PRECACHE_SOUND ("weapons/pl_gun3.wav");//handgun

m_usFireGlock1 = PRECACHE_EVENT( 1, "events/glock1.sc" );
m_usFireGlock2 = PRECACHE_EVENT( 1, "events/glock2.sc" );
}


now we are going to define de ammo of the weapon you could try to make the weapon shoot m203.

Someone wrote:
int CWeapon::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
p->pszAmmo1 = "9mm"; //buckshot (shotgun ammo)---357 (phyton ammo)--
p->iMaxAmmo1 = _9MM_MAX_CARRY;
p->pszAmmo2 = NULL; //later we will make a gun with secondary fire
p->iMaxAmmo2 = -1;
p->iMaxClip = GLOCK_MAX_CLIP; // Use this as default, its a fistol tutorial
p->iSlot = 1; // change the slot of the weapon : slot 0 will be the number 1 (crowbar)slot 1 will be the 2 slot 3 will be the 4 (rpg-//gauss-etc)
p->iPosition = 2;
p->iFlags = 0;
p->iId = m_iId = WEAPON_WEAPON; // this will be used later
p->iWeight = GLOCK_WEIGHT; // this is only the weight, if you want to go fast use this : SATCHEL_WEIGHT

return 1;
}


See ya tommorrow. with more tutorial

Edited by: ian502

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.