.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   Half-Life 2 SDK (http://forums.bots-united.com/forumdisplay.php?f=62)
-   -   draw beam (http://forums.bots-united.com/showthread.php?t=3315)

Cheeseh 01-01-2005 23:30

draw beam
 
okay I've been making a new bot template from botmans so far, I'm trying to do some waypoint stuff, just trying to wonder how to draw a waypoint.

I can't really include the beam stuff as I need to include lots of files that can't find lots of stuff.

I have:
Code:


void CWaypoint :: draw ( edict_t *pEdict )
{
        CTEBeamPoints *beam = new CTEBeamPoints();

        CEdictRecipient *filter = new CEdictRecipient(pEdict,false);

        engine->UserMessageBegin(filter,TE_BEAMPOINTS); // TE_BEAMPOINTS in here?? what about tempentity...?
        // are these in right order??
        WRITE_COORD(/*???*/) // ??? start and end points???
        WRITE_BYTE( m_nModelIndex ); //???
        WRITE_BYTE( m_nHaloIndex );
        WRITE_BYTE( m_nStartFrame );
        WRITE_BYTE( m_nFrameRate );
        WRITE_FLOAT( m_fLife );
        WRITE_FLOAT( m_fWidth );
        WRITE_FLOAT( m_fEndWidth );
        WRITE_BYTE( m_nFadeLength );
        WRITE_FLOAT( m_fAmplitude );
        WRITE_BYTE( r );
        WRITE_BYTE( g );
        WRITE_BYTE( b );
        WRITE_BYTE( a );
        WRITE_BYTE( m_nSpeed );
        WRITE_BYTE( m_nFlags );
        engine->MessageEnd();       

        delete filter;
}

I had to make a filter:
Code:

class CEdictRecipient : public IRecipientFilter
{
public:
        CEdictRecipient ( edict_t *pEdict, bool bReliable )
        {
                m_pEdict = pEdict;
                m_bReliable = bReliable;
        }

        // require destructor
        ~CEdictRecipient ()
        {
                m_pEdict = NULL;
                m_bReliable = false;
        }

        bool        IsReliable( void ) const { return m_bReliable; }

        bool        IsInitMessage( void ) const { return false; }

        int                GetRecipientCount( void ) const { return 1; }
        int                GetRecipientIndex( int slot ) const { return ENTINDEX(m_pEdict); } // only 1 stored
private:
        edict_t *m_pEdict;
        bool m_bReliable;
};

anyone found anything?

sfx1999 01-01-2005 23:51

Re: draw beam
 
Isn't there a beam entity?

Cheeseh 02-01-2005 00:08

Re: draw beam
 
aye but remember that this is a plugin, no access to lots of stuff, and when you try to include the beam code you get hundreds of errors and external errors because a lot of the stuff is non plugin related.

botman 02-01-2005 00:12

Re: draw beam
 
You might want to consider using NDebugOverlay stuff instead of beams. NDebugOverlay includes...
Code:

void Box(const Vector &origin, const Vector &mins, const Vector &maxs, int r, int g, int b, int a, float flDuration);
 void BoxDirection(const Vector &origin, const Vector &mins, const Vector &maxs, const Vector &forward, int r, int g, int b, int a, float flDuration);
 void BoxAngles(const Vector &origin, const Vector &mins, const Vector &maxs, const QAngle &angles, int r, int g, int b, int a, float flDuration);
 void SweptBox(const Vector& start, const Vector& end, const Vector& mins, const Vector& maxs, const QAngle & angles, int r, int g, int b, int a, float flDuration);
 void EntityBounds( const CBaseEntity *pEntity, int r, int g, int b, int a, float flDuration );
 void Line( const Vector &origin, const Vector &target, int r, int g, int b, bool noDepthTest, float flDuration );
 void Triangle( const Vector &p1, const Vector &p2, const Vector &p3, int r, int g, int b, int a, bool noDepthTest, float duration );
 void EntityText( int entityID, int text_offset, const char *text, float flDuration, int r = 255, int g = 255, int b = 255, int a = 255);
 void Grid( const Vector &vPosition );
 void Text( const Vector &origin, const char *text, bool bViewCheck, float flDuration );
 void ScreenText( float fXpos, float fYpos, const char *text, int r, int g, int b, int a, float flDuration);
 void Cross3D(const Vector &position, const Vector &mins, const Vector &maxs, int r, int g, int b, bool noDepthTest, float flDuration );
 void Cross3D(const Vector &position, float size, int r, int g, int b, bool noDepthTest, float flDuration );
 void Cross3DOriented( const Vector &position, const QAngle &angles, float size, int r, int g, int b, bool noDepthTest, float flDuration );
 void Cross3DOriented( const matrix3x4_t &m, float size, int c, bool noDepthTest, float flDuration );
 void DrawOverlayLines(void);
 void DrawTickMarkedLine(const Vector &startPos, const Vector &endPos, float tickDist, int tickTextDist, int r, int g, int b, bool noDepthTest, float flDuration );
 void DrawGroundCrossHairOverlay();
 void HorzArrow( const Vector &startPos, const Vector &endPos, float width, int r, int g, int b, int a, bool noDepthTest, float flDuration);
 void YawArrow( const Vector &startPos, float yaw, float length, float width, int r, int g, int b, int a, bool noDepthTest, float flDuration);
 void VertArrow( const Vector &startPos, const Vector &endPos, float width, int r, int g, int b, int a, bool noDepthTest, float flDuration);

See src\dlls\ndebugoverlay.cpp for details.

I'm not sure if/how NDebugOverlay would work from a plugin, but it seems like a much better system for drawing "debug" lines/boxes/text/etc in the game.

botman

Cheeseh 02-01-2005 00:15

Re: draw beam
 
thanks, yeah I've had a small look at that. There is a small thing though, there was a comment saying that is won't work on HL dedicated server (The interface would be NULL), meaning that clients wanting to make waypoints on a dedicated server might not be able to. I'll have a go at it anyway for now.

edit:

Actually I think the DebugOverlay stuff will ever only work for the local client, there is no input as to what player this should be sent to, even in the Line function it just picks the local player and works with it to determine what the local player can see to clip lines, but is not passed to the engine debugoverlay functions.

sfx1999 02-01-2005 05:08

Re: draw beam
 
Is there a network message you can send to trigger a beam on the client?

Cheeseh 02-01-2005 12:28

Re: draw beam
 
The only thing I know is I need to fire a TempEntity net message, with TE_BEAMPOINTS. But that needs access to a ServerClass() what ever that is, which means you really need the TE_BeamPoints class, but again when you try to include that it's a pian because it includes lots of non plugin stuff.

Cheeseh 02-01-2005 13:07

Re: draw beam
 
Actually I think I#ve got it, I think you've got to get the Server Effects Interface :

IEffects *g_pEffects = NULL;

..

g_pEffects = (IEffects* )interfaceFactory(IEFFECTS_INTERFACE_VERSION,NULL) ;

...

g_pEffects->Beam(..,..);

Haven't tried it yet though but it compiles okay

Edit:

Arrrrgh.. Okay the interfaceFactory returns NULL.. :@

Jerry 02-01-2005 14:04

Re: draw beam
 
Quote:

Originally Posted by Cheeseh
Actually I think I#ve got it, I think you've got to get the Server Effects Interface :

IEffects *g_pEffects = NULL;

..

g_pEffects = (IEffects* )interfaceFactory(IEFFECTS_INTERFACE_VERSION,NULL) ;

...

g_pEffects->Beam(..,..);

Haven't tried it yet though but it compiles okay

Edit:

Arrrrgh.. Okay the interfaceFactory returns NULL.. :@

Don't use interfaceFactory.
Use this instead:

Code:

effects = (IEffects*)gameServerFactory(IEFFECTS_INTERFACE_VERSION, NULL);

Cheeseh 02-01-2005 14:11

Re: draw beam
 
Thanks!

Cheeseh 02-01-2005 14:47

Re: draw beam
 
1 Attachment(s)
yay, here are some waypoints in the game, they're a bit small and fat.. still to work out the best size for them :)
thanks all

edit:

seems as though the origin from the "CollideOrigin" returns a vector on the players feet, thats why the waypoints were small, had to move them up from the origin.

again though this seems to only work with all players at once, no input entity. I really need to get the TempEntity interface, but doesn't seem like its possibile to get that.

Pierre-Marie Baty 02-01-2005 16:35

Re: draw beam
 
Superb! Once you guys find a clean way to do that, ------------> wikiwikiwiki plz :)

stefanhendriks 03-01-2005 14:44

Re: draw beam
 
You can get the player 'head' vector by using the Ear position, lemme search the correct line of code:

Code:

// position of ears (= eyes)
Vector UTIL_EarPosition( edict_t *pEdict )
{
        Vector *v = NULL;
 
        // Get vector
        gameclients->ClientEarPosition( pEdict, v );
 
        return *v;
}

it uses botmans template, so this *should* work.

THe only thing that still fails on me, is the code in the think function to get the first human players vector, as the plugin (and startframe code) runs while starting up the server, it crashes on init or something. As somehow the playerinfo or the other info from a client is not properly inited yet and i want to access it. Perhaps with a timer ;) But i have to do this later, i have no time now :D

