Toggling RPG Guidance: Difference between revisions
m (Reverted edit of last, changed back to last version by cur) |
TomEdwards (talk | contribs) (Category:Weapons programming, syntax highlight) |
||
Line 1: | Line 1: | ||
[[Category:Tutorials]][[Category: | [[Category:Tutorials]][[Category:Weapons programming]] | ||
''Based on tutorial found [http://www.hl2world.com/wiki/index.php/Toggle_RPG_Laser here].'' | ''Based on tutorial found [http://www.hl2world.com/wiki/index.php/Toggle_RPG_Laser here].'' | ||
Line 11: | Line 11: | ||
In CWeaponRPG::ItemPostFrame() (about line 1539), add the following code: | In CWeaponRPG::ItemPostFrame() (about line 1539), add the following code: | ||
< | <source lang=cpp> | ||
if ( pPlayer->m_afButtonPressed & IN_ATTACK2 ) | if ( pPlayer->m_afButtonPressed & IN_ATTACK2 ) | ||
{ | { | ||
ToggleGuiding(); | ToggleGuiding(); | ||
} | } | ||
</ | </source> | ||
at the end of the method, after: | at the end of the method, after: | ||
< | <source lang=cpp> | ||
if ( pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0 && m_hMissile == NULL ) | if ( pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0 && m_hMissile == NULL ) | ||
{ | { | ||
StopGuiding(); | StopGuiding(); | ||
} | } | ||
</ | </source> | ||
This says, in effect, "If the player hits the secondary attack, toggle rocket guidance on or off." | This says, in effect, "If the player hits the secondary attack, toggle rocket guidance on or off." | ||
Line 31: | Line 31: | ||
Then in CWeaponRPG::SuppressGuiding() (about line 1497), find the following code: | Then in CWeaponRPG::SuppressGuiding() (about line 1497), find the following code: | ||
< | <source lang=cpp> | ||
if ( m_hLaserDot == NULL ) | if ( m_hLaserDot == NULL ) | ||
{ | { | ||
Line 40: | Line 40: | ||
return; | return; | ||
} | } | ||
</ | </source> | ||
and comment "StartGuiding();" out, so that it looks like this: | and comment "StartGuiding();" out, so that it looks like this: | ||
< | <source lang=cpp> | ||
if ( m_hLaserDot == NULL ) | if ( m_hLaserDot == NULL ) | ||
{ | { | ||
Line 53: | Line 53: | ||
return; | return; | ||
} | } | ||
</ | </source> | ||
This stops the code from automatically starting up rocket guidance again. | This stops the code from automatically starting up rocket guidance again. | ||
Line 61: | Line 61: | ||
In CWeaponRPG::Lower() (about line 1528), find the following code: | In CWeaponRPG::Lower() (about line 1528), find the following code: | ||
< | <source lang=cpp> | ||
if ( m_hMissile != NULL ) | if ( m_hMissile != NULL ) | ||
return false; | return false; | ||
</ | </source> | ||
and change it to read: | and change it to read: | ||
< | <source lang=cpp> | ||
if ( m_hMissile != NULL && IsGuiding() ) | if ( m_hMissile != NULL && IsGuiding() ) | ||
return false; | return false; | ||
</ | </source> | ||
This prevents the code from automatically telling us that we can't lower the RPG if we're not guiding. You will then need to make the same change in CWeaponRPG::CanHolster() (about line 1641). | This prevents the code from automatically telling us that we can't lower the RPG if we're not guiding. You will then need to make the same change in CWeaponRPG::CanHolster() (about line 1641). | ||
Line 77: | Line 77: | ||
Then in CWeaponRPG::Reload() (about line 1827), add this code: | Then in CWeaponRPG::Reload() (about line 1827), add this code: | ||
< | <source lang=cpp> | ||
if ( pOwner->GetActiveWeapon() != this ) | if ( pOwner->GetActiveWeapon() != this ) | ||
return false; | return false; | ||
</ | </source> | ||
after: | after: | ||
< | <source lang=cpp> | ||
if ( pOwner->GetAmmoCount(m_iPrimaryAmmoType) <= 0 ) | if ( pOwner->GetAmmoCount(m_iPrimaryAmmoType) <= 0 ) | ||
return false; | return false; | ||
</ | </source> | ||
If we changed weapons after firing, this will prevent the RPG from getting kicked back up to us for a reload after the dumb rocket explodes. | If we changed weapons after firing, this will prevent the RPG from getting kicked back up to us for a reload after the dumb rocket explodes. | ||
And that's it! You're done. | And that's it! You're done. |
Revision as of 09:47, 15 August 2009
Based on tutorial found here.
Basically what we're going to be doing is allowing a player to switch the RPG's guiding laser on and off using the weapon's secondary fire. Along with this, we will allow a player who has fired a dumb (non-guided) rocket that hasn't yet exploded to change weapons.
Files affected:
- weapon_rpg.cpp
In CWeaponRPG::ItemPostFrame() (about line 1539), add the following code:
if ( pPlayer->m_afButtonPressed & IN_ATTACK2 )
{
ToggleGuiding();
}
at the end of the method, after:
if ( pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0 && m_hMissile == NULL )
{
StopGuiding();
}
This says, in effect, "If the player hits the secondary attack, toggle rocket guidance on or off."
Then in CWeaponRPG::SuppressGuiding() (about line 1497), find the following code:
if ( m_hLaserDot == NULL )
{
StartGuiding();
//STILL!?
if ( m_hLaserDot == NULL )
return;
}
and comment "StartGuiding();" out, so that it looks like this:
if ( m_hLaserDot == NULL )
{
//StartGuiding();
//STILL!?
if ( m_hLaserDot == NULL )
return;
}
This stops the code from automatically starting up rocket guidance again.
That's it for the guidance toggling code. Now to allow the player to lower the RPG after firing a dumb rocket but before it explodes.
In CWeaponRPG::Lower() (about line 1528), find the following code:
if ( m_hMissile != NULL )
return false;
and change it to read:
if ( m_hMissile != NULL && IsGuiding() )
return false;
This prevents the code from automatically telling us that we can't lower the RPG if we're not guiding. You will then need to make the same change in CWeaponRPG::CanHolster() (about line 1641).
Then in CWeaponRPG::Reload() (about line 1827), add this code:
if ( pOwner->GetActiveWeapon() != this )
return false;
after:
if ( pOwner->GetAmmoCount(m_iPrimaryAmmoType) <= 0 )
return false;
If we changed weapons after firing, this will prevent the RPG from getting kicked back up to us for a reload after the dumb rocket explodes.
And that's it! You're done.