Laserweapon

From Valve Developer Community
Revision as of 12:48, 8 November 2009 by Speedlly (talk | contribs) (Created page with 'How to make a the pistol shoot with a laser: Laser Pistol! '''1 Open pistol.cpp''' 1.1 Add this under includes "gamestat.h": '' #include "beam_shared.h" #include "ammodef.h" …')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

How to make a the pistol shoot with a laser: Laser Pistol!

1 Open pistol.cpp

1.1 Add this under includes "gamestat.h":

#include "beam_shared.h" #include "ammodef.h" #define PHYSCANNON_BEAM_SPRITE "sprites/orangelight1.vmt"

beam_shared.h defines alot abount beams ammodef.h is needed for the trace of the laser the PHYSCANNON_BEAM_SPRITE defines what sprite is used, if u change the vmt u can make the laser have another color

1.2 Add in public (under DECLARE_SERVERCLASS();):

void DrawBeam( const Vector &startPos, const Vector &endPos, float width ); void DoImpactEffect( trace_t &tr, int nDamageType );

DrawBeam and DoImpactEffect are new parts that we will put in the script

1.3 Add in private (under DECLARE_ACTTABLE();):

int m_nBulletType;

m_nBulletType is a variable that we will use in the script

1.4 Add under BEGIN_DATADESC( CWeaponPistol ): DEFINE_FIELD( m_nBulletType, FIELD_INTEGER ),

an extra define of m_nBulletType

1.5 Change:

void PrimaryAttack( void ); to void PrimaryAttack( trace_t &tr, int nDamageType, CBaseCombatCharacter *pOperator );

We will need trace_t &tr, int nDamageType, CBaseCombatCharacter *pOperator in the Primaryattack part

1.6 Go to

CWeaponSniperRifle::CWeaponSniperRifle( void )

Add:

m_nBulletType = -1;

1.7 Scroll down to:

void CWeaponPistol::PrimaryAttack( void )

and change it to

void CWeaponPistol::PrimaryAttack( trace_t &tr, int nDamageType, CBaseCombatCharacter *pOperator ) We will need trace_t &tr, int nDamageType, CBaseCombatCharacter *pOperator in this part

1.8 After

m_iPrimaryAttacks++; gamestats->Event_WeaponFired( pOwner, true, GetClassname() );

Add: Vector vecShootOrigin, vecShootDir; vecShootOrigin = pOperator->Weapon_ShootPosition();

DrawBeam( vecShootOrigin, tr.endpos, 15.5 );

We say that hl2 has to draw a beam from vecShootOrigin to tr.endpos

1.9 Scroll down to the end of the script, add:

//----------------------------------------------------------------------------- // Purpose: // Input  : &startPos - // &endPos - // width - // useMuzzle - //----------------------------------------------------------------------------- void CWeaponPistol::DrawBeam( const Vector &startPos, const Vector &endPos, float width ) { //Tracer down the middle UTIL_Tracer( startPos, endPos, 0, TRACER_DONT_USE_ATTACHMENT, 6500, false, "GaussTracer" );

//Draw the main beam shaft CBeam *pBeam = CBeam::BeamCreate( PHYSCANNON_BEAM_SPRITE, 15.5 );

pBeam->SetStartPos( startPos ); pBeam->PointEntInit( endPos, this ); pBeam->SetEndAttachment( LookupAttachment("Muzzle") ); pBeam->SetWidth( width ); // pBeam->SetEndWidth( 0.05f ); pBeam->SetBrightness( 255 ); pBeam->SetColor( 255, 185+random->RandomInt( -16, 16 ), 40 ); pBeam->RelinkBeam(); pBeam->LiveForTime( 0.1f ); } //----------------------------------------------------------------------------- // Purpose: // Input  : &tr - // nDamageType - //----------------------------------------------------------------------------- void CWeaponSniperRifle::DoImpactEffect( trace_t &tr, int nDamageType ) {

//Draw our beam DrawBeam( tr.startpos, tr.endpos, 15.5 );

if ( (tr.surface.flags & SURF_SKY) == false ) { CPVSFilter filter( tr.endpos ); te->GaussExplosion( filter, 0.0f, tr.endpos, tr.plane.normal, 0 );

m_nBulletType = GetAmmoDef()->Index("GaussEnergy");

UTIL_ImpactTrace( &tr, m_nBulletType ); } }

We define the beam

2 Open hl2_gamerules.cpp

Change

def.AddAmmoType("Pistol", DMG_BULLET, TRACER_LINE_AND_WHIZ, "sk_plr_dmg_pistol", "sk_npc_dmg_pistol", "sk_max_pistol", BULLET_IMPULSE(200, 1225), 0 );

to

def.AddAmmoType("Pistol", DMG_DISSOLVE, TRACER_NONE, "sk_plr_dmg_pistol", "sk_npc_dmg_pistol", "sk_max_pistol", BULLET_IMPULSE(200, 1225), 0 ); If the enemy dies, he will dissolve and there dont draw a line after the bullet

3 Open \Steam\steamapps\SourceMods\MyMod\scripts\weapon_pistol.txt 3.1 Change

"printname" "#HL2_Pistol"

to

"printname" "LASER PISTOL"

We change the name in the bucket

3.1 If u know how u can change the SoundData so it will make a better noise

4 Open \Steam\steamapps\SourceMods\MyMod\cfg\skill.cfg

Change

sk_plr_dmg_pistol "5" sk_npc_dmg_pistol "3" sk_max_pistol "148"

to

sk_plr_dmg_pistol "20" sk_npc_dmg_pistol "15" sk_max_pistol "148"

THis weapon doesn't shoot with normal bullets but with a laser so it will do a bigger damage to the enemy.

END

I hope this helps u a bit

Speedlly (Scubic)

=> this weapon (or a part of it) is going to play a role in the game that were maken (Cubic Life)