PDA

View Full Version : env_beam does not "appear"



Julcoool
09-04-2016, 07:37 PM
CBaseEntity@ raylight_START = g_EntityFuncs.Create( "info_target", origin1, pAngles, false, pPlayer.edict() );

raylight_START.pev.targetname = string_t( "beam_start" );

CBaseEntity@ raylight_END = g_EntityFuncs.Create( "info_target", origin2, pAngles, false, pPlayer.edict() );

raylight_END.pev.targetname = string_t( "beam_end" );


After I put those info_targets, I tried to create a beam with this method:



CBeam@ raylight_BEAM = g_EntityFuncs.CreateBeam( "sprites/laserbeam.spr", 8 );
raylight_BEAM.SetType( BEAM_ENTS );
raylight_BEAM.SetFlags( SF_BEAM_STARTON );
raylight_BEAM.SetStartEntity( raylight_START );
raylight_BEAM.SetEndEntity( raylight_END );
raylight_BEAM.RelinkBeam();
raylight_BEAM.SetNoise( 2 );
raylight_BEAM.SetWidth( 8 );
raylight_BEAM.SetColor( 250, 250, 100 );
raylight_BEAM.SetBrightness( 200 );
raylight_BEAM.pev.targetname = string_t( "RayLight" );
g_EntityFuncs.DispatchSpawn( raylight_BEAM.edict() );


Or even, with this method:



CBaseEntity@ raylight_BEAM = g_EntityFuncs.Create( "env_beam", pOrigin, pAngles, true, pPlayer.edict() );
g_EntityFuncs.DispatchKeyValue( raylight_BEAM.edict(), "LightningStart", "beam_start" );
g_EntityFuncs.DispatchKeyValue( raylight_BEAM.edict(), "LightningEnd", "beam_end" );
g_EntityFuncs.DispatchKeyValue( raylight_BEAM.edict(), "renderamt", "200" );
g_EntityFuncs.DispatchKeyValue( raylight_BEAM.edict(), "rendercolor", "250 250 100" );
g_EntityFuncs.DispatchKeyValue( raylight_BEAM.edict(), "BoltWidth", "8" );
g_EntityFuncs.DispatchKeyValue( raylight_BEAM.edict(), "NoiseAmplitude", "2" );
g_EntityFuncs.DispatchKeyValue( raylight_BEAM.edict(), "texture", "sprites/laserbeam.spr" );
g_EntityFuncs.DispatchKeyValue( raylight_BEAM.edict(), "TextureScroll", "2" );
g_EntityFuncs.DispatchKeyValue( raylight_BEAM.edict(), "spawnflags", "1" );
g_EntityFuncs.DispatchKeyValue( raylight_BEAM.edict(), "targetname", "RayLight" );
g_EntityFuncs.DispatchSpawn( raylight_BEAM.edict() );


But regardless of how I try to create the beam, the beam itself just won't appear. The entity seems to be created, but nothing happens.
What's wrong?

Solokiller
09-04-2016, 07:58 PM
The first method you used is correct, but you did some things you shouldn't be doing. here's an example from the SDK:



m_pBeam[m_iBeams] = CBeam::BeamCreate( "sprites/lgtning.spr", 30 );
if (!m_pBeam[m_iBeams])
return;

m_pBeam[m_iBeams]->PointEntInit( tr.vecEndPos, entindex( ) );
m_pBeam[m_iBeams]->SetEndAttachment( side < 0 ? 2 : 1 );
m_pBeam[m_iBeams]->SetColor( 96, 128, 16 );
m_pBeam[m_iBeams]->SetBrightness( 64 );
m_pBeam[m_iBeams]->SetNoise( 80 );


This code is used to create a beam for the Alien Slave's attacks.

You shouldn't call Spawn on the beam. This will change some settings that will likely make it invisible.

Julcoool
09-04-2016, 09:23 PM
Still unable to get it right.



