Go Back   Steam Users' Forums > Steam Tool Discussions > Source Coding

Reply
 
Thread Tools Display Modes
Old 02-18-2012, 10:13 AM   #1
Boby360
 
Join Date: Mar 2007
Reputation: 0
Posts: 37
Different scope images for different snipers.

I have multiple images done for the project i am working on for different sniper rifles. Like the AW50, Dragunov, PSG1, and 710. Weapons also have scope attachments like the anaconda, M4, Sg550, etc etc.

I would love some help to adjust my code to allow this if anyone has the spare time.

I am using this method. Also shown here:
https://developer.valvesoftware.com/..._a_weapon_zoom
Code:
#include "cbase.h"
#include "hudelement.h"
#include "hud_macros.h"
#include "iclientmode.h"
#include "c_gorm_player.h" //alternative #include "c_baseplayer.h"
 
#include <vgui/IScheme.h>
#include <vgui_controls/Panel.h>
#include <vgui/ISurface.h>
 
// memdbgon must be the last include file in a .cpp file!
#include "tier0/memdbgon.h"
 
/**
 * Simple HUD element for displaying a sniper scope on screen
 */
class CHudScope : public vgui::Panel, public CHudElement
{
	DECLARE_CLASS_SIMPLE( CHudScope, vgui::Panel );
 
public:
	CHudScope( const char *pElementName );
 
	void Init();
	void MsgFunc_ShowScope( bf_read &msg );
 
protected:
	virtual void ApplySchemeSettings(vgui::IScheme *scheme);
	virtual void Paint( void );
 
private:
	bool			m_bShow;
    CHudTexture*	m_pScope;
};
 
DECLARE_HUDELEMENT( CHudScope );
DECLARE_HUD_MESSAGE( CHudScope, ShowScope );
 
using namespace vgui;
 
/**
 * Constructor - generic HUD element initialization stuff. Make sure our 2 member variables
 * are instantiated.
 */
CHudScope::CHudScope( const char *pElementName ) : CHudElement(pElementName), BaseClass(NULL, "HudScope")
{
	vgui::Panel *pParent = g_pClientMode->GetViewport();
	SetParent( pParent );
 
	m_bShow = false;
	m_pScope = 0;
 
	// Scope will not show when the player is dead
	SetHiddenBits( HIDEHUD_PLAYERDEAD );
 
        // fix for users with diffrent screen ratio (Lodle)
	int screenWide, screenTall;
	GetHudSize(screenWide, screenTall);
	SetBounds(0, 0, screenWide, screenTall);
 
}
 
/**
 * Hook up our HUD message, and make sure we are not showing the scope
 */
void CHudScope::Init()
{
	HOOK_HUD_MESSAGE( CHudScope, ShowScope );
 
	m_bShow = false;
}
 
/**
 * Load  in the scope material here
 */
void CHudScope::ApplySchemeSettings( vgui::IScheme *scheme )
{
	BaseClass::ApplySchemeSettings(scheme);
 
	SetPaintBackgroundEnabled(false);
	SetPaintBorderEnabled(false);
 
	if (!m_pScope)
	{
		m_pScope = gHUD.GetIcon("scope");
	}
}
 
/**
 * Simple - if we want to show the scope, draw it. Otherwise don't.
 */
void CHudScope::Paint( void )
{
        C_GORMPlayer* pPlayer = C_GORMPlayer::GetLocalGORMPlayer();
        if (!pPlayer)
        {
                return;
        }
 
	if (m_bShow)
	{
                //Perform depth hack to prevent clips by world
	        //materials->DepthRange( 0.0f, 0.1f );
 
		// This will draw the scope at the origin of this HUD element, and
		// stretch it to the width and height of the element. As long as the
		// HUD element is set up to cover the entire screen, so will the scope
		int x1 = (GetWide() / 2) - (GetTall() / 2);
		int x2 = GetWide() - (x1 * 2);
		int x3 = GetWide() - x1;
 
		surface()->DrawSetColor(Color(0,0,0,255));
		surface()->DrawFilledRect(0, 0, x1, GetTall()); //Fill in the left side
 
		surface()->DrawSetColor(Color(0,0,0,255));
		surface()->DrawFilledRect(x3, 0, GetWide(), GetTall()); //Fill in the right side
 
		m_pScope->DrawSelf(x1, 0, x2, GetTall(), Color(255,255,255,255)); //Draw the scope as a perfect square
 
	        //Restore depth
	        //materials->DepthRange( 0.0f, 1.0f );
 
		// Hide the crosshair
  	  //      pPlayer->m_Local.m_iHideHUD |= HIDEHUD_CROSSHAIR;
	}
	else if ((pPlayer->m_Local.m_iHideHUD & HIDEHUD_CROSSHAIR) != 0)
	{
		pPlayer->m_Local.m_iHideHUD &= ~HIDEHUD_CROSSHAIR;
	}
}
 
 
/**
 * Callback for our message - set the show variable to whatever
 * boolean value is received in the message
 */
void CHudScope::MsgFunc_ShowScope(bf_read &msg)
{
	m_bShow = msg.ReadByte();
}
Then the code in each weapon here:
Code:
//=====================================================================================//

#include "cbase.h"
#include "gorm_weapon_base.h"

#if defined( CLIENT_DLL )

	#define CWeapon710 C_Weapon710
	#include "c_gorm_player.h"

#else

	#include "gorm_player.h"

#endif


class CWeapon710 : public CGORMWeaponBase
{
public:
	DECLARE_CLASS( CWeapon710, CGORMWeaponBase );
	DECLARE_NETWORKCLASS(); 
	DECLARE_PREDICTABLE();
	DECLARE_ACTTABLE();
	
	CWeapon710();

