Jump to content
  • Advertisement
Sign in to follow this  
cs_student

Hud crashes HL2MP mod

This topic is 3627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I made a radar for a hl2mp mod. I'm trying to figure out why my radar keeps crashing. It works fine until I throw a bot in the game and the for loop under Paint() carries through fully. Here's the code
#include "hud.h"
#include "cbase.h"
#include "radar_hud.h"
#include "iclientmode.h"
#include "hud_macros.h"
#include "vgui_controls/controls.h"
#include "vgui/ISurface.h"

#include "tier0/memdbgon.h"

using namespace vgui;



DECLARE_HUDELEMENT( CRadarHud );

static ConVar show_radar("show_radar", "1", 0, "toggles radar on and off");


CRadarHud::CRadarHud( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudImport" )
{
	
	
	
	Panel *pParent = g_pClientMode->GetViewport();
	SetParent( pParent );   
   
	SetVisible( true );

	// create radar texture
	m_nImport = surface()->CreateNewTextureID();
	surface()->DrawSetTextureFile( m_nImport, "HUD/hud_radar" , true, true);
	
	// hides radar if player is dead
	SetHiddenBits( HIDEHUD_PLAYERDEAD);

	// Draw the radar
	SetPaintBorderEnabled(false);
	surface()->DrawSetTexture( m_nImport );
	surface()->DrawTexturedRect( 2, 2, 128, 128 );
	
}


void CRadarHud::Paint()
{
	// draws the radar	
	SetPaintBorderEnabled(false);
	surface()->DrawSetTexture( m_nImport );
	surface()->DrawTexturedRect( 2, 2, 128, 128 );
	
	//	TODO:  We need to update the dots on the screen according to where the players are

	// create player pointer
	C_BasePlayer *pOtherPlayer = NULL;
	surface()->DrawSetColor( 250, 250, 250, 10 );
	surface()->DrawFilledRect(10, 60, 15, 65);

	for(int i = 1; i <= gpGlobals->maxClients; i++ )
	{
		pOtherPlayer = UTIL_PlayerByIndex( i );

		if(!pOtherPlayer)
			continue;
		if(!pOtherPlayer->IsAlive( ))
			continue;
		if(!pOtherPlayer->IsClient( ))
			continue;
		// draw everyone
		/*if(pOtherPlayer->GetTeamNumber( ) != pPlayer->GetTeamNumber( ))
			continue; // Don't draw enemies TODO radar amplifier */
		if(pOtherPlayer == C_BasePlayer::GetLocalPlayer( ))
			continue; // Don't draw self

		C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
		Vector offset = pOtherPlayer->GetAbsOrigin() - pLocalPlayer->GetAbsOrigin();
		offset /= scale; // you will have to choose the scale appropriately
		const Vector fixed = Vector(offset.x,offset.z,0);
		QAngle _angles;
		VectorAngles(fixed, _angles);
		_angles.x += pLocalPlayer->EyeAngles().x; // not sure whether you want to add to x, y or z here
		Vector* rotated = NULL;
		AngleVectors(_angles, rotated);
		int drawX = rotated->x;
		int drawY = rotated->y;
		if ( drawX > 0 && drawY > 0 
		   && drawX < panelWidth && drawY < panelHeight )
		{// this clips to a square, which is less pretty but easier

			surface()->DrawFilledRect( drawX-1, drawY-1, drawX+1, drawY+1 );
			Msg("DrawX: %f, DrawY: %f", drawX, drawY);
		}

	} // end for loop
}




void CRadarHud::togglePrint()
{
	if (!show_radar.GetBool())
		 this->SetVisible(false);
	else
		this->SetVisible(true);
}	

void CRadarHud::OnThink()
{
	togglePrint();
	
	BaseClass::OnThink();
	
}

Thank you for your time and effort. Joe

Share this post


Link to post
Share on other sites
Advertisement
Could you be more descriptive? Such as, which line it crashes on? Or, what kind of error you're getting?

Try compiling it in debug mode, then run it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!