Raised This Month: $ Target: $400
 0% 

[HOWTO] Make a nice say-hook


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
vancelorgin
Senior Member
Join Date: Dec 2004
Location: san frandisco
Old 01-06-2005 , 06:03  
Reply With Quote #5

I like the concept. Like I said I was trying to do this with slot commands but those are apparently done differently. I don't, however, use it for say. The code for the say command is right in the sdk .

Code:
const ConVar* mp_teamplay = NULL; 

void Handle_Say(int iMode){
	if(!mp_teamplay)
		mp_teamplay = cvar->FindVar("mp_teamplay");

	if(!mp_teamplay)
		return;

	edict_t* pEdict = engine->PEntityOfEntIndex(g_nCommandClientIndex + 1);

	CPlayer* pPlayer = CPlayer::Find(pEdict);

	int j;
	char* p;
	char text[AMP_MAX_LINE_LEN];
	char szTemp[AMP_MAX_LINE_LEN];
	
	const char* pcmd = engine->Cmd_Argv(0);
	int argc = engine->Cmd_Argc();

	if(argc == 0)
		return;

	if(!stricmp(pcmd, "say") || !stricmp(pcmd, "say_team") || !stricmp(pcmd, "say_admin"))
		if(argc >= 2)
			p = (char *)engine->Cmd_Args();
		else
			return; // say with a blank message, nothing to do
	
	else{  // Raw text, need to prepend argv[0]
		if(argc >= 2)
			_snprintf(szTemp,sizeof(szTemp), "%s %s", (char*)pcmd, (char*)engine->Cmd_Args());
		else
			_snprintf(szTemp,sizeof(szTemp), "%s", (char*)pcmd); // Just a one word command, use the first word...sigh
		
		p = szTemp;
	}

	p = CheckChatText(p); // make sure the text has vlaid content

	if(!p)
		return;

	if(*p == CONTROLCHAR && pPlayer)
		if(cmds.Execute(p, pEdict, true))
			return;
		else{
			msgs.SayTo(pEdict, "Invalid command \n");

			return;
		}

	const char* pszPrefix = NULL;

	if(iMode == 1)
		pszPrefix = "(TEAM) ";
	else if(iMode == 2)
		pszPrefix = "(ADMIN) ";

	if(pszPrefix && strlen( pszPrefix ) > 0)
		_snprintf(text, sizeof(text), "%s %s: ", pszPrefix, pPlayer? pPlayer->GetName() : "Server");
	else
		_snprintf(text, sizeof(text), "%s: ", pPlayer? pPlayer->GetName() : "Server");

	j = sizeof(text) - 2 - strlen(text);  // -2 for /n and null terminator
	
	if((int)strlen(p) > j)
		p[j] = 0;

	strncat(text, p, sizeof(text));

	if(iMode == 2){
		//admins only - player access levels are still being implimented
	}else
		msgs.SayFrom(pEdict, text, (mp_teamplay->GetInt() > 1));
}

CON_COMMAND_F(say, "Sends shit to everyone.", FCVAR_GAMEDLL){
	Handle_Say(0);
}

CON_COMMAND_F(say_team, "Sends shit to your team.", FCVAR_GAMEDLL){
	Handle_Say(1);
}

CON_COMMAND_F(say_admin, "Sends shit other nimdas.", FCVAR_GAMEDLL){
	Handle_Say(2);
}

COMMAND_(me, 0, "emote [<3 ltfxdude :]"){
	if(!pPlayer)
		return;

	std::string strText = VASTR(pPlayer->GetName());

	strText += " ";

	strText += cmds.Args();

	msgs.Say((char*)strText.c_str());
}
Thanks to my command manager all my commands are available through chat too. Woo-hah :/
__________________
Avoid like the plague.
vancelorgin is offline
 



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 07:19.


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