PDA

View Full Version : dont get ingame menus with MRecipientFilter working!


Fix
06-20-2005, 15:14
i made it after this tutorial: http://www.sourcewiki.org/wiki/index.php/Creating_an_in-game_menu_for_server_plugins#Creating_an_in-game_menu_for_server_plugins

but if i insert

if ( FStrEq( pcmd, "a_menu" ) )
{
IPlayerInfo *playerInfo = playerinfomanager->GetPlayerInfo(pEntity);
MRecipientFilter filter;
filter.AddRecipient(getIndexFromUserID(player Info->GetUserID()));
bf_write *pBuffer = engine->UserMessageBegin( &filter, 9 );
pBuffer->WriteShort( 7 ); //Sets how many options the menu has
pBuffer->WriteChar( -1 ); //Sets how long the menu stays open -1 for stay until option selected
pBuffer->WriteByte( false );
pBuffer->WriteString( "1.Assault Rifle\n2.AWP\n3.Exit" ); //The text shown on the menu
engine->MessageEnd();
return PLUGIN_STOP;
}

i cant compile anymore!

modX error LNK2019: Not dissolved external symbol "public: bool __ thiscall bf_write::WriteString(char const *)"(?WriteString@bf_write@@QAE_NPBD@Z), referred in function" public: virtual enum PLUGIN_RESULT __ thiscall CEmptyServerPlugin::ClientCommand(struct edict_t *)"(?ClientCommand@CEmptyServerPlugin@@UAE?AW4PL UGIN_RESULT@@PAUedict_t@@@Z)

modX error LNK2019: Not dissolved external symbol "public: void __ thiscall bf_write::WriteByte(int) "(?WriteByte@bf_write@@QAEXH@Z), referred in function" public: virtual enum PLUGIN_RESULT __ thiscall CEmptyServerPlugin::ClientCommand(struct edict_t *)"(?ClientCommand@CEmptyServerPlugin@@UAE?AW4PL UGIN_RESULT@@PAUedict_t@@@Z)

modX error LNK2019: Not dissolved external symbol "public: void __ thiscall bf_write::WriteChar(int) "(?WriteChar@bf_write@@QAEXH@Z), referred in function" public: virtual enum PLUGIN_RESULT __ thiscall CEmptyServerPlugin::ClientCommand(struct edict_t *)"(?ClientCommand@CEmptyServerPlugin@@UAE?AW4PL UGIN_RESULT@@PAUedict_t@@@Z)

modX error LNK2019: Not dissolved external symbol "public: void __ thiscall bf_write::WriteShort(int) "(?WriteShort@bf_write@@QAEXH@Z), referred in function" public: virtual enum PLUGIN_RESULT __ thiscall CEmptyServerPlugin::ClientCommand(struct edict_t *)"(?ClientCommand@CEmptyServerPlugin@@UAE?AW4PL UGIN_RESULT@@PAUedict_t@@@Z)

modX fatal error LNK1120: 4 not disolved external references

PM
06-20-2005, 15:19
Compile bitbuf.cpp from the sdk and link with it :D

If you are on MSVC IDE (the error messages suggest that), just add the file to the project.

Fix
06-20-2005, 15:39
thx it works now to compile, but the console says


] a_menu
SV_BroadcastMessage: Recipient Filter for message type 23 (reliable: no, init: no) with bogus client index (-1) in list of 1 clients

sslice
06-20-2005, 16:08
Instead of using IPlayerInfo and converting UserID to entity index, just get the index straight from pEntity with engine->IndexOfEdict(pEntity);

Fix
06-21-2005, 00:58
//---------------------------------------------------------------------------------
// Purpose: get player's indexes
//---------------------------------------------------------------------------------
//int getIndexFromUserID(int userid)
//{
// edict_t *player;
// IPlayerInfo *info;
// for(int i = 1; i <= maxplayers; i++)
// {
// player = engine->PEntityOfEntIndex(i);
// if(!player || player->IsFree() )
// continue;
// info = playerinfomanager->GetPlayerInfo(player);
//
// if(info->GetUserID() == userid)
// return i;
// }
//
// return -1;
//}

//---------------------------------------------------------------------------------
// Purpose: called when a client types in a command (only a subset of commands however, not CON_COMMAND's)
//---------------------------------------------------------------------------------
PLUGIN_RESULT CEmptyServerPlugin::ClientCommand( edict_t *pEntity )
{
const char *pcmd = engine->Cmd_Argv(0);

if ( !pEntity || pEntity->IsFree() )
{
return PLUGIN_CONTINUE;
}

if ( FStrEq( pcmd, "a_menu" ) )
{
//IPlayerInfo *playerInfo = playerinfomanager->GetPlayerInfo(pEntity);
MRecipientFilter filter;
filter.AddRecipient(engine->IndexOfEdict(pEntity));
bf_write *pBuffer = engine->UserMessageBegin( &filter, 9 );
pBuffer->WriteShort( 7 );
pBuffer->WriteChar( -1 );
pBuffer->WriteByte( false );
pBuffer->WriteString( "1.Assault Rifle\n2.AWP\n3.Exit" );
engine->MessageEnd();
return PLUGIN_STOP;
}
else if ( FStrEq( pcmd, "menuselect" ) )
{
const char *parameter = engine->Cmd_Argv(1);
if ( FStrEq( parameter, "1" ) )
{
engine->ClientCommand (pEntity, "buy m4a1;buy ak47;buy primammo;buy vesthelm;buy deagle;buy secammo;buy flashbang;buy hegrenade;buy flashbang");
}
else if ( FStrEq( parameter, "2" ) )
{
engine->ClientCommand (pEntity, "buy awp;buy primammo;buy vesthelm;buy deagle;buy secammo;buy flashbang;buy hegrenade;buy flashbang");
}
else if ( FStrEq( parameter, "3" ) )
{
engine->ClientPrintf(pEntity, "Menu Exited");
}
return PLUGIN_STOP;
}

return PLUGIN_CONTINUE;
}

