AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   Creating beams with entity endpoints (https://forums.alliedmods.net/showthread.php?t=237402)

mukunda 03-23-2014 13:29

Creating beams with entity endpoints
 
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;


Peace-Maker 03-25-2014 10:23

Re: Creating beams with entity endpoints
 
This is awesome! Thanks for sharing.

I'd use the enum instead of hardcoding 2.
PHP Code:

// Beam types, encoded as a byte
enum 
{
    
BEAM_POINTS 0,
    
BEAM_ENTPOINT,
    
BEAM_ENTS,
    
BEAM_HOSE,
    
BEAM_SPLINE,
    
BEAM_LASER,
    
NUM_BEAM_TYPES
}; 


Mitchell 03-25-2014 10:51

Re: Creating beams with entity endpoints
 
very interesting, will probably use it!

joshtrav 01-04-2015 03:16

Re: Creating beams with entity endpoints
 
I release this is rather old but has anyone successfully created a beam that uses the ring flags per the wiki? It says there that it doesn't seem to work, but I see this post: https://forums.alliedmods.net/showthread.php?t=221153, which describes using a ring. However, even when I do exactly the code as per that post I get a straight line.

friagram 01-04-2015 03:54

Re: Creating beams with entity endpoints
 
I have used info targets with env_beams int the past. The touch hooks don't work right unless you toggle the beam off/on after moving the endpoints iirc, which is quite annoying. Other than that, it works OK.

I think lduke's tripmines works off of this same idea.

joshtrav 01-04-2015 13:47

Re: Creating beams with entity endpoints
 
I can create a standard beam.

I shifted it to info_targets and parented one to forward and the other lfoot. However, it still just draws a line, even with spawnflags set to 8. I also tried setting beamflags.

I read that they need to be brush entities for the ring to work here: https://developer.valvesoftware.com/wiki/Talk:Env_beam

But I am not entirely sure how to make brush entities with SM. I did some searching and found a tutorial but its a bit beyond what I have the time for today. I will try more later.


All times are GMT -4. The time now is 23:21.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.