CClientCommand Test_Beam( "do_beam", "placeholder", @Test_Beam_CB );
void Test_Beam_CB( const CCommand@ pArgs )
{
CBasePlayer@ pPlayer = g_ConCommandSystem.GetCurrentPlayer();

Vector pOrigin = pPlayer.pev.origin;
Vector pAngles = pPlayer.pev.v_angle;
g_EngineFuncs.MakeVectors( pAngles );
Vector pForward = g_Engine.v_forward;

Vector pStart;
Vector pEnd;

VectorMA( pOrigin, 16.0, pForward, pStart );
VectorMA( pOrigin, 256.0, pForward, pEnd );

CBaseEntity@ raylight_START = g_EntityFuncs.Create( "info_target", pStart, g_vecZero, false, pPlayer.edict() );
CBaseEntity@ raylight_END = g_EntityFuncs.Create( "info_target", pEnd, g_vecZero, false, pPlayer.edict() );

CBeam@ raylight_BEAM = g_EntityFuncs.CreateBeam( "sprites/laserbeam.spr", 30 );
raylight_BEAM.EntsInit( raylight_START, raylight_END );
raylight_BEAM.SetColor( 250, 250, 100 );
raylight_BEAM.SetBrightness( 200 );
raylight_BEAM.SetNoise( 2 );
raylight_BEAM.pev.targetname = string_t( "RayLight" );
}

void VectorMA( const Vector& in veca, float& in scale, const Vector& in vecb, Vector& out vecc )
{
vecc[ 0 ] = veca[ 0 ] + scale * vecb[ 0 ];
vecc[ 1 ] = veca[ 1 ] + scale * vecb[ 1 ];
vecc[ 2 ] = veca[ 2 ] + scale * vecb[ 2 ];
}


Something's missing...?

Solokiller
10-04-2016, 06:25 AM
I tried your code. If i replace EntsInit with PointsInit and pass in the coordinates, it works. I suspect this happens because you're using info_target, which is invisible. Since EntsInit creates beams between entity positions, and invisible entities are not networked, it's probably caused by this.

If i replace the entities with the torch and medic grunt, a beam is created between their feet.



void Test_Beam_CB( const CCommand@ pArgs )
{
CBasePlayer@ pPlayer = g_ConCommandSystem.GetCurrentPlayer();

Vector pOrigin = pPlayer.pev.origin;
Vector pAngles = pPlayer.pev.v_angle;
g_EngineFuncs.MakeVectors( pAngles );
Vector pForward = g_Engine.v_forward;

Vector pStart;
Vector pEnd;

VectorMA( pOrigin, 16.0, pForward, pStart );
VectorMA( pOrigin, 256.0, pForward, pEnd );

CBaseEntity@ raylight_START = g_EntityFuncs.FindEntityByClassname( null, "monster_human_torch_ally" ); //g_EntityFuncs.Create( "info_target", pStart, g_vecZero, false, pPlayer.edict() );
CBaseEntity@ raylight_END = g_EntityFuncs.FindEntityByClassname( null, "monster_human_medic_ally" ); //g_EntityFuncs.Create( "info_target", pEnd, g_vecZero, false, pPlayer.edict() );

CBeam@ raylight_BEAM = g_EntityFuncs.CreateBeam( "sprites/laserbeam.spr", 30 );
raylight_BEAM.EntsInit( raylight_START, raylight_END );
raylight_BEAM.SetColor( 250, 250, 100 );
raylight_BEAM.SetBrightness( 200 );
raylight_BEAM.SetNoise( 2 );
raylight_BEAM.pev.targetname = string_t( "RayLight" );
}


If you want to create beams between moving entities, you'll have to make them be networked to clients. This means making them visible. Setting a model on them - even if it's just an empty one - should do this.

Note that the EF_NODRAW effects flag must not be set either. If you want to be sure it's not set, do this:



pEntity.pev.effects &= ~EF_NODRAW;


The entity will still need to be in the player's visible area to be networked, but that should be taken care of automatically. Note that if the beam endpoints are far away from eachother, this might result in one entity having the correct origin, while another has an outdated one. You could end up with beams that appear in seemingly random positions in the world, and that pop into existence all of a sudden.

This is the same problem that happens with spore grenades, and it's not something that can be fixed on the server side, at least not without C++ level support to override visibility checks. If you are in need of that, you will have to ask a developer for this.

Julcoool
10-04-2016, 11:30 AM
Ohhh... that's why...

Thanks, it works now.