Laserweapon: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
(added code tags and categorys)
Line 1: Line 1:
[[Category:Weapons programming]]
How to make a the pistol shoot with a laser: Laser Pistol!
How to make a the pistol shoot with a laser: Laser Pistol!


Line 7: Line 8:




'' #include "beam_shared.h"
<code> #include "beam_shared.h"


#include "ammodef.h"
#include "ammodef.h"


#define PHYSCANNON_BEAM_SPRITE "sprites/orangelight1.vmt"''
#define PHYSCANNON_BEAM_SPRITE "sprites/orangelight1.vmt"</code>


beam_shared.h defines alot abount beams
beam_shared.h defines alot abount beams
Line 22: Line 23:
1.2 Add in ''public'' (under DECLARE_SERVERCLASS();):
1.2 Add in ''public'' (under DECLARE_SERVERCLASS();):


<code> void DrawBeam( const Vector &startPos, const Vector &endPos, float width );


'' void DrawBeam( const Vector &startPos, const Vector &endPos, float width );
void DoImpactEffect( trace_t &tr, int nDamageType );</code>
 
void DoImpactEffect( trace_t &tr, int nDamageType );''




Line 34: Line 34:




'' int m_nBulletType;''
<code> int m_nBulletType;</code>




Line 42: Line 42:
1.4 Add under ''BEGIN_DATADESC( CWeaponPistol )'':
1.4 Add under ''BEGIN_DATADESC( CWeaponPistol )'':


''
<code> DEFINE_FIELD( m_nBulletType, FIELD_INTEGER ),</code>
DEFINE_FIELD( m_nBulletType, FIELD_INTEGER ),''




Line 52: Line 51:




''void PrimaryAttack( void );''
<code>void PrimaryAttack( void );</code>


to
to


''void PrimaryAttack( trace_t &tr, int nDamageType, CBaseCombatCharacter *pOperator );''
<code>void PrimaryAttack( trace_t &tr, int nDamageType, CBaseCombatCharacter *pOperator );</code>




Line 65: Line 64:




''CWeaponPistol::CWeaponPistol( void )''
<code>CWeaponPistol::CWeaponPistol( void )</code>




Line 71: Line 70:




''m_nBulletType = -1;''
<code>m_nBulletType = -1;</code>




Line 77: Line 76:




''void CWeaponPistol::PrimaryAttack( void )''
<code>void CWeaponPistol::PrimaryAttack( void )</code>




Line 83: Line 82:




''void CWeaponPistol::PrimaryAttack( trace_t &tr, int nDamageType, CBaseCombatCharacter *pOperator )
<code>void CWeaponPistol::PrimaryAttack( trace_t &tr, int nDamageType, CBaseCombatCharacter *pOperator )</code>
''


We will need trace_t &tr, int nDamageType, CBaseCombatCharacter *pOperator in this part
We will need trace_t &tr, int nDamageType, CBaseCombatCharacter *pOperator in this part
Line 92: Line 90:




'' m_iPrimaryAttacks++;
<code> m_iPrimaryAttacks++;


gamestats->Event_WeaponFired( pOwner, true, GetClassname() );''
gamestats->Event_WeaponFired( pOwner, true, GetClassname() );</code>




Add:
Add:


''
<code>
Vector vecShootOrigin, vecShootDir;
Vector vecShootOrigin, vecShootDir;


Line 105: Line 103:




DrawBeam( vecShootOrigin, tr.endpos, 15.5 );''
DrawBeam( vecShootOrigin, tr.endpos, 15.5 );</code>




Line 114: Line 112:




''//-----------------------------------------------------------------------------
<code>//-----------------------------------------------------------------------------


// Purpose:  
// Purpose:  
Line 195: Line 193:


}
}
''
</code>




Line 207: Line 205:




''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 );''
<code>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 );</code>




Line 213: Line 211:




''def.AddAmmoType("Pistol", DMG_DISSOLVE, TRACER_NONE, "sk_plr_dmg_pistol", "sk_npc_dmg_pistol", "sk_max_pistol", BULLET_IMPULSE(200, 1225), 0 );
<code>def.AddAmmoType("Pistol", DMG_DISSOLVE, TRACER_NONE, "sk_plr_dmg_pistol", "sk_npc_dmg_pistol", "sk_max_pistol", BULLET_IMPULSE(200, 1225), 0 );</code>
''


If the enemy dies, he will dissolve and there dont draw a line after the bullet
If the enemy dies, he will dissolve and there dont draw a line after the bullet
Line 224: Line 221:
3.1 Change
3.1 Change


''
<code>
"printname" "#HL2_Pistol"''
"printname" "#HL2_Pistol"</code>




to
to


''
<code>
"printname" "LASER PISTOL"''
"printname" "LASER PISTOL"</code>




Line 245: Line 242:
Change
Change


''
<code>
sk_plr_dmg_pistol "5"
sk_plr_dmg_pistol "5"


sk_npc_dmg_pistol "3"
sk_npc_dmg_pistol "3"


sk_max_pistol "148"''
sk_max_pistol "148"</code>




Line 256: Line 253:




'' sk_plr_dmg_pistol "20"
<code> sk_plr_dmg_pistol "20"


sk_npc_dmg_pistol "15"
sk_npc_dmg_pistol "15"


sk_max_pistol "148"''
sk_max_pistol "148"</code>





Revision as of 10:44, 7 January 2010

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


CWeaponPistol::CWeaponPistol( 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)