Adding a new gametype
From CryWiki
| ||||||||||||||
Contents |
Adding a new gametype
Adding a new gametype/gamerule in C++ is pretty simple. We just have to register our gamerules and then do all the logic work in lua.
Registering the gamerules
Open GameFactory.cpp and scroll to the end. We can identify the gametypes known from Crysis in there. To add our gametype, add this:
#ifndef SP_DEMO pFramework->GetIGameRulesSystem()->RegisterGameRules("PowerStruggle", "GameRules"); pFramework->GetIGameRulesSystem()->AddGameRulesAlias("PowerStruggle", "ps"); pFramework->GetIGameRulesSystem()->AddGameRulesLevelLocation("PowerStruggle", "multiplayer/ps/"); #endif //spdemo // NEW CODE STARTS HERE // Register the gametype pFramework->GetIGameRulesSystem()->RegisterGameRules("MyGameType", "GameRules"); // Add an alias pFramework->GetIGameRulesSystem()->AddGameRulesAlias("MyGameType", "mgt"); // Set level location pFramework->GetIGameRulesSystem()->AddGameRulesLevelLocation("MyGameType", "multiplayer/mgt/"); // END }
We register our gamerules with RegisterGameRules, then we add an alias and a location for the levels. Next up is setting up the hud so it knows what to show/hide in our gametype.
Setting up the HUD
By now the gametype should work, but we might want some gametype-specific HUD elements. For that we need some adjustmens in Hud.cpp and HudEnums.h
enum EHUDGAMERULES { EHUD_SINGLEPLAYER, EHUD_INSTANTACTION, EHUD_POWERSTRUGGLE, EHUD_TEAMACTION, // NEW CODE STARTS HERE EHUD_MYGAMETYPE, //END };
And then in Hud.cpp, the GameRulesSet function:
void CHUD::GameRulesSet(const char* name) { EHUDGAMERULES gameRules = EHUD_SINGLEPLAYER; if(gEnv->bMultiplayer) { if(!stricmp(name, "InstantAction")) gameRules = EHUD_INSTANTACTION; else if(!stricmp(name, "PowerStruggle")) gameRules = EHUD_POWERSTRUGGLE; else if(!stricmp(name, "TeamAction")) gameRules = EHUD_TEAMACTION; // NEW CODE STARTS HERE else if(!stricmp(name, "MyGameType")) gameRules = EHUD_MYGAMETYPE; // END } if(m_currentGameRules != gameRules)//unload stuff { LoadGameRulesHUD(false); m_currentGameRules = gameRules; } LoadGameRulesHUD(true); }
case EHUD_TEAMACTION: // NEW CODE STARTS HERE case EHUD_MYGAMETYPE: // END if(load) { if(!m_animScoreBoard.IsLoaded()) { m_animScoreBoard.Load("Libs/UI/HUD_MultiplayerScoreboard_TDM.gfx"); SetFlashColor(&m_animScoreBoard); }
We're done with the C++ work now. All that is left is a simple .xml adjustment.
Add gametype to EntityScheduler
Add this to the EntityScheduler.xml file (extract the file from ZPatch1.pak Scripts/Network and put it in Crysis/Mods/<yourmod>/Game/Scripts/Network/)
<EntityScheduler> <!-- game rules --> <Class name="InstantAction" policy="rule"/> <Class name="TeamAction" policy="rule"/> <Class name="TeamInstantAction" policy="rule"/> <Class name="PowerStruggle" policy="rule"/> <!-- NEW CODE STARTS HERE --> <Class name="MyGameType" policy="rule"/> <!-- END --> <!-- actors -->
Now all that's left is scripting the actual gamelogic, which will not be covered here. Have a look around in the original scriptfiles to get started.
What's next
- Script the gamelogic in lua. The scriptfile should be located at Crysis/Mods/<yourmod>/Game/Scripts/GameRules/MyGameType.lua.
- Add the gametype in the flash files (your gametype won't show up in the create server screen)
- Make a level which supports the gametype
How to play
To play the new gametype either edit the server creation menu so you can select it when starting a map or enter the following to the console:
- con_restricted 0
- sv_gamerules MyGameType
- map multiplayer/mgt/YourMapNameHere s
Don't forget the trailing s or you'll get the singleplayer HUD and won't be able to spawn.
