Go Back   Steam Users' Forums > Steam Tool Discussions > Source Coding

Reply
 
Thread Tools Display Modes
Old 03-27-2012, 02:10 AM   #1
Jeremy__
 
Join Date: Mar 2012
Reputation: 1
Posts: 38
How do I programatically load a map?

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:

Code:
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.

Last edited by Jeremy__: 03-27-2012 at 02:20 AM.
Jeremy__ is offline  
Reply With Quote
Old 03-27-2012, 02:23 AM   #2
tingtom
 
 
 
Join Date: Mar 2011
Reputation: 38
Posts: 388
send a command to server ( map <mapname> )?
tingtom is offline   Reply With Quote
Old 03-27-2012, 03:11 AM   #3
hello123
 
Join Date: Aug 2011
Reputation: 20
Posts: 354
Quote:
Originally Posted by tingtom View Post
send a command to server ( map <mapname> )?
Or just for a new map, call the hl2mp_gamerules "ChangeLevel" function.
hello123 is offline   Reply With Quote
Old 03-27-2012, 06:06 AM   #4
Jeremy__
 
Join Date: Mar 2012
Reputation: 1
Posts: 38
Quote:
Originally Posted by hello123 View Post
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.
Jeremy__ is offline   Reply With Quote
Old 03-27-2012, 10:51 AM   #5
durrchet
 
Join Date: Mar 2012
Reputation: 209
Posts: 909
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.
durrchet is offline   Reply With Quote
Old 03-27-2012, 12:49 PM   #6
tingtom
 
 
 
Join Date: Mar 2011
Reputation: 38
Posts: 388
Quote:
Originally Posted by Jeremy__ View Post
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
tingtom is offline   Reply With Quote
Old 03-27-2012, 01:18 PM   #7
Jeremy__
 
Join Date: Mar 2012
Reputation: 1
Posts: 38
Quote:
Originally Posted by tingtom View Post
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 .
Jeremy__ is offline   Reply With Quote
Reply

Go Back   Steam Users' Forums > Steam Tool Discussions > Source Coding


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -7. The time now is 04:08 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site Content Copyright Valve Corporation 1998-2014, All Rights Reserved.