Raised This Month: $51 Target: $400
 12% 

listening for events an get their datas.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Fix
Member
Join Date: Jun 2005
Old 12-17-2005 , 15:23   listening for events an get their datas.
Reply With Quote #1

im listening for a player_say event and i need the data (uid, text) for opening ingame menus with a say command.

if i start a dedicated source server and i join the server it works fine, if i type my command it shows the ingame menu.
but if i reconnect the server, the user id of the event increases each time.

i get the data like this:

Quote:
KeyValues *pValue = event->GetFirstValue();
int id=pValue->GetInt();

KeyValues * pKey=pValue->GetNextKey();
const char * s=pKey->GetString();
but it works only the first time i connect my dedicated server. why?

thx 4 help!
Fix is offline
Send a message via ICQ to Fix Send a message via MSN to Fix
Knagg0
SourceMod Donor
Join Date: Dec 2005
Location: Germany
Old 12-17-2005 , 16:08  
Reply With Quote #2

mhh... i don't know what you're doing there...

try that:

Code:
const char *pName = event->GetName();

if(FStrEq(pName, "player_say")) {

	int userid = event->GetInt("userid");
	char *pText = event->GetString("text");

}
sry about my bad english
Knagg0 is offline
Fix
Member
Join Date: Jun 2005
Old 12-17-2005 , 17:36  
Reply With Quote #3

lol did i ever say that i know what im doing here? i dont remeber anymore.
i think valves documentation for creating server plugins is definitely useless!

p.s. your code works but i have the same problem!

Client =![A-Team]!= web@gent connected (192.168.0.134:27006).
=![A-Team]!= web@gent: avp_settings
CEmptyServerPlugin::FireGameEvent: Got event "player_say"

works fine... ok retry

Client =![A-Team]!= web@gent connected (192.168.0.134:27006).
=![A-Team]!= web@gent: avp_settings
CEmptyServerPlugin::FireGameEvent: Got event "player_say"
SV_BroadcastMessage: Recipient Filter for message type 23 (reliable: no, init: no) with bogus client index (2) in list of 1 clients

ok retry

Client =![A-Team]!= web@gent connected (192.168.0.134:27006).
=![A-Team]!= web@gent: avp_settings
CEmptyServerPlugin::FireGameEvent: Got event "player_say"
SV_BroadcastMessage: Recipient Filter for message type 23 (reliable: no, init: no) with bogus client index (3) in list of 1 clients

the user index i get from the event increases each i reconnect the server!
i dont understand this!

thx 4 help
Fix is offline
Send a message via ICQ to Fix Send a message via MSN to Fix
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 12-17-2005 , 18:58  
Reply With Quote #4

If u really want us to debug this, post ALL code that referances the variable(s) you use for the index.
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
Fix
Member
Join Date: Jun 2005
Old 12-18-2005 , 03:13  
Reply With Quote #5

Code:
//---------------------------------------------------------------------------------
// Purpose: called when an event is fired
//---------------------------------------------------------------------------------
void CEmptyServerPlugin::FireGameEvent( KeyValues * event )
{
	const char * name = event->GetName(); 
	Msg( "CEmptyServerPlugin::FireGameEvent: Got event \"%s\"\n", name );
	if(FStrEq(name,"player_say"))
	{
		int id = event->GetInt("userid");

		/*KeyValues *pValue = event->GetFirstValue();
		int id=pValue->GetInt();

	    KeyValues *	pKey=pValue->GetNextKey();
		const char * s=pKey->GetString();*/

		if(FStrEq(event->GetString("text"),"avp_settings"))
		{
			createmenu(id-1,3,"AvP Settings\n--------------------\n1.Change Race\n2.Reset XP\n3.Exit","settings_main");
		}
}
but look, the first time it works, the 2nd time
...with bogus client index (2) in list of 1 clients
the 3rd time
...with bogus client index (3) in list of 1 clients

the id i get from the event is wrong!
Fix is offline
Send a message via ICQ to Fix Send a message via MSN to Fix
Knagg0
SourceMod Donor
Join Date: Dec 2005
Location: Germany
Old 12-18-2005 , 03:55  
Reply With Quote #6

post the code from the createmenu function... ;)

i think you need the index and not the userid...

Code:
const int GetIndexFromID(const int id) {

	edict_t *pEntity = NULL;

	for(int i = 1; i <= maxplayers; i++) {
		pEntity = engine->PEntityOfEntIndex(i);
		if(!pEntity || pEntity->IsFree()) continue;
		if(engine->GetPlayerUserId(pEntity) == id) return i;
	}

	return 0;
}

...

void CEmptyServerPlugin::FireGameEvent(KeyValues * event)  {

  const char *name = event->GetName();
   
  if(FStrEq(name, "player_say")) {

    const char *text = event->GetString("text");

    if(FStrEq(text, "avp_settings")) {

      const int index = GetIndexFromID(event->GetInt("userid"));
      f(index < 1) return;

      createmenu(index, 3, "AvP Settings\n--------------------\n1.Change Race\n2.Reset XP\n3.Exit", "settings_main");
    }
  }
}
Knagg0 is offline
Fix
Member
Join Date: Jun 2005
Old 12-18-2005 , 05:02  
Reply With Quote #7

lol wheres the difference between the user id and the index? Oo

ok here the code of the a bit complicated createmenu() function

Code:
void createmenu(int userid,int options,char const *content,char const *name)
{
	int i,n,pot,pot_options;
	pot=0;
	pot_options=0;
	for(i=0;i<(options+1);++i)
	{
		pot=0;
		for(n=0;n<i;++n)
		{
			if(n==0)
			{
				pot=1;
			}
			else
			{
			 
				pot=pot*2;
			}
		}
		pot_options=pot_options+pot;
	}

	MRecipientFilter filter;
    filter.AddRecipient(userid);
    bf_write *pBuffer = engine->UserMessageBegin( &filter, 10 );
	
    pBuffer->WriteShort( pot_options );
    pBuffer->WriteChar( -1 );
    pBuffer->WriteByte( false );
	pBuffer->WriteString( content );
    engine->MessageEnd();
	Q_snprintf(actual_menu,sizeof(actual_menu),name);
}
p.s.

Code:
void CEmptyServerPlugin::ClientPutInServer( edict_t *pEntity, char const *playername )
{
	createmenu(engine->IndexOfEdict(pEntity),4,"Race Choice\n---------------\n1.Alien\n2.Predator\n3.Human\n4.Previous","race_choice");
}
that works fine!
Fix is offline
Send a message via ICQ to Fix Send a message via MSN to Fix
Knagg0
SourceMod Donor
Join Date: Dec 2005
Location: Germany
Old 12-18-2005 , 05:41  
Reply With Quote #8

yes, u need the index not the userid...
use the code that i posted above ;)

my english is to bad to explain whats the difference

Code:
int maxplayers = 0;

...

void CEmptyServerPlugin::ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) {
	maxplayers = clientMax;
}
or use gpGlobals->maxClients...
Knagg0 is offline
jeanlepail
Member
Join Date: Nov 2005
Location: Paris France
Old 12-18-2005 , 05:52  
Reply With Quote #9

thanks now i can finish my Tk Management !

in create menu what is the pot_count ?

number of options or

0^2+1^2......
__________________
TK's Management : Finish
Bet Plugin : 90 %
jeanlepail is offline
Send a message via AIM to jeanlepail Send a message via MSN to jeanlepail
Knagg0
SourceMod Donor
Join Date: Dec 2005
Location: Germany
Old 12-18-2005 , 06:03  
Reply With Quote #10

@jeanlepail: here is the code that i use... maybe it will help you

Code:
#define MENU_KEY_1 (1<<0)
#define MENU_KEY_2 (1<<1)
#define MENU_KEY_3 (1<<2)
#define MENU_KEY_4 (1<<3)
#define MENU_KEY_5 (1<<4)
#define MENU_KEY_6 (1<<5)
#define MENU_KEY_7 (1<<6)
#define MENU_KEY_8 (1<<7)
#define MENU_KEY_9 (1<<8)
#define MENU_KEY_0 (1<<9)

void ShowMenu(const char *text, const int keys, const int index, const int time) {

	MRecipientFilter filter;

	if(index < 1) filter.AddAllPlayers(maxplayers);
	else filter.AddRecipient(index);

	bf_write *pWrite = engine->UserMessageBegin((IRecipientFilter *)&filter, 10);
	pWrite->WriteShort(keys);
	pWrite->WriteChar(time);
	pWrite->WriteByte(false);
	pWrite->WriteString(text);

	engine->MessageEnd();
}


ShowMenu("Test Menu\n \n1. Test 1\n2. Test 2\3. Test 3\n \n0. Exit", MENU_KEY_1 + MENU_KEY_2 + MENU_KEY_3 + MENU_KEY_0, index, -1);
Knagg0 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 06:28.


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