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

[INC] Beam Entities


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KORD_12.7
Senior Member
Join Date: Aug 2009
Location: Russia, Vladivostok
Old 05-09-2012 , 00:20   [INC] Beam Entities
Reply With Quote #1

[INC] Beam Entities [AGHL.ru link]
version 1.3
by KORD_12.7

Description:
Quote:
Originally Posted by HLSDK
These functions are here to show the way beams are encoded as entities. Encoding beams as entities simplifies their management in the client/server architecture.
Credits:
  • HLSDK - effects.cpp & effects.h
INC:
PHP Code:
/* AMX Mod X
*    Beam entities include by KORD_12.7.
*
* Version 1.3 (last update: 4, may (05), 2013)
*
* http://aghl.ru/forum/ - Russian Half-Life and Adrenaline Gamer Community
*
* This file is provided as is (no warranties)
*/

#if defined _beams_included
    #endinput
#endif
#define _beams_included

#include <engine>
#include <fakemeta>
#include <xs>


// These functions are here to show the way beams are encoded as entities.
// Encoding beams as entities simplifies their management in the client/server architecture.


// Beam types
enum _:Beam_Types
{
    
BEAM_POINTS,
    
BEAM_ENTPOINT,
    
BEAM_ENTS,
    
BEAM_HOSE
};

// Beam flags
#define BEAM_FSINE    0x10
#define BEAM_FSOLID    0x20
#define BEAM_FSHADEIN    0x40
#define BEAM_FSHADEOUT    0x80


#define Beam_SetType(%0,%1) set_pev(%0, pev_rendermode, (pev(%0, pev_rendermode) & 0xF0) | %1 & 0x0F)
/* stock Beam_SetType(const iBeamEntity, const iType)
    return set_pev(iBeamEntity, pev_rendermode, (pev(iBeamEntity, pev_rendermode) & 0xF0) | iType & 0x0F); */
    
#define Beam_SetFlags(%0,%1) set_pev(%0, pev_rendermode, (pev(%0, pev_rendermode) & 0x0F) | %1 & 0xF0)
/* stock Beam_SetFlags(const iBeamEntity, const iType)
    return set_pev(iBeamEntity, pev_rendermode, (pev(iBeamEntity, pev_rendermode) & 0x0F) | iType & 0xF0); */    

#define Beam_SetStartPos(%0,%1) set_pev(%0, pev_origin, %1)
/* stock Beam_SetStartPos(const iBeamEntity, const Float: flVecStart[3])
    return set_pev(iBeamEntity, pev_origin, flVecStart); */

#define Beam_SetEndPos(%0,%1) set_pev(%0, pev_angles, %1)
/* stock Beam_SetEndPos(const iBeamEntity, const Float: flVecEnd[3]) 
    return set_pev(iBeamEntity, pev_angles, flVecEnd); */

#define Beam_SetStartEntity(%0,%1) \
    
set_pev(%0pev_sequence, (%0x0FFF) | ((pev(%0pev_sequence) & 0xF000) << 12)); \
    
set_pev(%0pev_owner, %1) \
/* stock Beam_SetStartEntity(const iBeamEntity, const iEntityIndex) */

#define Beam_SetEndEntity(%0,%1) \
    
set_pev(%0pev_skin, (%0x0FFF) | ((pev(%0pev_skin) & 0xF000) << 12)); \
    
set_pev(%0pev_aiment, %1) \
/* stock Beam_SetEndEntity(const iBeamEntity, const iEntityIndex) */

#define Beam_SetStartAttachment(%0,%1) set_pev(%0, pev_sequence, (pev(%0, pev_sequence) & 0x0FFF) | ((%1 & 0xF) << 12))
/* stock Beam_SetStartAttachment(const iBeamEntity, const iAttachment)
    return set_pev(iBeamEntity, pev_sequence, (pev(iBeamEntity, pev_sequence) & 0x0FFF) | ((iAttachment & 0xF) << 12)); */

#define Beam_SetEndAttachment(%0,%1) set_pev(%0, pev_skin, (pev(%0, pev_skin) & 0x0FFF) | ((%1 & 0xF) << 12))
/* stock Beam_SetEndAttachment(const iBeamEntity, const iAttachment)
    return set_pev(iBeamEntity, pev_skin, (pev(iBeamEntity, pev_skin) & 0x0FFF) | ((iAttachment & 0xF) << 12)); */

#define Beam_SetTexture(%0,%1) set_pev(%0, pev_modelindex, %1)
/* stock Beam_SetTexture(const iBeamEntity, const iSpriteIndex)
    return set_pev(iBeamEntity, pev_modelindex, iSpriteIndex); */

#define Beam_SetWidth(%0,%1) set_pev(%0, pev_scale, %1)
/* stock Beam_SetWidth(const iBeamEntity, const Float: flWidth)
    return set_pev(iBeamEntity, pev_scale, flWidth); */

