How to make a team chat?
#1

Hello.
I've had a chat previously, but it got bugged somehow, and I'm still unable to fix it. I decided to script another chat, but apparently "Everyone" in the server can see it. How can I make a new one/edit this one so only Administrators can see it?

pawn Код:
// CHAT ADMIN
CMD:a(playerid, params[])
{
    new text[128];
    if(PlayerInfo[playerid][pAdmin]>=1)
    if(sscanf(params, "s[128]",text)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /a(dmin) [Text]");
    format(text,sizeof(text),"[Admin]%s: %s",GetName(playerid),params);
    foreach(Player, i)
    {
        if(PlayerInfo[playerid][pAdmin]>=1)
        {
            SendClientMessage(i,COLOR_RED,text);
        }
    }
    return 1;
}
Reply
#2

When you loop through the player to see if he is an admin, you are actually just checking if the player who typed the cmd is admin.
Change
pawn Код:
if(PlayerInfo[playerid][pAdmin]>=1)
to
pawn Код:
if(PlayerInfo[i][pAdmin]>=1)
Hope I helped, Aston.
Reply
#3

Thanks a ton, the other chats work.
How about this team chat? I've edited in a bit, and other people can still see it.
pawn Код:
CMD:t(playerid, params[])
{
    new text[128];
    if (gTeam[playerid] == TEAM_CT)
    if(sscanf(params, "s[128]",text)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /t(eam) [Text]");
    format(text,sizeof(text),"[TEAM]%s: %s",GetName(playerid),params);
    foreach(Player, i)
    {
        if (gTeam[i] == TEAM_CT)
        {
            SendClientMessage(i,COLOR_LIGHTBLUE,text);
        }
    }
    new text1[128];
    if (gTeam[playerid] == TEAM_TE)
    if(sscanf(params, "s[128]",text1)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /t(eam) [Text]");
    format(text1,sizeof(text1),"[TEAM]%s: %s",GetName(playerid),params);
    foreach(Player, i)
    {
        if (gTeam[i] == TEAM_TE)
        {
            SendClientMessage(i,COLOR_RED,text1);
        }
    }
    return 1;
}
Reply
#4

Ill give you the one i used to use before i started linking with MySQL, just change the command of Clan accordingly:

Top of your code:
Код:
enum PlayerData{
    InClan
};
Clan Command
Код:
CMD:c(playerid, params[])
{
    format(userfile, 256, "/CLAN/%s.ini", GetName(playerid));

    PlayerInfo[playerid][InClan] = dini_Int(userfile, "InClan");

    if(PlayerInfo[playerid][InClan] < 1) return false;
    if(!strlen(params)) return SendClientMessage(playerid,RED,"Usage: /c [text]");

    new name[24],string[256];

    GetPlayerName(playerid,name,sizeof(name));

    format(string,sizeof(string),"Clan Chat: %s (ID: %d): %s",name,playerid,params);

    SendClanMsg(LIGHTBLUE, string);

    return 1;
}
Stocks goes anywhere in your code
Код:
stock SendClanMsg(color,string[]){
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
            if(IsPlayerConnected(i) == 1 && PlayerInfo[i][InClan] > 0)
            {
                    SendClientMessage(i, color, string);
            }
    }
    return 1;
}
Also if you want a SetClan Member command for rcon admin:
Код:
CMD:setclanmember(playerid, params[])
{
    new player1, string[128], string2[128];

    sscanf(params,"d",player1);

    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "You must be RCON admin to set people to the clan!");
    if(sscanf(params,"u",player1)) return SendClientMessage(playerid,RED,"Usage: /setclanmember [PlayerID/PartOfName]");

    format(userfile, 128, "/CLAN/%s.ini", GetName(player1));

    if(dini_Int(userfile, "InClan")==1) return SendClientMessage(playerid,RED,"That player is already in a clan!");
    if(!IsPlayerConnected(player1) || player1 == INVALID_PLAYER_ID) return SendClientMessage(playerid,RED,"Invalid ID");

    format(string, sizeof(string), "You are now in the clan!");
    format(string2, sizeof(string2), "%s (ID: %d) is now in the clan!", GetName(player1), player1);

    if(!dini_Exists(userfile))
    {
            SendClientMessage(player1, GREEN, string);
            SendClientMessage(playerid, GREEN, string2);
            dini_Create(userfile);
            dini_IntSet(userfile, "InClan",1);
    }
    return 1;
}
Hope this helps, change it accordingly
Reply
#5

Try adding
pawn Код:
gTeam[playerid] = GetPlayerTeam(playerid);
at the top of your command just underneath your new text[128]; line.
I think you have to redefine gTeam in every different callback/command/whatever
Reply
#6

pawn Код:
CMD:t(playerid, params[])
{
    if(!isnull(params))
    {
        new string[128];
        format(string,sizeof(string),"[TEAM]%s: %s",GetName(playerid),params);
        foreach(Player, i)
        {
            if(gTeam[i] == gTeam[playerid]) SendClientMessage(i,COLOR_RED, string);
        }
    }
    else return SendClientMessage(playerid, COLOR_WHITE, "Usage: /t(eam) [Text]");
    return 1;
}
Reply
#7

I see. And Kvsolda, come to think of it. Clan's seems like a good idea to add into my Game now. Thanks guy, +rep of course.
Reply
#8

Quote:
Originally Posted by AstonDA-G
Посмотреть сообщение
Try adding
pawn Код:
gTeam[playerid] = GetPlayerTeam(playerid);
at the top of your command just underneath your new text[128]; line.
I think you have to redefine gTeam in every different callback/command/whatever
I'm posting again to clarify something for you.


pawn Код:
new gTeam[MAX_PLAYERS];
At the top of your script would make it a global variable, meaning you won't need to redefine it when using it.

pawn Код:
new gTeam[MAX_PLAYERS];
Inside of a function would make it a "local" variable, meaning it won't exist in other functions unless re-defined in them.
Reply
#9

In order for my command to work make sure you make a "CLAN" folder in your scriptfiles, dont forget
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)