Gangchat?
#1

Hi guys,how to add gangchat in my gm?

I use gTeam so i want,if a player writes:

;hiiii

it will be [GANG CHAT TEAMNAME PLAYERNAME: TEXT

Thanks a milion.
Reply
#2

pawn Код:
public OnPlayerText(playerid, text[])
{

   if(text[0] == '&')
   {
     new string[128],name[30];
     GetPlayerName(playerid, name, 30);
     format(string, sizeof(string), "CHAT: %s [ID: %d]: %s", name, playerid, text[1]);
     for(new i = 0; i < MAX_PLAYERS; i++)
     {
        if(PlayerInfo[playerid][Team] == PlayerInfo[i][Team])
        {
           SendClientMessage(i,agua,string);
           return 0;
        }
       
     }
     return 0;
   }
   return 0;
}
Make the needed changes
Reply
#3

Think about the steps you need to take to achieve this:

Step 1: Check whether the player has typed a message with a ; in front of it, ie, check the first character of "text" under the OnPlayerText callback:
pawn Код:
public OnPlayerText(playerid, text[])
{
    if(text[0] == ';')
    {
        // player has typed a message starting with ;
    }
    return 1;
}
Step 2: Think about what variables you will need for this. You want to know the player's name, the player's team name, and you will need the original message:
pawn Код:
public OnPlayerText(playerid, text[])
{
    if(text[0] == ';')
    {
        // player has typed a message starting with ;
        new msg[128], pname[MAX_PLAYER_NAME], teamname[MAX_TEAM_NAME];
    }
    return 1;
}
Step 3: Assign the corresponding data to these variables (using the help of a new method - GetTeamName. If you already have your own method like this, just use that one):
pawn Код:
#define MAX_TEAM_NAME 32 // defines the max length of a team name as 32 characters

stock GetTeamName(playerid, tname[], len) // Returns a player's team name depending on their team id (gTeam[playerid])
{
    switch(gTeam[playerid]) // Checks the player's team id
    {
        case 0: format(tname, len, "RedGang"); // teamid 0 has the teamname RedGang
        case 1: format(tname, len, "BlueGang"); // teamid 1 has the teamname BlueGang
        case 2: format(tname, len, "GreenGang"); // teamid 2 has the teamname GreenGang
        case 3: format(tname, len, "YellowGang"); // teamid 3 has the teamname YellowGang

        default: printf("Invalid team name"); // this will only print if there is an error
    }
    return 1;
}

public OnPlayerText(playerid, text[])
{
    if(text[0] == ';')
    {
        // player has typed a message starting with ;
        new msg[128], pname[MAX_PLAYER_NAME], teamname[MAX_TEAM_NAME];

        GetPlayerName(playerid, pname, sizeof(pname)); // gets the player's name
        GetTeamName(playerid, teamname, sizeof(teamname)); // gets the player's teamname
        strmid(msg, text, 1, strlen(text), sizeof(msg)); // saves what the player has typed without the ; at the start
        format(msg, sizeof(msg), "[%s]%s: %s", teamname, pname, msg); // puts all the info together to create the message to send to players on the same team

    }
    return 1;
}
Step 4: Cycle through all players, and print the message to those who are on the same team:
pawn Код:
#define MAX_TEAM_NAME 32

stock GetTeamName(playerid, tname[], len)
{
    switch(gTeam[playerid])
    {
        case 0: format(tname, len, "RedGang");
        case 1: format(tname, len, "BlueGang");
        case 2: format(tname, len, "GreenGang");
        case 3: format(tname, len, "YellowGang");

        default: printf("Invalid team name");
    }
    return 1;
}

public OnPlayerText(playerid, text[])
{
    if(text[0] == ';')
    {
        // player has typed a message starting with ;
        new msg[128], pname[MAX_PLAYER_NAME], teamname[MAX_TEAM_NAME];

        GetPlayerName(playerid, pname, sizeof(pname));
        GetTeamName(playerid, teamname, sizeof(teamname));
        strmid(msg, text, 1, strlen(text), sizeof(msg));
        format(msg, sizeof(msg), "[%s]%s: %s", teamname, pname, msg);

        for(new i=0; i<MAX_PLAYERS; i++) // loops through all players
        {
            if(gTeam[i] == gTeam[playerid]) // checks to see if the current player is on the same team as the player who typed the message
            {
                SendClientMessage(i, -1, msg); // prints the message for the player on the same team
            }
        }
        return 0; // return 0 so that the original message with ; in front of it isn't shown to everybody
    }
    return 1;
}
And voila. It's really not that difficult when you break it down!
Reply
#4

Thanks at both.

Benjo,i've a problem.

I definied the teams name as TEAM_TEAMNAME:

Код:
stock GetTeamName(playerid, tname[], len)
{
    switch(gTeam[playerid])
    {
        case 0: format(tname, len, "TEAM_SWAT");
        case 1: format(tname, len, "TEAM_CHICKENS");
        case 2: format(tname, len, "TEAM_KAMIKAZERS");
        case 3: format(tname, len, "TEAM_IMMIGRANTS");
        case 4; format(tname, len, "TEAM_MEDICS");
        case 5; format(tname, len, "TEAM_FARMERS");
        case 6; format(tname, len, "TEAM_RICHS")
        case 7; format(tname, len, "TEAM_PILOTS");

        default: printf("Invalid team name");
    }
    return 1;
}
But i get lots of errors in the gm...
Reply
#5

BUMP
Reply
#6

This one works. I use this one: e_e
pawn Код:
public OnPlayerText(playerid, text[])
{

   if(text[0] == '&')
   {
     new string[128],name[30];
     GetPlayerName(playerid, name, 30);
     format(string, sizeof(string), "CHAT: %s [ID: %d]: %s", name, playerid, text[1]);
     for(new i = 0; i < MAX_PLAYERS; i++)
     {
        if(GetPlayerTeam(playerid) == GetPlayerTeam(i)) // Send message to all players of the player which typed: & + text
        {
           SendClientMessage(i,0x00FFFFFF,string);
           return 0;
        }
       
     }
     return 0;
   }
   return 0;
}
Reply
#7

Well.. what are the errors?
Reply
#8

@Blackwave,i need to show the team too,not only "CHAT:"

@Darklom,tons of errors like Undefenied symbol or other".
Reply
#9

pawn Код:
if(text[0] == '&')
   {
     new string[128],name[30];
     GetPlayerName(playerid, name, 30);
     format(string, sizeof(string), "CHAT: %s [ID: %d]: %s", name, playerid, text[1]);
     for(new i = 0; i < MAX_PLAYERS; i++)
     {
        if(GetPlayerTeam(playerid) == GetPlayerTeam(i)) // Send message to all players of the player which typed: & + text
        {
           SendClientMessage(i,0x00FFFFFF,string);
           return 0;
        }
       
     }
     return 0;
   }
Just have to add this part on the OnPlayerText
Reply
#10

Quote:
Originally Posted by Logitech90
Посмотреть сообщение
Thanks at both.

Benjo,i've a problem.

I definied the teams name as TEAM_TEAMNAME:

Код:
stock GetTeamName(playerid, tname[], len)
{
    switch(gTeam[playerid])
    {
        case 0: format(tname, len, "TEAM_SWAT");
        case 1: format(tname, len, "TEAM_CHICKENS");
        case 2: format(tname, len, "TEAM_KAMIKAZERS");
        case 3: format(tname, len, "TEAM_IMMIGRANTS");
        case 4; format(tname, len, "TEAM_MEDICS");
        case 5; format(tname, len, "TEAM_FARMERS");
        case 6; format(tname, len, "TEAM_RICHS")
        case 7; format(tname, len, "TEAM_PILOTS");

        default: printf("Invalid team name");
    }
    return 1;
}
But i get lots of errors in the gm...
The problem comes because you have put semi-colons ( after case 4, 5, 6 and 7. They need to be colons (. Check out the correct that [FU]Victious made for you - should work fine.

Sorry for late response btw.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)