grenade laser trail

grenade laser trail

Re: grenade laser trail Posted by Crollo on Sun Jun 15th 2008 at 4:23pm
Crollo
148 posts
Posted 2008-06-15 4:23pm
Crollo
member
148 posts 15 snarkmarks Registered: May 8th 2008 Location: Canada
okay, i got the laser for the grenade for my hl2 mod, but i finally got rid of all errors but one, it says "precache();" is a "undeclared identifier"

here's my code:

/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
/*

===== generic grenade.cpp ================================================== ======

*/

#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "soundent.h"
#include "decals.h"

//===================grenade

LINK_ENTITY_TO_CLASS( grenade, CGrenade );

2}// Grenades flagged with this will be triggered when the owner calls detonateSatchelCharges</SPAN>
#define SF_DETONATE 0x0001

//
// Grenade Explode
//
void CGrenade::Explode( Vector vecSrc, Vector vecAim )
{
TraceResult tr;
UTIL_TraceLine ( pev->origin, pev->origin + Vector ( 0, 0, -32 ), ignore_monsters, ENT(pev), & tr);

Explode( &tr, DMG_BLAST );
}

// UNDONE: temporary scorching for PreAlpha - find a less sleazy permenant solution.
void CGrenade::Explode( TraceResult *pTrace, int bitsDamageType )
{
float flRndSound;// sound randomizer

pev->model = iStringNull;//invisible
pev->solid = SOLID_NOT;// intangible

pev->takedamage = DAMAGE_NO;

// Pull out of the wall a bit
if ( pTrace->flFraction != 1.0 )
{
pev->origin = pTrace->vecEndPos + (pTrace->vecPlaneNormal * (pev->dmg - 24) * 0.6);
}

int iContents = UTIL_PointContents ( pev->origin );

MESSAGE_BEGIN( MSG_PAS, SVC_TEMPENTITY, pev->origin );
WRITE_BYTE( TE_EXPLOSION ); // This makes a dynamic light and the explosion sprites/sound
WRITE_COORD( pev->origin.x ); // Send to PAS because of the sound
WRITE_COORD( pev->origin.y );
WRITE_COORD( pev->origin.z );
if (iContents != CONTENTS_WATER)
{
WRITE_SHORT( g_sModelIndexFireball );
}
else
{
WRITE_SHORT( g_sModelIndexWExplosion );
}
WRITE_BYTE( (pev->dmg - 50) * .60 ); // scale * 10
WRITE_BYTE( 15 ); // framerate
WRITE_BYTE( TE_EXPLFLAG_NONE );
MESSAGE_END();

CSoundEnt::InsertSound ( bits_SOUND_COMBAT, pev->origin, NORMAL_EXPLOSION_VOLUME, 3.0 );
entvars_t *pevOwner;
if ( pev->owner )
pevOwner = VARS( pev->owner );
else
pevOwner = NULL;

pev->owner = NULL; // can't traceline attack owner if this is set

RadiusDamage ( pev, pevOwner, pev->dmg, CLASS_NONE, bitsDamageType );

if ( RANDOM_FLOAT( 0 , 1 ) < 0.5 )
{
UTIL_DecalTrace( pTrace, DECAL_SCORCH1 );
}
else
{
UTIL_DecalTrace( pTrace, DECAL_SCORCH2 );
}

flRndSound = RANDOM_FLOAT( 0 , 1 );

switch ( RANDOM_LONG( 0, 2 ) )
{
case 0: EMIT_SOUND(ENT(pev), CHAN_VOICE, "weapons/debris1.wav", 0.55, ATTN_NORM); break;
case 1: EMIT_SOUND(ENT(pev), CHAN_VOICE, "weapons/debris2.wav", 0.55, ATTN_NORM); break;
case 2: EMIT_SOUND(ENT(pev), CHAN_VOICE, "weapons/debris3.wav", 0.55, ATTN_NORM); break;
}

pev->effects |= EF_NODRAW;
SetThink(&CGrenade:: Smoke );
pev->velocity = g_vecZero;
SetNextThink( 0.3 );

if (iContents != CONTENTS_WATER)
{
int sparkCount = RANDOM_LONG(0,3);
for ( int i = 0; i < sparkCount; i++ )
Create( "spark_shower", pev->origin, pTrace->vecPlaneNormal, NULL );
}
}

void CGrenade::Smoke( void )
{
if (UTIL_PointContents ( pev->origin ) == CONTENTS_WATER)
{
UTIL_Bubbles( pev->origin - Vector( 64, 64, 64 ), pev->origin + Vector( 64, 64, 64 ), 100 );
}
else
{
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, pev->origin );
WRITE_BYTE( TE_SMOKE );
WRITE_COORD( pev->origin.x );
WRITE_COORD( pev->origin.y );
WRITE_COORD( pev->origin.z );
WRITE_SHORT( g_sModelIndexSmoke );
WRITE_BYTE( (pev->dmg - 50) * 0.80 ); // scale * 10
WRITE_BYTE( 12 ); // framerate
MESSAGE_END();
}
UTIL_Remove( this );
}

void CGrenade::Killed( entvars_t *pevAttacker, int iGib )
{
Detonate( );
}

// Timed grenade, this think is called when time runs out.
void CGrenade::DetonateUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
SetThink(&CGrenade:: Detonate );
SetNextThink( 0 );
}

void CGrenade::PreDetonate( void )
{
CSoundEnt::InsertSound ( bits_SOUND_DANGER, pev->origin, 400, 0.3 );

SetThink(&CGrenade:: Detonate );
SetNextThink( 1 );
}

