View Single Post
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-23-2010 , 01:55   Re: Dynamic number of arguments in functions
Reply With Quote #4

For TextMsg i guess something like HLSDK would be more efficient.
Your tut is still usefull though.

PHP Code:
// Based on HLSDK ClientPrint and UTIL_ClientPrintAll from util.cpp
Util_ClientPrint(idiMsgDestszMessage[], szSubMessage1[] = ""szSubMessage2[] = ""szSubMessage3[] = ""szSubMessage4[] = "")
{
    
message_begin(id MSG_ONE_UNRELIABLE MSG_BROADCASTg_iTextMsg, .player=id)
    {
        
write_byte(iMsgDest)
        
write_string(szMessage)
        if( 
szSubMessage1[0] )
        {
            
write_string(szSubMessage1)
        }
        if( 
szSubMessage2[0] )
        {
            
write_string(szSubMessage2)
        }
        if( 
szSubMessage3[0] )
        {
            
write_string(szSubMessage3)
        }
        if( 
szSubMessage4[0] )
        {
            
write_string(szSubMessage4)
        }
    }
    
message_end()

Code:
void ClientPrint( entvars_t *client, int msg_dest, const char *msg_name, const char *param1, const char *param2, const char *param3, const char *param4 )
{
	MESSAGE_BEGIN( MSG_ONE, gmsgTextMsg, NULL, client );
		WRITE_BYTE( msg_dest );
		WRITE_STRING( msg_name );

		if ( param1 )
			WRITE_STRING( param1 );
		if ( param2 )
			WRITE_STRING( param2 );
		if ( param3 )
			WRITE_STRING( param3 );
		if ( param4 )
			WRITE_STRING( param4 );

	MESSAGE_END();
}
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 07-23-2010 at 01:57.
ConnorMcLeod is offline