#define Beam_SetNoise(%0,%1) set_pev(%0, pev_body, %1)
/* stock Beam_SetNoise(const iBeamEntity, const iNoise)
    return set_pev(iBeamEntity, pev_body, iNoise); */    
    
#define Beam_SetColor(%0,%1) set_pev(%0, pev_rendercolor, %1)
/* stock Beam_SetColor(const iBeamEntity, const Float: flColor[3])
    return set_pev(iBeamEntity, pev_rendercolor, flColor); */    
        
#define Beam_SetBrightness(%0,%1) set_pev(%0, pev_renderamt, %1)
/* stock Beam_SetBrightness(const iBeamEntity, const Float: flBrightness)
    return set_pev(iBeamEntity, pev_renderamt, flBrightness); */

#define Beam_SetFrame(%0,%1) set_pev(%0, pev_frame, %1)
/* stock Beam_SetFrame(const iBeamEntity, const Float: flFrame)
    return set_pev(iBeamEntity, pev_frame, flFrame); */

#define Beam_SetScrollRate(%0,%1) set_pev(%0, pev_animtime, %1)
/* stock Beam_SetScrollRate(const iBeamEntity, const Float: flSpeed)
    return set_pev(iBeamEntity, pev_animtime, flSpeed); */

#define Beam_GetType(%0) (pev(%0, pev_rendermode) & 0x0F)
/* stock Beam_GetType(const iBeamEntity)
    return pev(iBeamEntity, pev_rendermode) & 0x0F; */
    
#define Beam_GetFlags(%0) (pev(%0, pev_rendermode) & 0xF0)
/* stock Beam_GetFlags(const iBeamEntity)
    return pev(iBeamEntity, pev_rendermode) & 0xF0; */    

#define Beam_GetStartEntity(%0) (pev(%0, pev_sequence) & 0xFFF)
/* stock Beam_GetStartEntity(const iBeamEntity)
    return pev(iBeamEntity, pev_sequence) & 0xFFF; */

#define Beam_GetEndEntity(%0) (pev(%0, pev_skin) & 0xFFF)
/* stock Beam_GetEndEntity(const iBeamEntity)
    return pev(iBeamEntity, pev_skin) & 0xFFF; */

stock Beam_GetStartPos(const iBeamEntityFloatvecStartPos[3])
{
    static 
iEntityiEntity Beam_GetStartEntity(iBeamEntity);
    
    if (
Beam_GetType(iBeamEntity) == BEAM_ENTS && pev_valid(iEntity))
    {
        
pev(iEntitypev_originvecStartPos);
        return;
    }
    
    
pev(iBeamEntitypev_originvecStartPos);
}

stock Beam_GetEndPos(const iBeamEntityFloatvecEndPos[3])
{
    static 
iType
    static 
iEntity;
    
    
iType Beam_GetType(iBeamEntity);
    
    if (
iType == BEAM_POINTS || iType == BEAM_HOSE)
    {
        
pev(iBeamEntitypev_anglesvecEndPos);
        return;
    }
    
    
iEntity Beam_GetEndEntity(iBeamEntity);
    
    if (
pev_valid(iEntity))
    {
        
pev(iEntitypev_originvecEndPos);
        return;
    }
    
    
pev(iBeamEntitypev_anglesvecEndPos);
}

#define Beam_GetTexture(%0) pev(%0, pev_modelindex)
/* stock Beam_GetTexture(const iBeamEntity)
    return pev(iBeamEntity, pev_modelindex); */
    
#define Beam_GetWidth(%0) entity_get_float(%0, EV_FL_scale)
/* stock Float: Beam_GetWidth(const iBeamEntity)
    return entity_get_float(iBeamEntity, EV_FL_scale); */

#define Beam_GetNoise(%0) pev(%0, pev_body)
/* stock Beam_GetNoise(const iBeamEntity)
    return pev(iBeamEntity, pev_body); */
    
#define Beam_GetColor(%0,%1) pev(%0, pev_rendercolor,%1)
/* stock Beam_GetColor(const iBeamEntity, Float: flRGB[3])
    return pev(iBeamEntity, pev_rendercolor, flRGB); */

#define Beam_GetBrightness(%0) entity_get_float(%0, EV_FL_renderamt)
/* stock Float: Beam_GetBrightness(const iBeamEntity)
    return entity_get_float(iBeamEntity, EV_FL_renderamt); */
    
#define Beam_GetFrame(%0) entity_get_float(%0, EV_FL_frame)
/* stock Float: Beam_GetFrame(const iBeamEntity)
    return entity_get_float(iBeamEntity, EV_FL_frame); */