void CGrenade::Detonate( void )
{
TraceResult tr;
Vector vecSpot;// trace starts here!

vecSpot = pev->origin + Vector ( 0 , 0 , 8 );
UTIL_TraceLine ( vecSpot, vecSpot + Vector ( 0, 0, -40 ), ignore_monsters, ENT(pev), & tr);

Explode( &tr, DMG_BLAST );
}

//
// Contact grenade, explode when it touches something
//
void CGrenade::ExplodeTouch( CBaseEntity *pOther )
{
TraceResult tr;
Vector vecSpot;// trace starts here!

pev->enemy = pOther->edict();

vecSpot = pev->origin - pev->velocity.Normalize() * 32;
UTIL_TraceLine( vecSpot, vecSpot + pev->velocity.Normalize() * 64, ignore_monsters, ENT(pev), &tr );

Explode( &tr, DMG_BLAST );
}

void CGrenade::DangerSoundThink( void )
{
if (!IsInWorld())
{
UTIL_Remove( this );
return;
}

CSoundEnt::InsertSound ( bits_SOUND_DANGER, pev->origin + pev->velocity * 0.5, pev->velocity.Length( ), 0.2 );
SetNextThink( 0.2 );

if (pev->waterlevel != 0 && pev->watertype > CONTENT_FLYFIELD)
{
pev->velocity = pev->velocity * 0.5;
}
}

void CGrenade::BounceTouch( CBaseEntity *pOther )
{
// don't hit the guy that launched this grenade
if ( pOther->edict() == pev->owner )
return;

// only do damage if we're moving fairly fast
if (m_flNextAttack < gpGlobals->time && pev->velocity.Length() > 100)
{
entvars_t *pevOwner = VARS( pev->owner );
if (pevOwner)
{
TraceResult tr = UTIL_GetGlobalTrace( );
ClearMultiDamage( );
pOther->TraceAttack(pevOwner, 1, gpGlobals->v_forward, &tr, DMG_CLUB );
ApplyMultiDamage( pev, pevOwner);
}
m_flNextAttack = gpGlobals->time + 1.0; // debounce
}

Vector vecTestVelocity;
// pev->avelocity = Vector (300, 300, 300);

// this is my heuristic for modulating the grenade velocity because grenades dropped purely vertical
// or thrown very far tend to slow down too quickly for me to always catch just by testing velocity.
// trimming the Z velocity a bit seems to help quite a bit.
vecTestVelocity = pev->velocity;
vecTestVelocity.z *= 0.45;

if ( !m_fRegisteredSound && vecTestVelocity.Length() <= 60 )
{
//ALERT( at_console, "Grenade Registered!: %f\n", vecTestVelocity.Length() );

// grenade is moving really slow. It's probably very close to where it will ultimately stop moving.
// go ahead and emit the danger sound.

// register a radius louder than the explosion, so we make sure everyone gets out of the way
CSoundEnt::InsertSound ( bits_SOUND_DANGER, pev->origin, pev->dmg / 0.4, 0.3 );
m_fRegisteredSound = TRUE;
}

if (pev->flags & FL_ONGROUND)
{
// add a bit of static friction
pev->velocity = pev->velocity * 0.8;

pev->sequence = RANDOM_LONG( 1, 1 );
}
else
{
// play bounce sound
BounceSound();
}
pev->framerate = pev->velocity.Length() / 200.0;
if (pev->framerate > 1.0)
pev->framerate = 1;
else if (pev->framerate < 0.5)
pev->framerate = 0;

}

void CGrenade::SlideTouch( CBaseEntity *pOther )
{
// don't hit the guy that launched this grenade
if ( pOther->edict() == pev->owner )
return;

// pev->avelocity = Vector (300, 300, 300);

if (pev->flags & FL_ONGROUND)
{
// add a bit of static friction
pev->velocity = pev->velocity * 0.95;

if (pev->velocity.x != 0 || pev->velocity.y != 0)
{
// maintain sliding sound
}
}
else
{
BounceSound();
}
}

void CGrenade :: BounceSound( void )
{
switch ( RANDOM_LONG( 0, 2 ) )
{
case 0: EMIT_SOUND(ENT(pev), CHAN_VOICE, "weapons/grenade_hit1.wav", 0.25, ATTN_NORM); break;
case 1: EMIT_SOUND(ENT(pev), CHAN_VOICE, "weapons/grenade_hit2.wav", 0.25, ATTN_NORM); break;
case 2: EMIT_SOUND(ENT(pev), CHAN_VOICE, "weapons/grenade_hit3.wav", 0.25, ATTN_NORM); break;
}
}

void CGrenade :: TumbleThink( void )
{
if (!IsInWorld())
{
UTIL_Remove( this );
return;
}

StudioFrameAdvance( );
SetNextThink( 0.1 );

if (pev->dmgtime - 1 < gpGlobals->time)
{
CS
Re: grenade laser trail Posted by Gwil on Fri Jun 27th 2008 at 1:46pm
Gwil
2864 posts
Posted 2008-06-27 1:46pm
Gwil
super admin
2864 posts 315 snarkmarks Registered: Oct 13th 2001 Occupation: Student Location: Derbyshire, UK
Might be better looking on a dedicated C++ forum, there's literally a handful of people around here doing C++ and I think most of them are learning the ways as they go along just like you.
Re: grenade laser trail Posted by Crollo on Fri Jun 27th 2008 at 7:01pm
Crollo
148 posts
Posted 2008-06-27 7:01pm
Crollo
member
148 posts 15 snarkmarks Registered: May 8th 2008 Location: Canada
actually, i was using the wrong code, i was using ggrenade, instead of handgrenade :razz: sorry.