Raised This Month: $51 Target: $400
 12% 

Creating beams with entity endpoints


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mukunda
Member
Join Date: Sep 2012
Old 03-23-2014 , 13:29   Creating beams with entity endpoints
Reply With Quote #1

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;
__________________
mukunda is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 03-25-2014 , 10:23   Re: Creating beams with entity endpoints
Reply With Quote #2

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
}; 
__________________
Peace-Maker is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 03-25-2014 , 10:51   Re: Creating beams with entity endpoints
Reply With Quote #3

very interesting, will probably use it!
Mitchell is offline
joshtrav
Senior Member
Join Date: Sep 2009
Old 01-04-2015 , 03:16   Re: Creating beams with entity endpoints
Reply With Quote #4

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.
__________________

joshtrav is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 01-04-2015 , 03:54   Re: Creating beams with entity endpoints
Reply With Quote #5

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.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
joshtrav
Senior Member
Join Date: Sep 2009
Old 01-04-2015 , 13:47   Re: Creating beams with entity endpoints
Reply With Quote #6

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.
__________________

joshtrav is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:31.


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