Magazine style reloads: Difference between revisions
No edit summary |
m (It's not a clip, it's a magazine. They are NOT the same thing and naming this article could cause confusion regarding weapons with TRUE clips (like the M1 Garand)) |
||
Line 19: | Line 19: | ||
} | } | ||
This tells the game to fully reload the gun and deduct 1 from the iPrimaryAmmoType. From now on, the iPrimaryAmmoType will contain the number of full | This tells the game to fully reload the gun and deduct 1 from the iPrimaryAmmoType. From now on, the iPrimaryAmmoType will contain the number of full magazines instead of the number of bullets. | ||
You can also do this for secondary fire if you have a weapon which needs reloading. Just substitute primary for secondary. | You can also do this for secondary fire if you have a weapon which needs reloading. Just substitute primary for secondary. | ||
If you step on a weapon with ammo in the | If you step on a weapon with ammo in the magazine, the game grants you the ammo in the magazine. Unfortunately, in a magazine style ammo system, this will grant 30 magazines instead of 30 bullets. To correct this find '''BaseCombatCharacter.cpp''' and go to the '''Weapon_EquipAmmoOnly''' function. Change the code: | ||
int primaryGiven = (pWeapon->UsesClipsForAmmo1()) ? pWeapon->m_iClip1 : pWeapon->GetPrimaryAmmoCount(); | int primaryGiven = (pWeapon->UsesClipsForAmmo1()) ? pWeapon->m_iClip1 : pWeapon->GetPrimaryAmmoCount(); | ||
int secondaryGiven = (pWeapon->UsesClipsForAmmo2()) ? pWeapon->m_iClip2 : pWeapon->GetSecondaryAmmoCount(); | int secondaryGiven = (pWeapon->UsesClipsForAmmo2()) ? pWeapon->m_iClip2 : pWeapon->GetSecondaryAmmoCount(); | ||
Line 32: | Line 32: | ||
int primaryGiven = (pWeapon->UsesClipsForAmmo1()) ? pWeapon->m_iClip1 : pWeapon->GetPrimaryAmmoCount(); | int primaryGiven = (pWeapon->UsesClipsForAmmo1()) ? pWeapon->m_iClip1 : pWeapon->GetPrimaryAmmoCount(); | ||
int secondaryGiven = (pWeapon->UsesClipsForAmmo2()) ? pWeapon->m_iClip2 : pWeapon->GetSecondaryAmmoCount(); | int secondaryGiven = (pWeapon->UsesClipsForAmmo2()) ? pWeapon->m_iClip2 : pWeapon->GetSecondaryAmmoCount(); | ||
// Don't give 30 | // Don't give 30 magazines for picking up a weapon | ||
// with 30 bullets. | // with 30 bullets. | ||
if (primaryGiven > 0) primaryGiven = 1; | if (primaryGiven > 0) primaryGiven = 1; | ||
Line 39: | Line 39: | ||
int takenSecondary = GiveAmmo( secondaryGiven, pWeapon->m_iSecondaryAmmoType); | int takenSecondary = GiveAmmo( secondaryGiven, pWeapon->m_iSecondaryAmmoType); | ||
Now you will receive | Now you will receive one magazine, instead of 30. While this fix has the potential to add some bullets into the game, it is better than nothing. A better fix would require a system where you can save magazines without throwing them away. | ||
You will notice, that the game will still grant you 30 or more bullets if you pick up an ammo crate. Now go to the '''items.h''' and mod this part to your liking. You will receive the amount of full | You will notice, that the game will still grant you 30 or more bullets if you pick up an ammo crate. Now go to the '''items.h''' and mod this part to your liking. You will receive the amount of full magazines, you specify here. Whenever you pick up an ammo crate. | ||
#define SIZE_AMMO_PISTOL 12 | #define SIZE_AMMO_PISTOL 12 | ||
#define SIZE_AMMO_PISTOL_LARGE 100 | #define SIZE_AMMO_PISTOL_LARGE 100 | ||
Line 57: | Line 57: | ||
#define SIZE_AMMO_AR2_ALTFIRE 1 | #define SIZE_AMMO_AR2_ALTFIRE 1 | ||
You get some ammo at the start. That should be modded as well. Go to the '''hl2mp_player.cpp''' and look up the ''GiveDefaultItems'' procedure. Mod the part below to your liking. You will get the specified amount of | You get some ammo at the start. That should be modded as well. Go to the '''hl2mp_player.cpp''' and look up the ''GiveDefaultItems'' procedure. Mod the part below to your liking. You will get the specified amount of magazines at start. | ||
CBasePlayer::GiveAmmo( 255, "Pistol"); | CBasePlayer::GiveAmmo( 255, "Pistol"); | ||
CBasePlayer::GiveAmmo( 45, "SMG1"); | CBasePlayer::GiveAmmo( 45, "SMG1"); | ||
Line 64: | Line 64: | ||
CBasePlayer::GiveAmmo( 6, "357" ); | CBasePlayer::GiveAmmo( 6, "357" ); | ||
Ever noticed, that the game auto-reloads your gun if you holster it? This is not so good, if you have this | Ever noticed, that the game auto-reloads your gun if you holster it? This is not so good, if you have this magazine system. | ||
To remove this go to the '''weapon_hl2mpbasehlmpcombatweapon.cpp''' and find the ''ItemHolsterFrame'' procedure. Comment out the | To remove this go to the '''weapon_hl2mpbasehlmpcombatweapon.cpp''' and find the ''ItemHolsterFrame'' procedure. Comment out the | ||
FinishReload(); | FinishReload(); | ||
Line and you are good. | Line and you are good. | ||
Finally, it is not realistic to hold 200 | Finally, it is not realistic to hold 200 magazines. Decrease this value in '''hl2mp_gamerules.cpp'''. At the end of the file there is an ''AmmoDef'' part like the one below. | ||
def.AddAmmoType("AR2", DMG_BULLET, TRACER_LINE_AND_WHIZ, 0, 0, 60, BULLET_IMPULSE(200, 1225), 0 ); | def.AddAmmoType("AR2", DMG_BULLET, TRACER_LINE_AND_WHIZ, 0, 0, 60, BULLET_IMPULSE(200, 1225), 0 ); | ||
The 60 shows the max amount of ammo, the player can hold. If you change it to 5 then you can have maximum 5 reloads. | The 60 shows the max amount of ammo, the player can hold. If you change it to 5 then you can have maximum 5 reloads. | ||
You are now finished! | You are now finished! | ||
It would take more tinkering to have a true | It would take more tinkering to have a true magazine system, which does not throw away the used magazines. | ||
Idea! I was reading this and started to think that you can actually make this work by just modifying | Idea! I was reading this and started to think that you can actually make this work by just modifying magazine-reloading weapons to remove ammo amount of new magazine(GetMaxClip1()) and just modify hud to shot remaining ammo/30 or leave it as it is. | ||
[[Category:Programming]] | [[Category:Programming]] | ||
[[Category:Tutorials]] | [[Category:Tutorials]] |
Revision as of 10:10, 14 January 2009
This will be a short and simple one! Say you want to make each shot and each reload count? In CS you can reload anytime you feel like. Some bullets will be deducted and that is all. However, in real life, you will not start to load the half-empty mag, you pull out a new one, and throw away the used one. OK you don't throw it away but anyway. This system can be found in BF2, and some other games. So now to the code: Look up the basecombatweapon_shared.cpp and go to the FinishReload procedure. You will mod this part:
if ( UsesClipsForAmmo1() ) { int primary = min( GetMaxClip1() - m_iClip1, pOwner->GetAmmoCount(m_iPrimaryAmmoType)); m_iClip1 += primary; pOwner->RemoveAmmo( primary, m_iPrimaryAmmoType); }
to look like this:
if ( UsesClipsForAmmo1() ) { //int primary = min( GetMaxClip1() - m_iClip1, pOwner->GetAmmoCount(m_iPrimaryAmmoType)); m_iClip1 = GetMaxClip1(); pOwner->RemoveAmmo( 1, m_iPrimaryAmmoType); }
This tells the game to fully reload the gun and deduct 1 from the iPrimaryAmmoType. From now on, the iPrimaryAmmoType will contain the number of full magazines instead of the number of bullets.
You can also do this for secondary fire if you have a weapon which needs reloading. Just substitute primary for secondary.
If you step on a weapon with ammo in the magazine, the game grants you the ammo in the magazine. Unfortunately, in a magazine style ammo system, this will grant 30 magazines instead of 30 bullets. To correct this find BaseCombatCharacter.cpp and go to the Weapon_EquipAmmoOnly function. Change the code:
int primaryGiven = (pWeapon->UsesClipsForAmmo1()) ? pWeapon->m_iClip1 : pWeapon->GetPrimaryAmmoCount(); int secondaryGiven = (pWeapon->UsesClipsForAmmo2()) ? pWeapon->m_iClip2 : pWeapon->GetSecondaryAmmoCount(); int takenPrimary = GiveAmmo( primaryGiven, pWeapon->m_iPrimaryAmmoType); int takenSecondary = GiveAmmo( secondaryGiven, pWeapon->m_iSecondaryAmmoType);
To read:
int primaryGiven = (pWeapon->UsesClipsForAmmo1()) ? pWeapon->m_iClip1 : pWeapon->GetPrimaryAmmoCount(); int secondaryGiven = (pWeapon->UsesClipsForAmmo2()) ? pWeapon->m_iClip2 : pWeapon->GetSecondaryAmmoCount(); // Don't give 30 magazines for picking up a weapon // with 30 bullets. if (primaryGiven > 0) primaryGiven = 1; if (secondaryGiven > 0) secondaryGiven = 1; int takenPrimary = GiveAmmo( primaryGiven, pWeapon->m_iPrimaryAmmoType); int takenSecondary = GiveAmmo( secondaryGiven, pWeapon->m_iSecondaryAmmoType);
Now you will receive one magazine, instead of 30. While this fix has the potential to add some bullets into the game, it is better than nothing. A better fix would require a system where you can save magazines without throwing them away.
You will notice, that the game will still grant you 30 or more bullets if you pick up an ammo crate. Now go to the items.h and mod this part to your liking. You will receive the amount of full magazines, you specify here. Whenever you pick up an ammo crate.
#define SIZE_AMMO_PISTOL 12 #define SIZE_AMMO_PISTOL_LARGE 100 #define SIZE_AMMO_SMG1 30 #define SIZE_AMMO_SMG1_LARGE 225 #define SIZE_AMMO_AR2 20 #define SIZE_AMMO_AR2_LARGE 100 #define SIZE_AMMO_RPG_ROUND 1 #define SIZE_AMMO_SMG1_GRENADE 1 #define SIZE_AMMO_BUCKSHOT 20 #define SIZE_AMMO_357 6 #define SIZE_AMMO_357_LARGE 20 #define SIZE_AMMO_CROSSBOW 6 #define SIZE_AMMO_AR2_ALTFIRE 1
You get some ammo at the start. That should be modded as well. Go to the hl2mp_player.cpp and look up the GiveDefaultItems procedure. Mod the part below to your liking. You will get the specified amount of magazines at start.
CBasePlayer::GiveAmmo( 255, "Pistol"); CBasePlayer::GiveAmmo( 45, "SMG1"); CBasePlayer::GiveAmmo( 1, "grenade" ); CBasePlayer::GiveAmmo( 6, "Buckshot"); CBasePlayer::GiveAmmo( 6, "357" );
Ever noticed, that the game auto-reloads your gun if you holster it? This is not so good, if you have this magazine system. To remove this go to the weapon_hl2mpbasehlmpcombatweapon.cpp and find the ItemHolsterFrame procedure. Comment out the
FinishReload();
Line and you are good.
Finally, it is not realistic to hold 200 magazines. Decrease this value in hl2mp_gamerules.cpp. At the end of the file there is an AmmoDef part like the one below.
def.AddAmmoType("AR2", DMG_BULLET, TRACER_LINE_AND_WHIZ, 0, 0, 60, BULLET_IMPULSE(200, 1225), 0 );
The 60 shows the max amount of ammo, the player can hold. If you change it to 5 then you can have maximum 5 reloads. You are now finished! It would take more tinkering to have a true magazine system, which does not throw away the used magazines.
Idea! I was reading this and started to think that you can actually make this work by just modifying magazine-reloading weapons to remove ammo amount of new magazine(GetMaxClip1()) and just modify hud to shot remaining ammo/30 or leave it as it is.