View Full Version : dont get ingame menus with MRecipientFilter working!
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
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.
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
Instead of using IPlayerInfo and converting UserID to entity index, just get the index straight from pEntity with engine->IndexOfEdict(pEntity);
//---------------------------------------------------------------------------------
// 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 :(
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 );
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"
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!
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
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 );
What about g_EmptyServerPlugin?
why doesnt he compile?
look the quote
vBulletin® v3.8.7, Copyright ©2000-2024, vBulletin Solutions, Inc.