So, how would I format the message acording to the number of substrings? I know that I can find their number with get_msg_args(), but how to add them in the message?
PHP Code:
new szSubString[get_msg_args()][32] // This is invalid, because it isn't a constant expression
This has been bugging me for a long time and I still don't have a clue how to do it. I just need the %s parameters to be automatically replaced by the respective substrings.
You need to rebuild the message being sent by mapping out what the
final message text is being processed by the client. In your example
here, the bomb drop TextMsg #Game_bomb_drop is sent to the
client, who then looks up the entry in cstrike/titles.txt which is another
localized string: #Cstrike_TitlesTXT_Game_bomb_drop which
is then looked up in resource/cstrike_english.txt .
Simplify this process so that you get the final msg from the TextMsg
by using you own function to map out the messages being sent.
CS doesn't seem to use more than 3 of the 4 optional substrings BTW.
The code below is untested, but you get the picture.
Spoiler
Code:
new g_szMsgs[3][]=
{
"#Game_bomb_drop",
"#Game_bomb_pickup",
"#Game_radio"
}
public msgTextMsg(iMessage, iDest, id)
{
static szMessage[256], szText1[64], szText2[64], szText3[64]
get_msg_arg_string( 2, szMessage, charsmax(szMessage) )
if ( get_msg_args() > 2 )
{
get_msg_arg_string( 3, szText1, charsmax(szText1) )
if ( get_msg_args() > 3 )
{
get_msg_arg_string( 4, szText2, charsmax(szText2) )
if ( get_msg_args() > 4 )
{
get_msg_arg_string( 5, szText3, charsmax(szText3) )
}
}
}
new index = GetIndexForMsg( szMessage )
if ( index == -1)
{
// Log error yada
return PLUGIN_CONTINUE
}
switch(index)
{
// You can use a dictionary file here to restore the localized string functionality,
// here english entry would be:
// GAME_BOMB_DROP = %s dropped the bomb.
// case 0: format(szMessage, charsmax(szMessage), "%L", LANG_PLAYER, "GAME_BOMB_DROP", szText1 )
case 0: format( szMessage, charsmax(szMessage), "%s dropped the bomb.", szText1 )
case 1: format( szMessage, charsmax(szMessage), "%s picked up the bomb.", szText1 )
case 2: format( szMessage, charsmax(szMessage), "%s (RADIO): %s", szText1, szText2 )
}
set_hudmessage(bla bla)
show_hudmessage(id, szMessage)
return PLUGIN_CONTINUE // ?? send or override TextMsg
}
stock GetIndexForMsg( const szText[] )
{
if ( strlen(szText) == 0 ) return -1
new iRet = -1
for( new i = 0; i < sizeof g_szMsgs; i++)
{
if (equal( szText, g_szMsgs[i] ))
{
iRet = i
break
}
}
return iRet
}
So basically I'll need to check the number of parameters 1 by 1 and form the messages with all the checks again. I guess I can do that if there's no easier way.