|
|
|
Here I will show how you could implement an experience system, my example uses the experience to augument damage done when you inflict some, it could also be used to increase running speed and/or jumping height/distance, which I will show examples of how to do here. Old code is yellow, new code is red. First off we open up the mp.dll project and open the file player.h, in the class definition of CBasePlayer (under public:, around line 76), we add: float m_fExperience; // the experience the player has so far. Then we open up player.cpp and jump down to around line 417 or so (in TakeDamage): CBaseEntity *pAttacker = CBaseEntity::Instance(pevAttacker); // MODIFIED CBasePlayer *peAttacker = (CBasePlayer*)pAttacker; flDamage = flDamage * peAttacker->m_fExperience; // MODIFIED Then we open up multiplay_gamerules.cpp and jump down to around line 434 (in PlayerSpawn) addDefault = TRUE; // MODIFIED if (!pPlayer->m_fExperience) { // if experience isnt defined, we define one.. pPlayer->m_fExperience = 1.00; } // MODIFIED Then we jump down to around line 503 (same file), which is under PlayerKilled: if ( pVictim->pev == pKiller ) { // killed self pKiller->frags -= 1; //MODIFIED peKiller->m_fExperience = peKiller->m_fExperience * 0.9; //MODIFIED } And then a few lines later (around line 509), still under PlayerKilled: pKiller->frags += IPointsForKill( peKiller, pVictim ); // MODIFIED pVictim->m_fExperience = pVictim->m_fExperience * 0.9; peKiller->m_fExperience = peKiller->m_fExperience * 1.1; // MODIFIED Now.. This should give you an experience system that gives you more experience when you kill someone, and lowers it if you die or suicide, lets make the person run faster if they are experienced shall we ? :) (for brownie points perhaps ? lol) We go down to the end of PreThink in player.cpp (around line 2242): // MODIFIED pev->velocity.x = pev->velocity.x * m_fExperience; pev->velocity.y = pev->velocity.y * m_fExperience; // MODIFIED } If we wanted to for example implement a different increase of experience depending on what player class you kill (if you have classes that is..), you would do it under PlayerKilled, might look something like this (remember to define the things in CAPS, and m_iClass): pKiller->frags += IPointsForKill( peKiller, pVictim ); // MODIFIED if (pVictim->m_iClass == PLAYER_CLASS_NORMAL) { pVictim->m_fExperience = pVictim->m_fExperience * 0.9; } else if (pVictim->m_iClass == PLAYER_CLASS_SCOUT) { pVictim->m_fExperience = pVictim->m_fExperience * 0.95; } else if (pVictim->m_iClass == PLAYER_CLASS_HEAVY) { pVictim->m_fExperience = pVictim->m_fExperience * 0.8; } // This would lower experience for the person who died varying on their class... if (peKiller->m_iClass == PLAYER_CLASS_NORMAL) { peKiller->m_fExperience = peKiller->m_fExperience * 1.1; } else if (peKiller->m_iClass == PLAYER_CLASS_SCOUT) { peKiller->m_fExperience = peKiller->m_fExperience * 1.2; } else if (peKiller->m_iClass == PLAYER_CLASS_HEAVY) { peKiller->m_fExperience = peKiller->m_fExperience * 1.05; } // and this would increase the experience for the killer... // MODIFIED
Any questions or suggestions should be sent to me:
raptor3@hotmail.com