Toggling RPG Guidance: Difference between revisions
No edit summary |
Mazdothewolf (talk | contribs) (Remade the part about the ItemPostFrame function since it was obselete) |
||
(8 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
{{Dead end|date=January 2024}} | |||
NOTE: This tutorial may not work for Source SDK 2013 Multiplayer, the last element Identifier StopLaserEffects() is nonexistent in the server.dll, causing the errors E0020 undefined and C3861 Identifier not found in V.S. 2022 and fails to compile the server.dll. This tutorial should be capable i believe on the SDKs 2006 and 2007. This is not an issue for the current version of the 2013 SDK. | |||
''Based on tutorial found [https://web.archive.org/web/20061105023442/https://www.hl2world.com/wiki/index.php/Toggle_RPG_Laser here].'' | |||
Basically what we're going to be doing is allowing a [[player]] to switch the [[weapon_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:''' | '''Files affected:''' | ||
* ''weapon_rpg.cpp'' | * ''weapon_rpg.cpp'' | ||
In CWeaponRPG::ItemPostFrame() find the following code: | |||
In CWeaponRPG::ItemPostFrame() | |||
<source lang=cpp> | <source lang=cpp> | ||
if ( | if ( g_pGameRules->IsMultiplayer() == true ) | ||
{ | { | ||
ToggleGuiding(); | if ( pPlayer->m_afButtonPressed & IN_ATTACK2 ) | ||
{ | |||
ToggleGuiding(); | |||
} | |||
} | } | ||
</source> | </source> | ||
And comment out the following like that (or delete them): | |||
<source lang=cpp> | <source lang=cpp> | ||
if ( | //if ( g_pGameRules->IsMultiplayer() == true ) | ||
{ | //{ | ||
if ( pPlayer->m_afButtonPressed & IN_ATTACK2 ) | |||
} | { | ||
ToggleGuiding(); | |||
} | |||
//} | |||
</source> | </source> | ||
This | This removes the gamerule that only allows you to toggle RPG guidance in multiplayer. | ||
Then in CWeaponRPG::SuppressGuiding() (about line 1497), find the following code: | Then in CWeaponRPG::SuppressGuiding() (about line 1497), find the following code: | ||
Line 73: | Line 80: | ||
</source> | </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:: | 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::Holster() (about line 1641). | ||
Then in CWeaponRPG::Reload() (about line 1827), add this code: | Then in CWeaponRPG::Reload() (about line 1827), add this code: | ||
Line 90: | Line 97: | ||
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. | ||
As soon as we run out of rockets, the RPG is forced to lower, causing a constant toggle sound to play forever, we clearly don't want that, and there is a very simple fix for this sort of issue, in ''void CWeaponRPG::StopGuiding()'' change this code : | As soon as we run out of rockets, the RPG is forced to lower, causing a constant toggle sound to play forever, we clearly don't want that, and there is a very simple fix for this sort of issue, in ''void CWeaponRPG::StopGuiding()'' change this code : | ||
Line 129: | Line 135: | ||
{{note|This still retains the Toggling sound when you Disable or Enable guidance, so there is nothing to worry about :)}} | {{note|This still retains the Toggling sound when you Disable or Enable guidance, so there is nothing to worry about :)}} | ||
And that's it! You're done! | |||
'''If any issues arise, ensure that you've done the steps above correctly, and that you didn't misplace (or create a typo within) the code.''' | |||
==See also== | |||
* {{ent|npc_missiledefense}} | |||
* {{ent|item_rpg_round}} | |||
* {{ent|trigger_rpgfire}} | |||
[[Category:Tutorials]] | |||
[[Category:Weapons programming]] | |||
[[Category:Programming]] |
Latest revision as of 13:13, 3 August 2025



January 2024
NOTE: This tutorial may not work for Source SDK 2013 Multiplayer, the last element Identifier StopLaserEffects() is nonexistent in the server.dll, causing the errors E0020 undefined and C3861 Identifier not found in V.S. 2022 and fails to compile the server.dll. This tutorial should be capable i believe on the SDKs 2006 and 2007. This is not an issue for the current version of the 2013 SDK.
Based on tutorial found here.
Basically what we're going to be doing is allowing a player to switch the weapon_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() find the following code:
if ( g_pGameRules->IsMultiplayer() == true )
{
if ( pPlayer->m_afButtonPressed & IN_ATTACK2 )
{
ToggleGuiding();
}
}
And comment out the following like that (or delete them):
//if ( g_pGameRules->IsMultiplayer() == true )
//{
if ( pPlayer->m_afButtonPressed & IN_ATTACK2 )
{
ToggleGuiding();
}
//}
This removes the gamerule that only allows you to toggle RPG guidance in multiplayer.
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::Holster() (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.
As soon as we run out of rockets, the RPG is forced to lower, causing a constant toggle sound to play forever, we clearly don't want that, and there is a very simple fix for this sort of issue, in void CWeaponRPG::StopGuiding() change this code :
m_bGuiding = false;
WeaponSound( SPECIAL2 );
StopLaserEffects();
// Kill the dot completely
if (m_hLaserDot != NULL)
{
m_hLaserDot->TurnOff();
UTIL_Remove(m_hLaserDot);
m_hLaserDot = NULL;
}
To this :
m_bGuiding = false;
StopLaserEffects();
// Kill the dot completely
if (m_hLaserDot != NULL)
{
m_hLaserDot->TurnOff();
UTIL_Remove(m_hLaserDot);
m_hLaserDot = NULL;
WeaponSound(SPECIAL2);
}
What we did here, was simply change the position of the WeaponSound(SPECIAL2);, putting it inside of the if statement of which is designated to kill the guidance dot.

And that's it! You're done!
If any issues arise, ensure that you've done the steps above correctly, and that you didn't misplace (or create a typo within) the code.