botman 03-01-2005 15:19

Re: draw beam
 
In your server plugin, use LevelInit() and LevelShutdown() to set a global flag that indicates whether a map is running or not.

If the map hasn't been initialized yet, you can skip over everything you added in the GameFrame() function.

P.S. Note that in Half-Life2, plugins get loaded by the engine BEFORE the game actually starts running. You r plugin will be running while the Half-Life2 main menu is displayed (since the menu actually loads a small map as the "background" image).

botman

stefanhendriks 03-01-2005 16:26

Re: draw beam
 
ah, thanks for the tip botman, that will make it easier then using an ugly timer.

stefanhendriks 03-01-2005 16:57

Re: draw beam
 
i tried it, but i still needed a timer to prevent it from crashing.

EDIT:
Correction, somehow the code crashed somewhere else, though the debugger in MSVC pointed to this line where you call the engine function. But, i did not really trust it, so i did not use my own function to return this vector, but using the engine function itself. It works flawlessley, yeey, i hate timers ;)

Cheeseh 03-01-2005 17:20

Re: draw beam
 
It would be good to get the player Max's and min's, simply set up the waypoint size to be the player size at the time of creation (e.g. when crouched the size will be smaller so we can find the right size from it, sort of...)

Or does (CollideOrigin + EarPosition)/2 = center origin ??

