|
|
|
New Code = Cyan Original Half-Life Code = Red Deleted Half-Life Code = YellowWell this is my second tutorial, This tutorial will teach you how to have a different max armor amount depending on what class you are using. You have seen this if you have ever played Team Fortress, the snipers max is 90, the HW Guy max is 300, etc, etc. Well lets get right to it.
Open up item.h and jump to line 22. void Spawn( void ); // Begin Neo_Matrix int ReturnMaxArmor ( int ); // Will Return Max Armor Value // End Neo_MatrixWhat we have just done is added declared a new function to the CItem Class. We used an integer because it will return the max armor depending on the class. And it takes an integer value to determine, which class you are. Now lets go code ReturnMaxArmor.
Now open up item.cpp and jump to line 217. void Precache( void ) { PRECACHE_MODEL ("models/w_battery.mdl"); PRECACHE_SOUND( "items/gunpickup2.wav" ); } // Begin Neo_Matrix // Function for Returning the Max Armor int ReturnMaxArmor(int ClassInt) // ClassInt is equal to m_iPlayerClass { if (ClassInt == 1) // If Spy Class Max Armor is 50 { return (50); // Return 50 as max } else if (ClassInt == 2) // If Sub-Machine Gun Class Max Armor is 75 { return (75); // Return 75 as max } else // Else { return (100); // Return default of 100 } } // End Neo_MatrixWe have just added the ReturnMaxArmor Function. What we have declared is if spy have low armor amount of 50 and if sub machine gun to have 75. You can plug in any numbers here that will fit in the integer form. Else returned the default value. You can also put instead of 100, MAX_NORMAL_BATTERY which is defined in weapons.h. Now wherever MAX_NORMAL_ARMOR was called we must change it to ReturnMaxArmor.
Now jump to line 239. if ((pPlayer->pev->armorvalue < MAX_NORMAL_BATTERY ) && (pPlayer->pev->weapons & (1<< WEAPON_SUIT))) Change it to: if ((pPlayer->pev->armorvalue < ReturnMaxArmor(pPlayer->m_iPlayerClass) ) && (pPlayer->pev->weapons & (1<< WEAPON_SUIT))) // We are calling the ReturnMaxArmor function and have made // pPlayer->m_iPlayerClass equal to ClassInt Now jump to line 246. pPlayer->pev->armorvalue += gSkillData.batteryCapacity; pPlayer->pev->armorvalue = min(pPlayer->pev->armorvalue, MAX_NORMAL_BATTERY ); Change it to: pPlayer->pev->armorvalue += gSkillData.batteryCapacity; pPlayer->pev->armorvalue=min(pPlayer->pev->armorvalue, ReturnMaxArmor(pPlayer->m_iPlayerClass)); /* We are calling the ReturnMaxArmor function and have made pPlayer->m_iPlayerClass equal to ClassInt */ Now jump to line 257 to make the final change. // Suit reports new power level // For some reason this wasn't working in release build -- round it. pct = (int)( (float)(pPlayer->pev->armorvalue * 100.0) * (1.0/MAX_NORMAL_BATTERY) + 0.5); pct = (pct / 5); Change it to: // Suit reports new power level // For some reason this wasn't working in release build -- round it. pct = (int)( (float)(pPlayer->pev->armorvalue * 100.0) * (1.0/ ReturnMaxArmor(pPlayer->m_iPlayerClass)) + 0.5); pct = (pct / 5); // We are calling the ReturnMaxArmor function and // have made pPlayer->m_iPlayerClass equal to ClassIntWhat we have just done is changed wherever MAX_NORMAL_BATTERY to call ReturnMaxArmor instead. We inserted pPlayer->m_iPlayerClass into it and made it equal to ClassInt when we declared the function and had it set up as int ReturnMaxArmor (int ClassInt). What this is really saying is to return an int wherever ReturnMaxArmor is called. But we have int ClassInt and then use it in determining which call they are. When we put pPlayer->m_iPlayerClass into the parenthesis it is actually saying make ( ClassInt = pPlayer->m_iPlayerClass ). That should be known if you have knowledge of C++ and OOP.
Any questions or suggestions should be sent to me:
JeDiGuy98@aol.com