Laserweapon: Difference between revisions
NickBMarine (talk | contribs) No edit summary |
(changed unknow <code> tags to <pre> tags -Xoom3r) |
||
Line 1: | Line 1: | ||
[[Category:Weapons programming]] | [[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! | ||
'''1 Open pistol.cpp''' | '''1 Open pistol.cpp''' | ||
1.1 Add this under includes "gamestat.h": | 1.1 Add this under includes "gamestat.h": | ||
<pre> #include "beam_shared.h" | |||
< | |||
#include "ammodef.h" | #include "ammodef.h" | ||
#define PHYSCANNON_BEAM_SPRITE "sprites/orangelight1.vmt"</pre> | |||
#define PHYSCANNON_BEAM_SPRITE "sprites/orangelight1.vmt"</ | |||
beam_shared.h defines alot abount beams | beam_shared.h defines alot abount beams | ||
ammodef.h is needed for the trace of the laser | 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 | 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();): | 1.2 Add in ''public'' (under DECLARE_SERVERCLASS();): | ||
<pre> void DrawBeam( const Vector &startPos, const Vector &endPos, float width ); | |||
< | void DoImpactEffect( trace_t &tr, int nDamageType );</pre> | ||
void DoImpactEffect( trace_t &tr, int nDamageType );</ | |||
DrawBeam and DoImpactEffect are new parts that we will put in the script | DrawBeam and DoImpactEffect are new parts that we will put in the script | ||
1.3 Add in ''private'' (under DECLARE_ACTTABLE();): | 1.3 Add in ''private'' (under DECLARE_ACTTABLE();): | ||
<pre> int m_nBulletType;</pre> | |||
< | |||
m_nBulletType is a variable that we will use in the script | m_nBulletType is a variable that we will use in the script | ||
1.4 Add under ''BEGIN_DATADESC( CWeaponPistol )'': | 1.4 Add under ''BEGIN_DATADESC( CWeaponPistol )'': | ||
<pre> DEFINE_FIELD( m_nBulletType, FIELD_INTEGER ),</pre> | |||
< | |||
an extra define of m_nBulletType | an extra define of m_nBulletType | ||
1.5 Change: | 1.5 Change: | ||
<pre>void PrimaryAttack( void );</pre> | |||
< | |||
to | to | ||
<pre>void PrimaryAttack( trace_t &tr, int nDamageType, CBaseCombatCharacter *pOperator );</pre> | |||
< | |||
We will need trace_t &tr, int nDamageType, CBaseCombatCharacter *pOperator in the Primaryattack part | We will need trace_t &tr, int nDamageType, CBaseCombatCharacter *pOperator in the Primaryattack part | ||
1.6 Go to | 1.6 Go to | ||
<pre>CWeaponPistol::CWeaponPistol( void )</pre> | |||
< | |||
Add: | Add: | ||
<pre>m_nBulletType = -1;</pre> | |||
< | |||
1.7 Scroll down to: | 1.7 Scroll down to: | ||
<pre>void CWeaponPistol::PrimaryAttack( void )</pre> | |||
< | |||
and change it to | and change it to | ||
<pre>void CWeaponPistol::PrimaryAttack( trace_t &tr, int nDamageType, CBaseCombatCharacter *pOperator )</pre> | |||
< | |||
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 | ||
1.8 After | 1.8 After | ||
<pre> m_iPrimaryAttacks++; | |||
gamestats->Event_WeaponFired( pOwner, true, GetClassname() );</pre> | |||
< | |||
gamestats->Event_WeaponFired( pOwner, true, GetClassname() );</ | |||
Add: | Add: | ||
<pre> | |||
< | |||
Vector vecShootOrigin, vecShootDir; | Vector vecShootOrigin, vecShootDir; | ||
vecShootOrigin = pOperator->Weapon_ShootPosition(); | vecShootOrigin = pOperator->Weapon_ShootPosition(); | ||
DrawBeam( vecShootOrigin, tr.endpos, 15.5 );</pre> | |||
DrawBeam( vecShootOrigin, tr.endpos, 15.5 );</ | |||
We say that hl2 has to draw a beam from vecShootOrigin to tr.endpos | 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: | 1.9 Scroll down to the end of the script, add: | ||
<pre>//----------------------------------------------------------------------------- | |||
< | |||
// Purpose: | // Purpose: | ||
// Input : &startPos - | // Input : &startPos - | ||
// &endPos - | // &endPos - | ||
// width - | // width - | ||
// useMuzzle - | // useMuzzle - | ||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||
void CWeaponPistol::DrawBeam( const Vector &startPos, const Vector &endPos, float width ) | void CWeaponPistol::DrawBeam( const Vector &startPos, const Vector &endPos, float width ) | ||
{ | { | ||
//Tracer down the middle | //Tracer down the middle | ||
UTIL_Tracer( startPos, endPos, 0, TRACER_DONT_USE_ATTACHMENT, 6500, false, "GaussTracer" ); | UTIL_Tracer( startPos, endPos, 0, TRACER_DONT_USE_ATTACHMENT, 6500, false, "GaussTracer" ); | ||
//Draw the main beam shaft | //Draw the main beam shaft | ||
CBeam *pBeam = CBeam::BeamCreate( PHYSCANNON_BEAM_SPRITE, 15.5 ); | CBeam *pBeam = CBeam::BeamCreate( PHYSCANNON_BEAM_SPRITE, 15.5 ); | ||
pBeam->SetStartPos( startPos ); | pBeam->SetStartPos( startPos ); | ||
pBeam->PointEntInit( endPos, this ); | pBeam->PointEntInit( endPos, this ); | ||
pBeam->SetEndAttachment( LookupAttachment("Muzzle") ); | pBeam->SetEndAttachment( LookupAttachment("Muzzle") ); | ||
pBeam->SetWidth( width ); | pBeam->SetWidth( width ); | ||
// pBeam->SetEndWidth( 0.05f ); | // pBeam->SetEndWidth( 0.05f ); | ||
pBeam->SetBrightness( 255 ); | pBeam->SetBrightness( 255 ); | ||
pBeam->SetColor( 255, 185+random->RandomInt( -16, 16 ), 40 ); | pBeam->SetColor( 255, 185+random->RandomInt( -16, 16 ), 40 ); | ||
pBeam->RelinkBeam(); | pBeam->RelinkBeam(); | ||
pBeam->LiveForTime( 0.1f ); | pBeam->LiveForTime( 0.1f ); | ||
} | } | ||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||
// Purpose: | // Purpose: | ||
// Input : &tr - | // Input : &tr - | ||
// nDamageType - | // nDamageType - | ||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||
void CWeaponPistol::DoImpactEffect( trace_t &tr, int nDamageType ) | void CWeaponPistol::DoImpactEffect( trace_t &tr, int nDamageType ) | ||
{ | { | ||
//Draw our beam | //Draw our beam | ||
DrawBeam( tr.startpos, tr.endpos, 15.5 ); | DrawBeam( tr.startpos, tr.endpos, 15.5 ); | ||
if ( (tr.surface.flags & SURF_SKY) == false ) | if ( (tr.surface.flags & SURF_SKY) == false ) | ||
{ | { | ||
CPVSFilter filter( tr.endpos ); | CPVSFilter filter( tr.endpos ); | ||
te->GaussExplosion( filter, 0.0f, tr.endpos, tr.plane.normal, 0 ); | te->GaussExplosion( filter, 0.0f, tr.endpos, tr.plane.normal, 0 ); | ||
m_nBulletType = GetAmmoDef()->Index("GaussEnergy"); | m_nBulletType = GetAmmoDef()->Index("GaussEnergy"); | ||
UTIL_ImpactTrace( &tr, m_nBulletType ); | UTIL_ImpactTrace( &tr, m_nBulletType ); | ||
} | } | ||
} | } | ||
</ | </pre> | ||
We define the beam | We define the beam | ||
'''2 Open hl2_gamerules.cpp''' | '''2 Open hl2_gamerules.cpp''' | ||
Change | Change | ||
<pre>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 );</pre> | |||
< | |||
to | to | ||
<pre>def.AddAmmoType("Pistol", DMG_DISSOLVE, TRACER_NONE, "sk_plr_dmg_pistol", "sk_npc_dmg_pistol", "sk_max_pistol", BULLET_IMPULSE(200, 1225), 0 );</pre> | |||
< | |||
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 | ||
'''3 Open \Steam\steamapps\SourceMods\MyMod\scripts\weapon_pistol.txt | '''3 Open \Steam\steamapps\SourceMods\MyMod\scripts\weapon_pistol.txt | ||
''' | ''' | ||
3.1 Change | 3.1 Change | ||
<pre>"printname" "#HL2_Pistol"</pre> | |||
< | |||
to | to | ||
<pre>"printname" "LASER PISTOL"</pre> | |||
< | |||
We change the name in the bucket | 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 | 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''' | '''4 Open \Steam\steamapps\SourceMods\MyMod\cfg\skill.cfg''' | ||
Change | Change | ||
<pre>sk_plr_dmg_pistol "5" | |||
< | sk_npc_dmg_pistol "3" | ||
sk_max_pistol "148"</pre> | |||
to | to | ||
<pre> sk_plr_dmg_pistol "20" | |||
< | |||
sk_npc_dmg_pistol "15" | sk_npc_dmg_pistol "15" | ||
sk_max_pistol "148"</pre> | |||
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. | THis weapon doesn't shoot with normal bullets but with a laser so it will do a bigger damage to the enemy. | ||
I hope this helps u a bit | I hope this helps u a bit | ||
Speedlly (Scubic) | Speedlly (Scubic) | ||
this weapon (or a part of it) is going to play a role in the game that were maken (Cubic Life) | |||
Revision as of 05:53, 17 February 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 CWeaponPistol::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. 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)