Raised This Month: $ Target: $400
 0% 

Show an in game menu with textbox


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hendrikswa
Junior Member
Join Date: Oct 2006
Old 10-30-2006 , 15:12   Show an in game menu with textbox
Reply With Quote #1

I would like to display a form to the player on the client that takes text input. Is this possible? I've done this with HL2DM before, but that was done with a VGUI form on the client side.

I wonder if the Type_File option from the MOTD tutorial isn't what I need, but I can't even get an example to work. If someone can place an updated tutorial on how to do a MOTD that guy will be everybody's hero!

This is what I've got for the MOTD message. It compiles, but it just does nothing. I've put a breakpoint in and it does get called

Please help me!! I've been trying to do this for the last month.

Code:
 
void SamplePlugin::ClientPutInServer(edict_t *pEntity, char const *playername)
{
ShowMOTD( "http://www.yahoo.com", "Yahoo.com !", 2, "", pEntity );
META_LOG(g_PLAPI, "ClientPutInServer called: pEntity=%d, playername=%s", pEntity ? m_Engine->IndexOfEdict(pEntity) : 0, playername);
RETURN_META(MRES_IGNORED);
}
 
 
void SamplePlugin::ShowMOTD(const char* lpcMsg, const char* lpcTitle, int iType, const char* lpcCmd, edict_t *pEntity){
KeyValues* kv = new KeyValues("data");

kv->SetString("title", lpcTitle); // info panel title
if ( iType == 1 )
{
kv->SetString("type", "1"); // show userdata from stringtable entry 
}
else if ( iType == 2 )
{
kv->SetString("type", "2"); // show userdata from stringtable entry 
}
else if ( iType == 3 )
{
kv->SetString("type", "4"); // show userdata from stringtable entry 
}
else if ( iType == 4 )
{
kv->SetString("type", "4"); // show userdata from stringtable entry 
}
// TYPE_TEXT = 0, // just display this plain text
// TYPE_INDEX, // lookup text & title in stringtable
// TYPE_URL, // show this URL
// TYPE_FILE, 
kv->SetString("msg", lpcMsg); // use this stringtable entry
if(lpcCmd && *lpcCmd)
kv->SetString("cmd", lpcCmd);// exec this command if panel closed
ShowViewPortPanel(pEntity, "info", true, kv);
kv->deleteThis();
}
 
 
void SamplePlugin::ShowViewPortPanel(edict_t* pEdict, const char* name, bool bShow, KeyValues* data){
int count = 0;
KeyValues *subkey = NULL;
if(data){
subkey = data->GetFirstSubKey();

while(subkey){
count++;

subkey = subkey->GetNextKey();
}
subkey = data->GetFirstSubKey(); // reset 
}
MRecipientFilter filter;
filter.AddRecipient(m_Engine->IndexOfEdict(pEdict));
bf_write *pBuffer = m_Engine->UserMessageBegin( &filter, 10 );

pBuffer->WriteString(name); 
pBuffer->WriteByte(bShow ? 1 : 0); 
pBuffer->WriteByte(count);
while(subkey){
pBuffer->WriteString(subkey->GetName());
pBuffer->WriteString(subkey->GetString());

subkey = subkey->GetNextKey();
}
m_Engine->MessageEnd();
}
hendrikswa is offline
sslice
Senior Member
Join Date: Feb 2005
Location: Texas, USA
Old 10-30-2006 , 16:21   Re: Show an in game menu with textbox
Reply With Quote #2

The VGUIMenu user message no longer has an index of 10. In fact, I don't even know what the index of it is. The best way to use it is determine the index at runtime if you don't want your plugin to break in future engine updates.

Basically, you use IServerGameDLL::GetUserMessageInfo() to loop through all user messages until you find the one you need.
Code:
	int GetUserMessageIndex(const char *pszName)
	{
		char name [128];
		int size = 0;

		for (int x = 1; x != 22; ++x)
		{
			serverdll->GetUserMessageInfo(x, name, 128, size);
			if (size && strcmp(pszName, name) == 0)
			{
				return x;
			}
		}

		return 0;
	}
Now, instead of calling this everytime ShowViewPortPanel() is called, you would find the index when the plugin loads and store it in a global variable since it will not change while the server is running.

In this case, you would do something like:
Code:
g_vguiMenuIndex = GetUserMessageIndex("VGUIMenu");

I'm not sure how you'll end up getting data from this, though... sure you could have a form but how would you receive that data?

Last edited by sslice; 10-30-2006 at 16:26.
sslice is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 14:14.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode