PDA

View Full Version : How do I programatically load a map?


Jeremy__
03-27-2012, 01:10 AM
I am trying to cause a particular vgui button to respond to a command by loading a map. I already have my vgui dialog setup, I need to write the OnCommand member function to respond to the command by loading a particular map though I am unable to find out how to do this with the source sdk.

Here is what I've got:


int CJNewGame::getCommandIndex(const char* sCommand)
{

int iCmdBuffer;

std::auto_ptr<char> sSig(new char[WINDOWNAME.length()]);

if(!sSig.get())
throw CJException(std::string("Memory allocation error."));

std::stringstream ssCommand(sCommand);

ssCommand.readsome(sSig.get(), WINDOWNAME.length());

if(std::string(sSig.get(), WINDOWNAME.length()).compare(WINDOWNAME) != 0)
throw CJException(std::string("Invalid signature possesed by command."));

if(!(ssCommand>>iCmdBuffer))
throw CJException(std::string("Unable to parse command ID parameter"));

return iCmdBuffer;
}

void CJNewGame::OnCommand(const char* sCommand)
{
try
{
switch(getCommandIndex(sCommand))
{
case CJNewGameCommands_Start:
throw CJException(std::string("Command not implemented."));
break;
default:
throw CJException(std::string("Unknown command index"));
}
}catch(CJException& e)
{
Warning("%s not parsing command '%s'; %s\n", WINDOWNAME.c_str(), sCommand, e.Reason.c_str());
}
}


Obviously, in the CHNewGameCommands_Start case I need to start loading the map.

tingtom
03-27-2012, 01:23 AM
send a command to server ( map <mapname> )?

hello123
03-27-2012, 02:11 AM
send a command to server ( map <mapname> )?
Or just for a new map, call the hl2mp_gamerules "ChangeLevel" function.

Jeremy__
03-27-2012, 05:06 AM
Or just for a new map, call the hl2mp_gamerules "ChangeLevel" function.
I'll look in to that, thanks.

@tingtop : The game is independant of a server. I was thinking of doing this though.

durrchet
03-27-2012, 09:51 AM
Use clientcmd, instead of server command.
And i believe, you cannot use gamerules, unless you logged into server, or the function is static, so it could be acessed without creating a new gamerules object clientside.

tingtom
03-27-2012, 11:49 AM
I'll look in to that, thanks.

@tingtop : The game is independant of a server. I was thinking of doing this though.

not sure but i think its client side aswell, and lol @ tingtop

Jeremy__
03-27-2012, 12:18 PM
not sure but i think its client side aswell, and lol @ tingtop

LOL I had to write your name five times before I ended up with it incorrectly - hard for me to remember your name somehow .