View Single Post
Eradicator
Junior Member
Join Date: Dec 2004
Location: Canada
Old 12-13-2004 , 16:48  
Reply With Quote #15

Here is my code that works. This is in ClientPutInServer:
Code:
   char msg[128];
	int index = engine->IndexOfEdict(pEntity);
	if (index)
	{
		MRecipientFilter mrf;
		bf_write *pWrite; 
		sprintf(msg,"Server is running: %s", plugin_name);
		mrf.AddPlayer(index);
		pWrite = engine->UserMessageBegin((IRecipientFilter *)&mrf,3); 
		pWrite->WriteString(msg); 
		engine->MessageEnd();
	}
And the AddPlayer function that I added to mosca's MRecipientFilter class:
Code:
void MRecipientFilter::AddPlayer(int index) 
{ 
	edict_t *pPlayer = engine->PEntityOfEntIndex(index); 
	if ( !pPlayer || pPlayer->IsFree()) { 
		return; } 
	m_Recipients.AddToTail(index); 
}
That entity check is unnecesarry and I'll probably remove it as it doesn't even really check if its a player and I can do that (and should) before calling mrf.AddPlayer(index) anyway (if not in ClientPutInServer that is...).
Fruch, I don't know what those extra WriteBytes are for? I didn't need them.
[edit]
I noticed the first character of the message gets cut off. Anyone know why?
Eradicator is offline
Send a message via MSN to Eradicator