|
|
|
Editor: RED is new, YELLOW is old. I have noticed that many mods now want a money system like cstrike, so here is a tutorial on how! First we need a variable to hold the amount of money a person has, go into player.h and right above: int m_iPlayerSound; Put: int m_iMoneyAmount; That variable will hold the amount of money a person has. We need to give the person money for certain things like when they kill someone or they get killed. Open up player.cpp and go to the function CBasePlayer::Killed right above the lines: SetThink(PlayerDeathThink); pev->nextthink = gpGlobals->time + 0.1; Put the line m_iMoneyAmount += 100; That gives the money to the person when they die. Open up client.cpp and go to the function ClientKill Right below pl->Killed( pev, GIB_NEVER ); Put pl->m_iMoneyAmount -= 100; That will subtract $100 because a person killed themselves. Now to give money to a person for killing someone else. Open up multiplay_gamerules.cpp and go to the function IPointsForKill and right above: return 1; Put the line pAttacker->m_iMoneyAmount += 500; That will give the killer $500. Now all that money is nothing unless you can buy something with it, so open up teamplay_gamerules.cpp and right below #include "game.h" Put extern int gmsgShowMenu; void ShowMenu(CBasePlayer *pPlayer, int bitsValidSlots, int nDisplayTime, BOOL fNeedMore, char pszText[500]) { MESSAGE_BEGIN( MSG_ONE, gmsgShowMenu, NULL, pPlayer ->pev); WRITE_SHORT( bitsValidSlots); WRITE_CHAR( nDisplayTime ); WRITE_BYTE( fNeedMore ); WRITE_STRING (pszText); MESSAGE_END(); } Editor: This isnt the complete menu code. Read the menu tutorial at Wavelength. That will allow us to show a menu to buy the weapons. Go to the clientcommand function right above return FALSE; Put else if (FStrEq(pcmd, "buy" )) { ShowMenu(pPlayer, 0x1F, 20, 0, "#buy_menu"); pPlayer->m_iMenu = 1; return TRUE; } That will show the menu, there is a variable there that says what menu it is. Open up player.h and right above or below: m_iMoneyAmount; Put m_iMenu; I use that variable so I can have different things happen with each different menu. Now back to teamplay_gamerules.cpp the clientcommand function. Under int slot = atoi( CMD_ARGV(1) ); Put if(pPlayer->m_iMenu == 1) { switch(slot) { case 1: if(pPlayer->m_iMoneyAmount <= 199) return TRUE; pPlayer->GiveNamedItem( "weapon_python" ); pPlayer->m_iMoneyAmount -= 200; break; case 2: if(pPlayer->m_iMoneyAmount <= 399) return TRUE; pPlayer->GiveNamedItem( "weapon_shotgun" ); pPlayer->m_iMoneyAmount -= 400; break; case 3: if(pPlayer->m_iMoneyAmount <= 599) return TRUE; pPlayer->GiveNamedItem( "weapon_9mmAR" ); pPlayer->m_iMoneyAmount -= 600; break; case 4: if(pPlayer->m_iMoneyAmount <= 799) return TRUE; pPlayer->GiveNamedItem( "weapon_handgrenade" ); pPlayer->m_iMoneyAmount -= 800; break; case 5: if(pPlayer->m_iMoneyAmount <= 999) return TRUE; pPlayer->GiveNamedItem( "weapon_crossbow" ); pPlayer->m_iMoneyAmount -= 1000; break; } } That will check to see if the menu is the correct one (the one to give weapons). Then it will see what number the person typed in and for that number it will check to see if they have enough money and if they do have enough money it gives the person the weapon and subtracts its amount from the amount of money the person has. This tutorial is real basic, and does not go in to any detail, it definatly needs to be improved! Good luck =)
Any questions or suggestions should be sent to me: