Lowering your weapon on sprint: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(unnamed parameters don't require the "1=" :p)
No edit summary
Line 1: Line 1:
This article provides a basic implementation of weapon lowering while sprinting, and preventing weapon fire while doing so.
{{lang|title=Abaixando sua arma enquanto correndo}}
Este artigo fornece uma implementação básica de abaixamento de armas durante a corrida e prevenção de disparos de armas ao fazê-lo.


{{note|This will not work if your viewmodel doesn't have ACT_VM_IDLE_LOWERED animation declared somewhere in the .qc file.}}
{{note|Isso não funcionará se seu modelo de visualização não tiver animação ACT_VM_IDLE_LOWERED declarada em algum lugar do arquivo .qc.}}


{{note|Se sua gun_yourweaponname.cpp estiver substituindo ItemPostFrame, você deverá colocar BaseClass::ProcessAnimationEvents(); no ItemPostFrame dessa classe, mas somente se você não estiver chamando BaseClass::ItemPostFrame();. Por exemplo, em arma_shotgun.cpp ele tem uma substituição de ItemPostFrame, o que significa que o código de redução da arma não será chamado para esta arma, a menos que você adicione uma chamada a ela! '''Lembre-se de colocar as declarações Basecombatweapon_Shared.h em públicas ou protegidas para que você possa fazer uso dessas variáveis ​​​​em classes que herdam basecombatweapon_shared, como o ItemPostFrame do Weapon_shotgun.cpp. Se você não fizer isso, receberá erros de identificador não declarados'''}}


{{note|If your weapon_yourweaponname.cpp is overriding ItemPostFrame then you have to place BaseClass::ProcessAnimationEvents(); in the ItemPostFrame of that class but only if you aren't calling BaseClass::ItemPostFrame();. For example in the weapon_shotgun.cpp it has an override of ItemPostFrame which means that the lowering weapon code will not be called for this weapon unless you add a call to it! '''Remember to put the Basecombatweapon_Shared.h declarations under public or protected so that you can make use of these variables in classes which inherit basecombatweapon_shared, like the weapon_shotgun.cpp's ItemPostFrame. If you don't do this you will get undeclared identifier errors'''}}
== O Codigo ==
 
== The Code ==
{{note|This has been tested with HL2MP, 2013 and Alien Swarm SDKS.}}
{{note|This has been tested with HL2MP, 2013 and Alien Swarm SDKS.}}


===BASECOMBATWEAPON_SHARED.CPP===
===BASECOMBATWEAPON_SHARED.CPP===


Hit CTRL+F and search for this code:
Aperta CRTL+F e procure para essa parte:
 
<source lang=cpp>
<source lang=cpp>


Line 19: Line 18:
</source>
</source>


Then copy and paste this above it:
Em seguida, copie e cole isto acima:


<source lang=cpp>
<source lang=cpp>
Line 57: Line 56:
</source>
</source>


Now to make sure our code gets called we add ProcessAnimationEvents(); here:
Agora, para garantir que nosso código seja chamado, adicionamos ProcessAnimationEvents(); aqui:


<source lang=cpp>
<source lang=cpp>
Line 63: Line 62:
void CBaseCombatWeapon::ItemPostFrame( void )
void CBaseCombatWeapon::ItemPostFrame( void )
{
{
      //Add this underneath the pOwner accessor check.
    //Adicione isso abaixo da verificação do acessador pOwner.
       ProcessAnimationEvents();
       ProcessAnimationEvents();
}
}
Line 71: Line 70:
===BASECOMBATWEAPON_SHARED.H===
===BASECOMBATWEAPON_SHARED.H===


Add these declarations under public at line 211 below '''bool IsViewModelSequenceFinished( void ); // Returns if the viewmodel's current animation is finished''':
Adicione essas declarações em public na linha 211 abaixo '''bool IsViewModelSequenceFinished( void ); // Retorna se a animação atual do viewmodel foi finalizada''':
{{note|We make ProcessAnimationEvents virtual so that we can override it in classes which inherit this class.}}
{{note|Tornamos ProcessAnimationEvents virtuais para que possamos substituí-lo em classes que herdam esta classe.}}


<source lang=cpp>
<source lang=cpp>
Line 81: Line 80:
</source>
</source>


==Finish==
==Fim==


Now your weapon should be lowered when you hit the sprint button and you will not be able to shoot until you release the button!
Now your weapon should be lowered when you hit the sprint button and you will not be able to shoot until you release the button!
[[File:Sprint.gif|none|Finished Product]]
[[File:Sprint.gif|none| Olhe como fica! ]


[[Category:Weapons programming]]
[[Category:Weapons programming:pt-br]]
[[Category:Tutorials]]
[[Category:Tutorials:pt-br]]
[[Category:Programming:pt-br]]

Revision as of 10:12, 16 January 2024

English (en)Português do Brasil (pt-br)Translate (Translate)

Este artigo fornece uma implementação básica de abaixamento de armas durante a corrida e prevenção de disparos de armas ao fazê-lo.

Note.pngNote:Isso não funcionará se seu modelo de visualização não tiver animação ACT_VM_IDLE_LOWERED declarada em algum lugar do arquivo .qc.
Note.pngNote:Se sua gun_yourweaponname.cpp estiver substituindo ItemPostFrame, você deverá colocar BaseClass::ProcessAnimationEvents(); no ItemPostFrame dessa classe, mas somente se você não estiver chamando BaseClass::ItemPostFrame();. Por exemplo, em arma_shotgun.cpp ele tem uma substituição de ItemPostFrame, o que significa que o código de redução da arma não será chamado para esta arma, a menos que você adicione uma chamada a ela! Lembre-se de colocar as declarações Basecombatweapon_Shared.h em públicas ou protegidas para que você possa fazer uso dessas variáveis ​​​​em classes que herdam basecombatweapon_shared, como o ItemPostFrame do Weapon_shotgun.cpp. Se você não fizer isso, receberá erros de identificador não declarados

O Codigo

Note.pngNote:This has been tested with HL2MP, 2013 and Alien Swarm SDKS.

BASECOMBATWEAPON_SHARED.CPP

Aperta CRTL+F e procure para essa parte:

void CBaseCombatWeapon::ItemPostFrame( void )

Em seguida, copie e cole isto acima:

void CBaseCombatWeapon::ProcessAnimationEvents(void)
{
	CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
	if (!pOwner)
		return;

	if ( !m_bWeaponIsLowered && (pOwner->m_nButtons & IN_SPEED ) )
	{
		m_bWeaponIsLowered = true;
		SendWeaponAnim( ACT_VM_IDLE_LOWERED );
		m_flNextPrimaryAttack = gpGlobals->curtime + GetViewModelSequenceDuration();
	        m_flNextSecondaryAttack = m_flNextPrimaryAttack;
	}
	else if ( m_bWeaponIsLowered && !(pOwner->m_nButtons & IN_SPEED ) )
	{
		m_bWeaponIsLowered = false;
		SendWeaponAnim( ACT_VM_IDLE );
		m_flNextPrimaryAttack = gpGlobals->curtime + GetViewModelSequenceDuration();
 	        m_flNextSecondaryAttack = m_flNextPrimaryAttack;
	}

	if ( m_bWeaponIsLowered )
	{
		if ( gpGlobals->curtime > m_flNextPrimaryAttack )
		{
			SendWeaponAnim( ACT_VM_IDLE_LOWERED );
			m_flNextPrimaryAttack = gpGlobals->curtime + GetViewModelSequenceDuration();
			m_flNextSecondaryAttack = m_flNextPrimaryAttack;
		}
	}
}

Agora, para garantir que nosso código seja chamado, adicionamos ProcessAnimationEvents(); aqui:

void CBaseCombatWeapon::ItemPostFrame( void )
{
     //Adicione isso abaixo da verificação do acessador pOwner.
      ProcessAnimationEvents();
}

BASECOMBATWEAPON_SHARED.H

Adicione essas declarações em public na linha 211 abaixo bool IsViewModelSequenceFinished( void ); // Retorna se a animação atual do viewmodel foi finalizada:

Note.pngNote:Tornamos ProcessAnimationEvents virtuais para que possamos substituí-lo em classes que herdam esta classe.
	virtual void            ProcessAnimationEvents(void);
	bool                    m_bWeaponIsLowered;

Fim

Now your weapon should be lowered when you hit the sprint button and you will not be able to shoot until you release the button! [[File:Sprint.gif|none| Olhe como fica! ]