	virtual GORMWeaponID GetWeaponID( void ) const		{ return GORM_WEAPON_710; }
	void ToggleZoom();
	bool Holster(CBaseCombatWeapon *pSwitchingTo);
	void SecondaryAttack();

private:
	CNetworkVar(bool, m_bZoomed);

	CWeapon710( const CWeapon710 & );
};

IMPLEMENT_NETWORKCLASS_ALIASED( Weapon710, DT_Weapon710 )

BEGIN_NETWORK_TABLE( CWeapon710, DT_Weapon710 )
#ifdef CLIENT_DLL
	RecvPropBool( RECVINFO(m_bZoomed) ),
#else
	SendPropBool( SENDINFO(m_bZoomed) ),
#endif
END_NETWORK_TABLE()

BEGIN_PREDICTION_DATA( CWeapon710 )
END_PREDICTION_DATA()

LINK_ENTITY_TO_CLASS( weapon_710, CWeapon710 );
PRECACHE_WEAPON_REGISTER( weapon_710 );



CWeapon710::CWeapon710()
{
	m_nFireMode = FM_SEMIAUTOMATIC;
	m_nValidFireModes = (1 << FM_SEMIAUTOMATIC);
	m_bZoomed = false;
}

//Tony; todo; add ACT_MP_PRONE* activities, so we have them.
acttable_t CWeapon710::m_acttable[] = 
{
	{ ACT_MP_STAND_IDLE,					ACT_DOD_STAND_IDLE_TOMMY,				false },
	{ ACT_MP_CROUCH_IDLE,					ACT_DOD_CROUCH_IDLE_TOMMY,				false },
	{ ACT_MP_PRONE_IDLE,					ACT_DOD_PRONE_AIM_TOMMY,				false },

	{ ACT_MP_RUN,							ACT_DOD_RUN_AIM_TOMMY,					false },
	{ ACT_MP_WALK,							ACT_DOD_WALK_AIM_TOMMY,					false },
	{ ACT_MP_CROUCHWALK,					ACT_DOD_CROUCHWALK_AIM_TOMMY,			false },
	{ ACT_MP_PRONE_CRAWL,					ACT_DOD_PRONEWALK_IDLE_TOMMY,			false },
	{ ACT_SPRINT,							ACT_DOD_SPRINT_IDLE_TOMMY,				false },

	{ ACT_MP_ATTACK_STAND_PRIMARYFIRE,		ACT_DOD_PRIMARYATTACK_TOMMY,			false },
	{ ACT_MP_ATTACK_CROUCH_PRIMARYFIRE,		ACT_DOD_PRIMARYATTACK_TOMMY,			false },
	{ ACT_MP_ATTACK_PRONE_PRIMARYFIRE,		ACT_DOD_PRIMARYATTACK_PRONE_TOMMY,		false },
	{ ACT_MP_ATTACK_STAND_SECONDARYFIRE,	ACT_DOD_SECONDARYATTACK_TOMMY,			false },
	{ ACT_MP_ATTACK_CROUCH_SECONDARYFIRE,	ACT_DOD_SECONDARYATTACK_CROUCH_TOMMY,	false },
	{ ACT_MP_ATTACK_PRONE_SECONDARYFIRE,	ACT_DOD_SECONDARYATTACK_PRONE_TOMMY,	false },

	{ ACT_MP_RELOAD_STAND,					ACT_DOD_RELOAD_TOMMY,					false },
	{ ACT_MP_RELOAD_CROUCH,					ACT_DOD_RELOAD_CROUCH_TOMMY,			false },
	{ ACT_MP_RELOAD_PRONE,					ACT_DOD_RELOAD_PRONE_TOMMY,				false },

};

IMPLEMENT_ACTTABLE( CWeapon710 );

bool CWeapon710::Holster(CBaseCombatWeapon *pSwitchingTo)
{
	if (m_bZoomed)
		ToggleZoom();

	return BaseClass::Holster(pSwitchingTo);
}

void CWeapon710::SecondaryAttack()
{
	ToggleZoom();

	m_flNextSecondaryAttack = gpGlobals->curtime + GetAltFireRate();
}

void CWeapon710::ToggleZoom()
{
	CGORMPlayer *pPlayer = GetPlayerOwner();
	if (!pPlayer)
	{
		m_bZoomed = false;
		return;
	}

#ifndef CLIENT_DLL
	if (m_bZoomed)
	{
		pPlayer->SetFOV(this, 0, 0.1);
	}
	else
	{
		pPlayer->SetFOV(this, 11.25, 0.2);
	}
#endif

	m_bZoomed = !m_bZoomed;
}
Would really appreciate it if anyone that can help.

Thanks,
Boby
Boby360 is offline  
Reply With Quote
Old 02-19-2012, 04:25 PM   #2
Boby360
 
Join Date: Mar 2007
Reputation: 0
Posts: 37
Iv attempted to stick the texture data in the script file specifically with no change. removing from hud_textures then hoping it would use from script file also a failure.

Just popped into my head. Was really hoping it would work ^.^

Help would be appreciated.

Last edited by Boby360: 02-19-2012 at 04:28 PM.
Boby360 is offline   Reply With Quote
Old 02-19-2012, 09:24 PM   #3
Boby360
 
Join Date: Mar 2007
Reputation: 0
Posts: 37
Well the lack of advise sucked although i ended up creating a .cpp file for each different scope. Then renaming everything with CHudScope and Showscope. Not that clean although it got the job done for anyone in the future looking for an answer. Everything else should be apparent.
Boby360 is offline   Reply With Quote
Reply

Go Back   Steam Users' Forums > Steam Tool Discussions > Source Coding


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



All times are GMT -7. The time now is 01:52 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site Content Copyright Valve Corporation 1998-2014, All Rights Reserved.