Hi everyone , I'm new to amxx scripting and I'm learning by modifying others' plugins. The following code is modified from 'all chat' by ian.cammarata
what I want to do is , when players say a team message , the message will only show to specific player in a team , and other teammate won't see the message.
but when I say a team message , the game crashes and shows the error mentioned , where is my error?
PHP Code:
new g_PlayerTeam[33] // [ID] = TeammateID , text will only show to him
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_message( get_user_msgid("SayText"), "SayTextHandler" )
}
/*
...
// codes about g_PlayerTeam
...
*/
public SayTextHandler( msg_id, msg_dest, rcvr ){
console_print(0 , "Say Detected")
new str2[26]
get_msg_arg_string( 2, str2, 25 ) // ( String 1 )
if( equal( str2, "#Cstrike_Chat", 13 ) )
{
new str3[22]
get_msg_arg_string( 3, str3, 21 ) // ( String 2 )
if( !strlen( str3 ) )
{
new str4[101] // (String 3 , MsgContent)
get_msg_arg_string( 4, str4, 100 )
new sender = get_msg_arg_int( 1 ) // ( Byte 1 , SenderID)
if(g_PlayerTeam[sender] == -1) // Player don't have a Target to show message
{
console_print(0 , "HANDLED")
return PLUGIN_HANDLED
}
new bool:is_team_msg = !bool:equal( str2, "#Cstrike_Chat_All", 17 )
new sender_team = get_user_team( sender )
new bool:is_sender_spec = !bool:( 0 < sender_team < 3 )
if(is_team_msg && !is_sender_spec){
if( is_team_msg ) //Now we know it's team_msg
{
console_print(0 , "TeamMSG")
PrintTeamMsg(g_PlayerTeam[sender] , str4) // Show to Target ONLY
}
}
}
}
return PLUGIN_HANDLED
}
public PrintTeamMsg(id , Msg[]){
message_begin( MSG_ONE, get_user_msgid( "SayText" ), _, id )
write_byte( id )
write_string( Msg )
message_end()
}