AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   say_team - minor problem (https://forums.alliedmods.net/showthread.php?t=134060)

CsIosefin 07-31-2010 10:46

say_team - minor problem
 
Code:

public say_team(id)
{
    static name[32], mes[200];
    read_args(mes, 199);
    remove_quotes(mes);
    trim(mes);
    get_user_name(id, name, 31);

    switch(cs_get_user_team(id))
    {
        case CS_TEAM_T:
        {
            if(is_user_alive(id))
            {
                chat(0, "!team[Team] *ALIVE* !g%s !y: !team%s", name, mes);
            }
                else
            {
                chat(0, "!team[Team] *DEAD* !g%s !y: !team%s", name, mes);
            }
        }

        case CS_TEAM_CT:
        {
            if(is_user_alive(id))
            {
                chat(0, "!team[Team] *ALIVE* !g%s !y: !team%s", name, mes);
            }
                else
            {
                chat(0, "!team[Team] *DEAD* !g%s !y: !team%s", name, mes);
            }
        }
    }

    return PLUGIN_HANDLED;
}

How do you see only the team?
I wrote and CS_TEAM_CT CS_TEAM_T why not work?

nikhilgupta345 07-31-2010 11:10

Re: say_team - minor problem
 
Not sure if this is why, but try making a variable before the switch and testing that variable.

Like

New CsTeams:team
team=cs_get_user_team(id)
switch(team)
//CODE HERE

CsIosefin 07-31-2010 11:18

Re: say_team - minor problem
 
nikhilgupta345: I already put up what to select, it selects your team, but not punching the team, this is the problem ...

nikhilgupta345 07-31-2010 12:06

Re: say_team - minor problem
 
What's wrong with it, do you mean that it's showing to everyone? Not just the team?

Hunter-Digital 07-31-2010 12:48

Re: say_team - minor problem
 
chat(0, ...

That means it's sent to all players, I guess your chat() function is a copy of colorchat or something, and first arg is the player ID.

So, you must do a loop and see wich player is on player's team and send'em the message.

You could either use get_players() function (I understand it's buggy) or just a for() loop and check stuff.

Also, create a variable to hold is_user_alive() if you use the loop... and also, you can do this:

Code:

chat(0, "!team[Team] *%s* !g%s !y: !team%s", (alive ? "ALIVE" : "DEAD"), name, mes);

CsIosefin 07-31-2010 13:13

Re: say_team - minor problem
 
Code:

public say_team(id)
{
    static name[32], mes[200], players [32];
    read_args(mes, 199);
    remove_quotes(mes);
    trim(mes);
    get_user_name(id, name, 31);

    new player_count = get_playersnum();
    get_players(players, player_count, "c");

for (new i = 0; i < player_count; i++)
{
    switch(cs_get_user_team(id))
    {
        case CS_TEAM_T:
        {
            if(is_user_alive(players[i]))
            {
                chat(players[i], "!team[Team] *ALIVE* !g%s !y: !team%s", name, mes);
            }
                else
            {
                chat(players[i], "!team[Team] *DEAD* !g%s !y: !team%s", name, mes);
            }
        }

        case CS_TEAM_CT:
        {
            if(is_user_alive(players[i]))
            {
                chat(players[i], "!team[Team] *ALIVE* !g%s !y: !team%s", name, mes);
            }
                else
            {
                chat(players[i], "!team[Team] *DEAD* !g%s !y: !team%s", name, mes);
            }
        }
    }
}

    return PLUGIN_HANDLED;
}

That would be a good way?
Expect a response from you Hunter-Digital

Hunter-Digital 07-31-2010 13:20

Re: say_team - minor problem
 
No, it's not, learn to go through the code and try to simulate in your mind what it does.

Yours, apart from the verry repeatitive call of is_user_alive(), you're calling it wrong, you need to check if the sender is alive, not the receiver.

Code:

public say_team(id)
{
        static name[32], mes[200], players[32], player, alive, num, i, CsTeams:team;

        read_args(mes, 199);
        remove_quotes(mes);
        trim(mes);

        get_user_name(id, name, 31);
        alive = is_user_alive(id);
        team = cs_get_user_team(id);

        num = get_playersnum();
        get_players(players, num, "c");

        for (i = 0; i < num; i++)
        {
                player = players[i];

                /* you could replace is_user_connected(player) with is_user_alive(player) == alive if you don't want dead-alive chat. */

                if(is_user_connected(player) && cs_get_user_team(player) == team)
                        chat(player, "!team[Team] *%s* !g%s !y: !team%s", (alive ? "ALIVE" : "DEAD"), name, mes);
        }

        return PLUGIN_HANDLED;
}



All times are GMT -4. The time now is 00:16.

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