Pick up the crowbar of research scientist Gordon Freeman, who finds himself on an alien-infested Earth being picked to the bone, its resources depleted, its populace dwindling. Freeman is thrust into the unenviable role of rescuing the world from the wrong he unleashed back at Black Mesa. And a lot of people, people he cares about, are counting on him.

Report article How to make a laser weapon (hl2 mod)

It was hard for me to make a laser for our game (Cubic Life) so I tought, I'll make my own tutorial and promote our game a bit ;p If u want to put a laser in ur mod just follow this tutorial.

Posted by Speedlly on Nov 8th, 2009 digg this super bookmark
Intermediate Server Side Coding.


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

Just follow this tutorial and ur pistol is going to shoot laserbeams

 1 Open pistol.cpp

add this under includes "gamestat.h":

  1. C++ code:
  1. #include "beam_shared.h"
  2. #include "ammodef.h"
  3. #define PHYSCANNON_BEAM_SPRITE "sprites/orangelight1.vmt"

beam_shared.h defines alot about 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

add in public (under DECLARE_SERVERCLASS();):

  1. C++ code:
  1. void    DrawBeam( const Vector &startPos, const Vector &endPos, float width );
  2. void    DoImpactEffect( trace_t &tr, int nDamageType );

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

Add in private (under DECLARE_ACTTABLE();):

  1. C++ code:
  1. int        m_nBulletType;

m_nBulletType is a variable that we will use in the script

Add under BEGIN_DATADESC( CWeaponPistol ):

  1. C++ code:
  1. DEFINE_FIELD( m_nBulletType,            FIELD_INTEGER ),

an extra define for m_nBulletType

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

Go to

  1. C++ code:
  1. CWeaponPistol::CWeaponPistol( void )

Add:

  1. C++ code:
  1. m_nBulletType        = -1;

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

 

  1. C++ code:
  1. //-----------------------------------------------------------------------------
  2. // Purpose:
  3. // Input  : &startPos -
  4. //      &endPos -
  5. //      width -
  6. //      useMuzzle -
  7. //-----------------------------------------------------------------------------
  8. void CWeaponPistol::DrawBeam( const Vector &startPos, const Vector &endPos, float width )
  9. {
  10.   //Tracer down the middle
  11.   UTIL_Tracer( startPos, endPos, 0, TRACER_DONT_USE_ATTACHMENT, 6500, false, "GaussTracer" );
  12.  
  13.   //Draw the main beam shaft
  14.   CBeam *pBeam = CBeam::BeamCreate( PHYSCANNON_BEAM_SPRITE, 15.5 );
  15.  
  16.   pBeam->SetStartPos( startPos );
  17.   pBeam->PointEntInit( endPos, this );
  18.   pBeam->SetEndAttachment( LookupAttachment("Muzzle") );
  19.   pBeam->SetWidth( width );
  20. //  pBeam->SetEndWidth( 0.05f );
  21.   pBeam->SetBrightness( 255 );
  22.   pBeam->SetColor( 255, 185+random->RandomInt( -16, 16 ), 40 );
  23.   pBeam->RelinkBeam();
  24.   pBeam->LiveForTime( 0.1f );
  25. }
  26. //-----------------------------------------------------------------------------
  27. // Purpose:
  28. // Input  : &tr -
  29. //      nDamageType -
  30. //-----------------------------------------------------------------------------
  31. void CWeaponPistol::DoImpactEffect( trace_t &tr, int nDamageType )
  32. {
  33.  
  34.   //Draw our beam
  35.   DrawBeam( tr.startpos, tr.endpos, 15.5 );
  36.  
  37.   if ( (tr.surface.flags & SURF_SKY) == false )
  38.   {
  39.     CPVSFilter filter( tr.endpos );
  40.     te->GaussExplosion( filter, 0.0f, tr.endpos, tr.plane.normal, 0 );
  41.  
  42.     m_nBulletType = GetAmmoDef()->Index("GaussEnergy");
  43.  
  44.     UTIL_ImpactTrace( &tr, m_nBulletType );
  45.   }
  46. }

We define the beam

2 Open hl2_gamerules.cpp

Change

  1. C++ code:
  1. 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

  1. C++ code:
  1. 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

Change

  1. C++ code:
  1. "printname"    "#HL2_Pistol"

to

  1. C++ code:
  1. "printname"    "LASER PISTOL"

We change the name in the bucket

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

  1. C++ code:
  1. sk_plr_dmg_pistol        "5"
  2. sk_npc_dmg_pistol        "3"
  3. sk_max_pistol            "148"


to

  1. C++ code:
  1. sk_plr_dmg_pistol        "20"
  2. sk_npc_dmg_pistol        "15"
  3. 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)

This works... i tested it myself

Comments
ghostings
ghostings Nov 8 2009, 8:21pm says:

GAH D:

That much work for a single laser pistol?

+2 votes     reply to comment
tnk_x5000
tnk_x5000 Nov 9 2009, 3:02am replied: Online

That's normal.

+1 vote     reply to comment
maxen1416
maxen1416 Nov 9 2009, 9:22am says:

too much to read,
why dont you upload pre-made files?
its just an idea though.

+2 votes     reply to comment
tymaxbeta
tymaxbeta Nov 22 2009, 4:48pm replied:

that takes all the fun ;D nice tutorial guys, this is going to be amazing :D

+1 vote     reply to comment
~BloodRaven~
~BloodRaven~ Nov 9 2009, 12:06pm says:

lol thats epic

+1 vote     reply to comment
Calibur25
Calibur25 Nov 10 2009, 3:14pm says:

Just wondering how long it took you to find the code to extend as well as tweek it to your liking? Nice work!

+2 votes     reply to comment
Savant7
Savant7 Nov 11 2009, 11:03am says:

could be useful for my mod i will pass it forward, thanks!

+1 vote     reply to comment
Post a Comment

Only registered members can share their thoughts. So come on! Join the community today (totally free) and do things you never thought possible.

Track this game Profile
Icon
Half-Life 2
Platforms
PC, X360, PS3, XBOX
Developer & Publisher
Valve
Engine
Source
Contact
Send Message
Official Page
Half-life2.com
Release Date
Released Nov 16, 2004
Game Watch
Track this game
Bookmark
Digg Super bookmark
Tutorial
Browse
Tutorials
Report Abuse
Report article
Bookmark
Digg Super bookmark
Related Games
Half-Life 2
Half-Life 2
Single & Multiplayer First Person Shooter
Related Engines
Source
Source
Commercial Released Nov 1, 2004
Related Groups
Valve
Valve
Developer & Publisher