This is not obvious at all, so here's what you do:
Create an env_beam and fill out your basic parameters.
To hook it to entities you need to:
set SendProp "m_hAttachEntity"[0] to the source entity (the beam itself, or another entity)
set SendProp "m_hAttachEntity"[1] to the target entity
ie:
Code:
SetEntPropEnt( beam, Prop_Send, "m_hAttachEntity", EntIndexToEntRef(tar), 1 );
I don't know if EntIndexToEntRef is required, but it seemed like that's what it prefers from looking at the engine code.
set SendProp "m_nNumBeamEnts" to 2
set SendProp "m_nBeamType" to 2 // the magic is here, this is "BEAM_ENTS" which tells it to use the entity endpoint mode, this is NOT set automatically unlike creating a beam in hammer
Full test snippet:
Code:
#define MODEL2 "sprites/laserbeam.vmt"
PrecacheModel(MODEL2);
decl Float:pos[3];
decl Float:dir[3];
GetClientEyePosition( client, pos );
GetClientEyeAngles(client, dir );
GetAngleVectors( dir, dir, NULL_VECTOR, NULL_VECTOR );
decl Float:start[3];
decl Float:end[3];
for( new i = 0; i < 3; i++ ) {
start[i] = pos[i] + dir[i] * 100.0;
end[i] = pos[i] + dir[i] * 200.0;
}
new tar = CreateEntityByName("env_sprite");
SetEntityModel( tar, MODEL2 );
DispatchKeyValue( tar, "renderamt", "255" );
DispatchKeyValue( tar, "rendercolor", "255 255 255" );
DispatchSpawn( tar );
AcceptEntityInput(tar,"ShowSprite");
ActivateEntity(tar);
TeleportEntity( tar, end, NULL_VECTOR, NULL_VECTOR );
new beam = CreateEntityByName( "env_beam" );
SetEntityModel( beam, MODEL2 );
DispatchKeyValue( beam, "renderamt", "100" );
DispatchKeyValue( beam, "rendermode", "0" );
DispatchKeyValue( beam, "rendercolor", "255 255 255" );
DispatchKeyValue( beam, "life", "0" );
TeleportEntity( beam, start, NULL_VECTOR, NULL_VECTOR );
DispatchSpawn(beam);
SetEntPropEnt( beam, Prop_Send, "m_hAttachEntity", EntIndexToEntRef(beam) );
SetEntPropEnt( beam, Prop_Send, "m_hAttachEntity", EntIndexToEntRef(tar), 1 );
SetEntProp( beam, Prop_Send, "m_nNumBeamEnts", 2);
SetEntProp( beam, Prop_Send, "m_nBeamType", 2);
SetEntPropFloat( beam, Prop_Data, "m_fWidth", 10.0 );
SetEntPropFloat( beam, Prop_Data, "m_fEndWidth", 1.0 );
AcceptEntityInput(beam,"TurnOn");
return Plugin_Handled;
__________________