#define Beam_GetScrollRate(%0) entity_get_float(%0, EV_FL_animtime)
/* stock Float: Beam_GetScrollRate(const iBeamEntity)
    return entity_get_float(iBeamEntity, EV_FL_animtime); */

stock Beam_Create(const szSpriteName[], const FloatflWidth)
{
    static 
iBeamEntityiszAllocStringCached;
    if (
iszAllocStringCached || (iszAllocStringCached engfunc(EngFunc_AllocString"beam")))
    {
        
iBeamEntity engfunc(EngFunc_CreateNamedEntityiszAllocStringCached);
    }
    
    if (!
pev_valid(iBeamEntity))
    {
        return 
FM_NULLENT;
    }
    
    
Beam_Init(iBeamEntityszSpriteNameflWidth);
    return 
iBeamEntity;
}

stock Beam_Init(const iBeamEntity, const szSpriteName[], const FloatflWidth)
{
    
set_pev(iBeamEntitypev_flagspev(iBeamEntitypev_flags) | FL_CUSTOMENTITY);
    
    
Beam_SetColor(iBeamEntityFloat: {255.0255.0255.0});
    
Beam_SetBrightness(iBeamEntity255.0);
    
Beam_SetNoise(iBeamEntity0);
    
Beam_SetFrame(iBeamEntity0.0);
    
Beam_SetScrollRate(iBeamEntity0.0);
    
Beam_SetWidth(iBeamEntityflWidth);
    
    
engfunc(EngFunc_SetModeliBeamEntityszSpriteName);
    
    
set_pev(iBeamEntitypev_skin0);
    
set_pev(iBeamEntitypev_sequence0);
    
set_pev(iBeamEntitypev_rendermode0);
}

stock Beam_PointsInit(const iBeamEntity, const FloatflVecStart[3], const FloatflVecEnd[3])
{
    
Beam_SetType(iBeamEntityBEAM_POINTS);
    
Beam_SetStartPos(iBeamEntityflVecStart);
    
Beam_SetEndPos(iBeamEntityflVecEnd);
    
Beam_SetStartAttachment(iBeamEntity0);
    
Beam_SetEndAttachment(iBeamEntity0);
    
Beam_RelinkBeam(iBeamEntity);
}

stock Beam_HoseInit(const iBeamEntity, const FloatflVecStart[3], const FloatflVecDirection[3])
{
    
Beam_SetType(iBeamEntityBEAM_HOSE);
    
Beam_SetStartPos(iBeamEntityflVecStart);
    
Beam_SetEndPos(iBeamEntityflVecDirection);
    
Beam_SetStartAttachment(iBeamEntity0);
    
Beam_SetEndAttachment(iBeamEntity0);
    
Beam_RelinkBeam(iBeamEntity);
}

stock Beam_PointEntInit(const iBeamEntity, const FloatflVecStart[3], const iEndIndex)
{
    
Beam_SetType(iBeamEntityBEAM_ENTPOINT);
    
Beam_SetStartPos(iBeamEntityflVecStart);
    
Beam_SetEndEntity(iBeamEntityiEndIndex);
    
Beam_SetStartAttachment(iBeamEntity0);
    
Beam_SetEndAttachment(iBeamEntity0);
    
Beam_RelinkBeam(iBeamEntity);
}

stock Beam_EntsInit(const iBeamEntity, const iStartIndex, const iEndIndex)
{
    
Beam_SetType(iBeamEntityBEAM_ENTS);
    
Beam_SetStartEntity(iBeamEntityiStartIndex);
    
Beam_SetEndEntity(iBeamEntityiEndIndex);
    
Beam_SetStartAttachment(iBeamEntity0);
    
Beam_SetEndAttachment(iBeamEntity0);
    
Beam_RelinkBeam(iBeamEntity);
}

stock Beam_RelinkBeam(const iBeamEntity)
{
    static 
FloatvecMins[3];
    static 
FloatvecMaxs[3];
    
    static 
FloatvecOrigin[3];
    static 
FloatvecEndPos[3];
    static 
FloatvecStartPos[3];
    
    
pev(iBeamEntitypev_originvecOrigin);
    
    
Beam_GetStartPos(iBeamEntityvecStartPos);
    
Beam_GetEndPos(iBeamEntityvecEndPos);
    
    
vecMins[0] = floatmin(vecStartPos[0], vecEndPos[0]);
    
vecMins[1] = floatmin(vecStartPos[1], vecEndPos[1]);
    
vecMins[2] = floatmin(vecStartPos[2], vecEndPos[2]);
    
    
vecMaxs[0] = floatmax(vecStartPos[0], vecEndPos[0]);
    
vecMaxs[1] = floatmax(vecStartPos[1], vecEndPos[1]);
    
vecMaxs[2] = floatmax(vecStartPos[2], vecEndPos[2]);
    
    
xs_vec_sub(vecMinsvecOriginvecMins);
    
xs_vec_sub(vecMaxsvecOriginvecMaxs);
    
    
set_pev(iBeamEntitypev_minsvecMins);
    
set_pev(iBeamEntitypev_maxsvecMaxs);
    
    
engfunc(EngFunc_SetSizeiBeamEntityvecMinsvecMaxs);
    
engfunc(EngFunc_SetOriginiBeamEntityvecOrigin);

TO DO:
Add some code examples with creating beam ents
Attached Files
File Type: inc beams.inc (9.8 KB, 2338 views)
__________________

Vi Veri Veniversum Vivus Vici
Russian Half-Life and Adrenaline Gamer community

Last edited by KORD_12.7; 05-04-2013 at 01:41.
KORD_12.7 is offline
Send a message via ICQ to KORD_12.7
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 05-09-2012 , 13:44   Re: [INC] Beam Entities
Reply With Quote #2

Very cool, good job. I didn't know you could create beams as entities.

Can you explain what a BEAM_HOSE is?

Are you able to use this method to create other types of beam messages? (ie. TE_BEAMSPRITE, TE_BEAMTORUS, TE_BEAMDISK, TE_BEAMCYLINDER, TE_BEAMFOLLOW, and TE_BEAMRING)

I assume using this is equivalent to doing MSG_BROADCAST, is there a way to show only to a single player?

One thing I think you should change is letting iSpriteIndex be optional in Beam_Create and Beam_Init; you should be able to find the index for the sprite if you have the name (or vice versa).

You should also try to put a little more documentation for each macro/function to make it easier to understand for beginners.

Overall good job though; I'm sure I will end up using this some day.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-09-2012 , 14:32   Re: [INC] Beam Entities
Reply With Quote #3

Quote:
I didn't know you could create beams as entities
Never heard of env_laser/env_beam/beam entities ?

Quote:
Can you explain what a BEAM_HOSE is
BEAM_HOSE is the same as BEAM_POINTS, except your provide a direction instead of an end point.

Quote:
Are you able to use this method to create other types of beam messages?
No. It's specific. Though you can try to reproduce the same effect.

Quote:
I assume using this is equivalent to doing MSG_BROADCAST, is there a way to show only to a single player?
Like any others entities, if you want to filter, I guess you have to use AddToFullPack.
__________________
Arkshine is offline
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 05-10-2012 , 00:20   Re: [INC] Beam Entities
Reply With Quote #4

about the entity, I suggest you to see the "halflife-cs.fgd"
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
KORD_12.7
Senior Member
Join Date: Aug 2009
Location: Russia, Vladivostok
Old 06-11-2012 , 06:53   Re: [INC] Beam Entities
Reply With Quote #5

Updated.
__________________

Vi Veri Veniversum Vivus Vici
Russian Half-Life and Adrenaline Gamer community
KORD_12.7 is offline
Send a message via ICQ to KORD_12.7
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-11-2012 , 06:56   Re: [INC] Beam Entities
Reply With Quote #6

You should say what are the changes.
__________________
Arkshine is offline
KORD_12.7
Senior Member
Join Date: Aug 2009
Location: Russia, Vladivostok
Old 06-11-2012 , 07:57   Re: [INC] Beam Entities
Reply With Quote #7

Removed iSpriteIndex argument in Beam_Create and Beam_Init stocks.
__________________

Vi Veri Veniversum Vivus Vici
Russian Half-Life and Adrenaline Gamer community
KORD_12.7 is offline
Send a message via ICQ to KORD_12.7
LARP
Senior Member
Join Date: Aug 2008
Location: Santiago, Chile
Old 06-25-2012 , 19:03   Re: [INC] Beam Entities
Reply With Quote #8

Are you able to create a sample plugin with INC, please?

Thanks
__________________
------

LARP is offline
Merciless
BANNED
Join Date: Aug 2009
Location: Belgium
Old 08-11-2012 , 16:04   Re: [INC] Beam Entities
Reply With Quote #9

Hello;

Using this shizzle for a new mod of me.
Pretty hard to use without examples anyway;

I think you forgot to include <xs>, bcs I had errors when I compiled.

[Edit]
- Used first time, and worked.
- This is awesome, thanks!

[Edit #2]
- Is it possible to detect touch?

Last edited by Merciless; 08-11-2012 at 16:50.
Merciless is offline
Merciless
BANNED
Join Date: Aug 2009
Location: Belgium
Old 08-12-2012 , 17:57   Re: [INC] Beam Entities
Reply With Quote #10

Touch works here now,

but after testing, and I move sometimes..
at a time the line doesnt come anymore, it says an entity number.. but nothing shows

arround entitynumber 90

How to solve this?

Last edited by Merciless; 08-12-2012 at 17:59.
Merciless is offline
Reply


Thread Tools
Display Modes

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 11:24.


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