| bLacK-bLooD |
10-05-2014 03:30 |
get_players & cs_get_user_team is inaccurate
Hi, i am using a chat plugin that allows tags to be used by admins, but i often have problems with detecting the right team of players when they chat. As far as i have been able to research the problem, get_players doesn't update the index of the player if he has moved while alive, but it's not the case here. They just chat and all of a sudden they have wrong team color (as if he is CT but chat is displaying spectator or T for no reason)
So i am sharing here the code, perhaps someone can figure it out.
PHP Code:
public plugin_init {
register_clcmd("say","hook_say");
register_clcmd("say_team","hook_say2");
}
public hook_say(id) {
if(is_user_bot(id)) {
return PLUGIN_CONTINUE;
}
if(!is_user_connected(id)) {
return PLUGIN_CONTINUE
}
new nick[32];
get_user_name(id,nick,31);
static chat[192];
read_args(chat, sizeof(chat) - 1);
remove_quotes(chat);
if(equali(chat,"")) {
return PLUGIN_CONTINUE;
}
if(( contain(chat, "/who") != -1 || contain(chat, "/admin") != -1 || contain(chat, "/admins") != -1))
set_task(time_shower,"who_motd",id)
if(is_user_admin(id)) {
for(new i=0; i<MAX_GROUPS; i++) {
if(get_user_flags(id) == g_RangFlag_Value[i]) {
switch(cs_get_user_team(id)) {
case CS_TEAM_T:
{
if(is_user_alive(id)) {
ColorChat(0,GREEN,"[%s] ^x03%s^x01: %s",g_Rang[i],nick,chat);
}
else if(!is_user_alive(id)) {
ColorChat(0,NORMAL,"*DEAD*^x04[%s] ^x03%s^x01: %s",g_Rang[i],nick,chat);
}
}
case CS_TEAM_CT:
{
if(is_user_alive(id)) {
ColorChat(0,GREEN,"[%s] ^x03%s^x01: %s",g_Rang[i],nick,chat);
}
else if(!is_user_alive(id)) {
ColorChat(0,NORMAL,"*DEAD*^x04[%s] ^x03%s^x01: %s",g_Rang[i],nick,chat);
}
}
case CS_TEAM_SPECTATOR:
{
ColorChat(0,GREY,"*SPEC*^x04[%s] ^x03%s^x01: %s",g_Rang[i],nick,chat);
}
}
}
}
return PLUGIN_HANDLED;
}
else {
switch(cs_get_user_team(id)) {
case CS_TEAM_T:
{
if(is_user_alive(id)) {
ColorChat(0,RED,"%s^x01: %s",nick,chat);
}
else if(!is_user_alive(id)) {
ColorChat(0,NORMAL,"*DEAD*^x03%s^x01: %s",nick,chat);
}
}
case CS_TEAM_CT:
{
if(is_user_alive(id)) {
ColorChat(0,BLUE,"%s^x01: %s",nick,chat);
}
else if(!is_user_alive(id)) {
ColorChat(0,NORMAL,"*DEAD*^x03%s^x01: %s",nick,chat);
}
}
case CS_TEAM_SPECTATOR:
{
ColorChat(0,GREY,"%s^x01: %s",nick,chat);
}
}
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
public hook_say2(id) {
if(is_user_bot(id)) {
return PLUGIN_CONTINUE;
}
if(!is_user_connected(id)) {
return PLUGIN_CONTINUE
}
new nick[32];
get_user_name(id,nick,31);
static chat[192];
read_args(chat, sizeof(chat) - 1);
remove_quotes(chat);
if(equali(chat,"")) {
return PLUGIN_CONTINUE;
}
if((contain(chat, "/who") != -1 || contain(chat, "/admin") != -1 || contain(chat, "/admins") != -1))
set_task(time_shower,"who_motd",id)
if(is_user_admin(id)) {
for(new i=0; i<MAX_GROUPS; i++) {
if(get_user_flags(id) == g_RangFlag_Value[i]) {
new players[32],num;
get_players(players,num,"c");
for(new x=0; x<num; x++) {
if(cs_get_user_team(id) == cs_get_user_team(players[x])) {
switch(cs_get_user_team(id)) {
case CS_TEAM_T:
{
if(is_user_alive(id)) {
ColorChat(players[x],NORMAL,"(Terrorist)^x04[%s]^x03%s^x01: %s",g_Rang[i],nick,chat);
}
else if(!is_user_alive(id)) {
ColorChat(players[x],NORMAL,"*DEAD*^x03(Terrorist)^x04[%s]^x03%s^x01: %s",g_Rang[i],nick,chat);
}
}
case CS_TEAM_CT:
{
if(is_user_alive(id)) {
ColorChat(players[x],NORMAL,"(Counter-Terrorist)^x04[%s]^x03%s^x01: %s",g_Rang[i],nick,chat);
}
else if(!is_user_alive(id)) {
ColorChat(players[x],NORMAL,"*DEAD*^x03(Counter-Terrorist)^x04[%s]^x03%s^x01: %s",g_Rang[i],nick,chat);
}
}
case CS_TEAM_SPECTATOR:
{
ColorChat(players[x],GREY,"(Spectator)^x04[%s]^x03%s^x01: %s",g_Rang[i],nick,chat);
}
}
}
else {
if(cs_get_user_team(id) == cs_get_user_team(players[x])) {
switch(cs_get_user_team(id)) {
case CS_TEAM_T:
{
if(is_user_alive(id)) {
ColorChat(players[x],NORMAL,"(Terrorist)^x04[Admin]^x03 %s^x01: %s",nick,chat);
}
else if(!is_user_alive(id)) {
ColorChat(players[x],NORMAL,"*DEAD*^x03(Terrorist)^x04[Admin]^x03 %s^x01: %s",nick,chat);
}
}
case CS_TEAM_CT:
{
if(is_user_alive(id)) {
ColorChat(players[x],BLUE,"(Counter-Terrorist) %s^x04 (Admin) : %s",nick,chat);
}
else if(!is_user_alive(id)) {
ColorChat(players[x],NORMAL,"*DEAD*^x03(Counter-Terrorist)^x04[ADMIN]^x03 %s^x01: %s",nick,chat);
}
}
case CS_TEAM_SPECTATOR:
{
ColorChat(players[x],GREY,"(Spectator)^x04[ADMIN]^x03 %s^x01: %s",nick,chat);
}
}
}
}
}
return PLUGIN_HANDLED;
}
}
}
else {
new players[32],num;
get_players(players,num,"c");
for(new x=0; x<num; x++) {
if(cs_get_user_team(id) == cs_get_user_team(players[x])) {
switch(cs_get_user_team(id)) {
case CS_TEAM_T:
{
if(is_user_alive(id)) {
ColorChat(players[x],NORMAL,"(Terrorist)^x03 %s^x01: %s",nick,chat);
}
else if(!is_user_alive(id)) {
ColorChat(players[x],NORMAL,"*Mort*(Terrorist)^x03 %s^x01: %s",nick,chat);
}
}
case CS_TEAM_CT:
{
if(is_user_alive(id)) {
ColorChat(players[x],NORMAL,"(Counter-Terrorist)^x03 %s^x01: %s",nick,chat);
}
else if(!is_user_alive(id)) {
ColorChat(players[x],NORMAL,"*Mort*(Counter-Terrorist)^x03 %s^x01: %s",nick,chat);
}
}
case CS_TEAM_SPECTATOR:
{
if(is_user_alive(id)) {
ColorChat(players[x],GREY,"(Spectator) %s^x01: %s",nick,chat);
}
}
}
}
return PLUGIN_HANDLED;
}
}
return PLUGIN_CONTINUE;
}
I also want to mention that admins have the same problem when displaying a message in chat (wrong team)
Thank you and have a nice day.
|