Cheeseh 05-01-2005 16:04

Re: draw beam
 
heres how to get the very centre origin of any entity

Code:

Vector entityOrigin ( edict_t *pEntity )
{
        static float *fOrigin;
       
        fOrigin = pEntity->GetNetworkable()->GetPVSInfo()->m_vCenter;

        return Vector(fOrigin[0],fOrigin[1],fOrigin[2]);
}


stefanhendriks 05-01-2005 16:54

Re: draw beam
 
w0h00! :D

* i also tried drawing waypoints, and i got them drawing, they are thinner and such. But somehow it only draws a few. I don't know yet how to make it draw more waypoints. It looks like as if i can draw way less wpts then in the HL1 engine?

Cheeseh 05-01-2005 17:13

Re: draw beam
 
It draws all the waypoints for me, I think.

I think HL might be smart and cut some out if they aren't in your field of view.

I'm using a 3d hashtable for mine to draw the waypoints nearest the player so only those in the nearest buckets to me get drawn.

ps, just edited the code above, don't need GetServerEntity() it will work just from pEntity ;)

stefanhendriks 05-01-2005 17:31

Re: draw beam
 
you think? ;) i am writing the waypoint system from scratch, but i am talking about 20 wpts to be needed to be drawn. It somehow does not get drawn! here is my beam code:

Code:

void WaypointDraw(edict_t *pEdict)
{
        // When gWaypointSprite failed, try again here
        if (engine->IsModelPrecached(PHYSGUN_BEAM_SPRITE) || gWaypointSprite < 0)
        {
                // Precache sprite
                gWaypointSprite = engine->PrecacheModel(PHYSGUN_BEAM_SPRITE);
        }
        int iIndex=0;
        for (iIndex; iIndex < MAX_WAYPOINTS; iIndex++)
        {
                // every waypoint that has Vector != 0,0,0
                if (gWaypoints[iIndex].Origin != Vector(0,0,0))
                {
                        // Draw beam
                        //engine->
                        effects->Beam(gWaypoints[iIndex].Origin + Vector(0,0,-128),
                                                  gWaypoints[iIndex].Origin,
                                                  gWaypointSprite,
                                                  0,
                                                  0, 0, 10, 1, 1, 1, 0,
                                                  255,255,255,255,5);
/*
                                virtual void Beam( const Vector &Start, const Vector &End, int nModelIndex,
  int nHaloIndex, unsigned char frameStart, unsigned char frameRate,
  float flLife, unsigned char width, unsigned char endWidth, unsigned char fadeLength,
  unsigned char noise, unsigned char red, unsigned char green,
  unsigned char blue, unsigned char brightness, unsigned char speed) = 0;*/
                }
        }
}


Cheeseh 05-01-2005 21:01

Re: draw beam
 
could be the "fadeLength" parameter, try making it 255. Maybe make the width a bit more to see it easier too ;)

heres what i use for drawing a waypoint (try copying the values)
Code:

        g_pEffects->Beam( m_vOrigin - Vector(0,0,WAYPOINT_HEIGHT/2), m_vOrigin + Vector(0,0,WAYPOINT_HEIGHT/2), CWaypoints::waypointTexture(),
        0, 0, 1,
        1, WAYPOINT_WIDTH, WAYPOINT_WIDTH, 255,
        1, 0, 0, 255, 200, 10);

the waypoint origin is in the center so i draw from -36units to + 36units

stefanhendriks 06-01-2005 10:17

Re: draw beam
 
well, ok, the width is abit thin, but i like slim wpts ;) :D

i will try the fadelength.

Cheeseh 06-01-2005 18:49

Re: draw beam
 
okay looks as though I can't edit my old posts :'(

anyway.

this code works for bots and players and maybe even ohter entities which I havne't been able to test with yet (works with players and bots).

you may need GetIServerEntity

PHP Code:

Vector entityOrigin edict_t *pEntity )
{
    static 
float *fOrigin;
    
    
fOrigin pEntity->GetIServerEntity()->GetNetworkable()->GetPVSInfo()->m_vCenter;

    return 
Vector(fOrigin[0],fOrigin[1],fOrigin[2]);



stefanhendriks 06-01-2005 19:07

Re: draw beam
 
rofl, i somehow remember that you said that could be left out? ;) well i changed it into the above code and i will try it asap.

Cheeseh 06-01-2005 19:58

Re: draw beam
 
yeah I thought that because it would still compile and thought it would do basically the same thing but never actually tested it. Better look before i leap :P


All times are GMT +2. The time now is 11:30.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.