if i now type a_menu nothing happens, no error, no menu :(

sslice
06-21-2005, 01:12
If you are running this in CS:S, you need to use UserMessage 10 instead of 9.

Example:

Use
bf_write *pBuffer = engine->UserMessageBegin( &filter, 10 );
Instead of...
bf_write *pBuffer = engine->UserMessageBegin( &filter, 9 );

Fix
06-21-2005, 12:16
hey ty you guys rule :D

but from where do you know such things?

and do you also know how to change the font's color?

and do you maybe know how to interpret command with variables? for example menu "string"

Fix
06-21-2005, 13:10
else if(FStrEq( pcmd, "msg" ))
{
char * msg;
Q_snprintf( msg, sizeof(msg), "%s \n", engine->Cmd_Args() );

mrf.AddAllPlayers( g_EmptyServerPlugin.myNumPlayers );
pWrite = engine->UserMessageBegin(&mrf,5); // 4 for HL2
pWrite->WriteByte( 4 ); // Centered TextMsg
pWrite->WriteString(msg); // Message
engine->MessageEnd();
}

->

j:\Source Mod\src\utils\modX\modX.cpp(396): error C2227: The left part of ' - > WriteString ' must show j:\Source Mod\src\utils\modX\modX.cpp(393) to class/structure/union: error C2065: ' g_EmptyServerPlugin ': not-defined designator j:\Source Mod\src\utils\modX\modX.cpp(393): error C2065: ' mrf ': not-defined designator j:\Source Mod\src\utils\modX\modX.cpp(393): error C2228: The left part of ' AddAllPlayers ' must a class/structure/union its j:\Source Mod\src\utils\modX\modX.cpp(393): error C2228: The left part of ' myNumPlayers ' must a class/structure/union its j:\Source Mod\src\utils\modX\modX.cpp(394): error C2065: ' pWrite ': not-defined designator j:\Source Mod\src\utils\modX\modX.cpp(395): error C2227: The left part of ' - > WriteByte ' must point to class/structure/union

but the ingame menu works andthe name of the plugin is EmptyServerPlugin!

sslice
06-21-2005, 13:16
else if(FStrEq( pcmd, "msg" ))
{
char * msg;
Q_snprintf( msg, sizeof(msg), "%s \n", engine->Cmd_Args() );

mrf.AddAllPlayers( g_EmptyServerPlugin.myNumPlayers );
pWrite = engine->UserMessageBegin(&mrf,5); // 4 for HL2
pWrite->WriteByte( 4 ); // Centered TextMsg
pWrite->WriteString(msg); // Message
engine->MessageEnd();
}

->

j:\Source Mod\src\utils\modX\modX.cpp(396): error C2227: The left part of ' - > WriteString ' must show j:\Source Mod\src\utils\modX\modX.cpp(393) to class/structure/union: error C2065: ' g_EmptyServerPlugin ': not-defined designator j:\Source Mod\src\utils\modX\modX.cpp(393): error C2065: ' mrf ': not-defined designator j:\Source Mod\src\utils\modX\modX.cpp(393): error C2228: The left part of ' AddAllPlayers ' must a class/structure/union its j:\Source Mod\src\utils\modX\modX.cpp(393): error C2228: The left part of ' myNumPlayers ' must a class/structure/union its j:\Source Mod\src\utils\modX\modX.cpp(394): error C2065: ' pWrite ': not-defined designator j:\Source Mod\src\utils\modX\modX.cpp(395): error C2227: The left part of ' - > WriteByte ' must point to class/structure/union

but the ingame menu works andthe name of the plugin is EmptyServerPlugin!


Don't forget to declare your variables. :wink:

else if(FStrEq( pcmd, "msg" ))
{
char msg[255];
Q_snprintf( msg, sizeof(msg), "%s \n", engine->Cmd_Args() );
MRecipientFilter mrf;
mrf.AddAllPlayers( g_EmptyServerPlugin.myNumPlayers );
bf_write *pWrite = engine->UserMessageBegin(&mrf,5); // 4 for HL2
pWrite->WriteByte( 4 ); // Centered TextMsg
pWrite->WriteString(msg); // Message
engine->MessageEnd();
}


Edit: For colored menus look here. http://forums.alliedmods.net/showthread.php?t=37645

Fix
06-21-2005, 13:33
he doesnt know g_EmptyServer plugin!
but
//
// The plugin is a static singleton that is exported as an interface
//
CEmptyServerPlugin g_EmtpyServerPlugin;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CEmptyServe rPlugin, IServerPluginCallbacks, INTERFACEVERSION_ISERVERPLUGINCALLBACKS, g_EmtpyServerPlugin );

sslice
06-22-2005, 10:35
What about g_EmptyServerPlugin?

Fix
06-22-2005, 13:26
why doesnt he compile?
look the quote

Fix
06-24-2005, 13:03
nobody knows anything?