Need Help About Team
#1

How can i make team system ? like anti teamkill - teamchat ? can someone teach me on here or pm pls thx
Reply
#2

check this for anti-team kill
https://sampforum.blast.hk/showthread.php?tid=403883

and for team chat

pawn Код:
#include <a_samp>
#include <zcmd>
#include <foreach>
#include <sscanf>

forward TeamChat(playerid,string[]);

public TeamChat(playerid,string[])
{
    foreach(Player,i)
    {
        if(GetPlayerTeam(i) == GetPlayerTeam(playerid))
        {
            SendClientMessage(i,-1,string);
        }
    }
    return 1;
}

CMD:t(playerid,params[])
{
    new text[128],pName[MAX_PLAYER_NAME],formatted[156];
    if(sscanf(params,"s[128]",text)) return SendClientMessage(playerid,-1,"Usage: /t [teamchat text]");
    GetPlayerName(playerid,pName,sizeof(pName));
    format(formatted,sizeof(formatted),"[Team Chat]: %s(%d): %s",pName,playerid,text);
    TeamChat(playerid,formatted);
    return 1;
}
Reply
#3

first of all you define the gTeam and the teams
pawn Код:
new gTeam[MAX_PLAYERS];

#define TEAM_EDITTHIS1 0
#define TEAM_EDITTHIS2 1
onplayerspawn:this one will prevent team kill
pawn Код:
if (gTeam[playerid] == TEAM_EDITTHIS1)
 {
 SetPlayerTeam(playerid,0);
 }
 if(gTeam[playerid] == TEAM_EDITTHIS2)
 {
 SetPlayerTeam(playerid,1);
 }
now let's set the team color:
pawn Код:
SetPlayerToTeamColor(playerid)
{
    if (gTeam[playerid] == TEAM_EDITTHIS1)
    {
        SetPlayerColor(playerid,0x008040FF);
    }
    if(gTeam[playerid] == TEAM_EDITTHIS2)
    {
        SetPlayerColor(playerid,0xFFFFFFFF);
    }
team chat:
pawn Код:
public OnPlayerText(playerid,text[])
{
    if(strfind(text, "!",true))
    {
    new gangChat[256];
    new playername[MAX_PLAYER_NAME];
    new string[256];

    strmid(gangChat,text,1,strlen(text));

    GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
    format(string, sizeof(string),"[TeamChat] %s: %s", playername, gangChat);

    for(new i = 0; i < MAX_PLAYERS; i++)
    {
    if(gTeam[i] == gTeam[playerid])
    {
    SendClientMessage(i, -1, string);
    }
    return 0;
    }
    }
  return 1;
}
this is just an example you can edit it if you want
Reply
#4

Quote:
Originally Posted by Eth
Посмотреть сообщение
first of all you define the gTeam and the teams
pawn Код:
new gTeam[MAX_PLAYERS];

#define TEAM_EDITTHIS1 0
#define TEAM_EDITTHIS2 1
onplayerspawn:this one will prevent team kill
pawn Код:
if (gTeam[playerid] == TEAM_EDITTHIS1)
 {
 SetPlayerTeam(playerid,0);
 }
 if(gTeam[playerid] == TEAM_EDITTHIS2)
 {
 SetPlayerTeam(playerid,1);
 }
now let's set the team color:
pawn Код:
SetPlayerToTeamColor(playerid)
{
    if (gTeam[playerid] == TEAM_EDITTHIS1)
    {
        SetPlayerColor(playerid,0x008040FF);
    }
    if(gTeam[playerid] == TEAM_EDITTHIS2)
    {
        SetPlayerColor(playerid,0xFFFFFFFF);
    }
team chat:
pawn Код:
public OnPlayerText(playerid,text[])
{
    if(strfind(text, "!",true))
    {
    new gangChat[256];
    new playername[MAX_PLAYER_NAME];
    new string[256];

    strmid(gangChat,text,1,strlen(text));

    GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
    format(string, sizeof(string),"[TeamChat] %s: %s", playername, gangChat);

    for(new i = 0; i < MAX_PLAYERS; i++)
    {
    if(gTeam[i] == gTeam[playerid])
    {
    SendClientMessage(i, -1, string);
    }
    return 0;
    }
    }
  return 1;
}
this is just an example you can edit it if you want
compiles but in game i typing a without ! it shows [TeamChat]GfxZz:
when i type with ! it shows GfxZz:a
Reply
#5

Quote:
Originally Posted by Protonix
Посмотреть сообщение
compiles but in game i typing a without ! it shows [TeamChat]GfxZz:
when i type with ! it shows GfxZz:a
ok here is a command for the team chat:
first ;
in any place in your pawno:
pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
now sendteammessage :
pawn Код:
public SendTeamMessage(team, color, string[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(gTeam[i] == team)
            {
                SendClientMessage(i, color, string);
            }
        }
    }
}
command for team chat:
pawn Код:
if(strcmp(cmd, "/teamchat", true) == 0 || strcmp(cmd, "/tc", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            new sendername[MAX_PLAYER_NAME];
            GetPlayerName(playerid, sendername, sizeof(sendername));
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[64];
            while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
            {
                result[idx - offset] = cmdtext[idx];
                idx++;
            }
            result[idx - offset] = EOS;
            if(!strlen(result))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: (/t)eam©hat [message]");
                return 1;
            }
            new team = gTeam[playerid];
            new string[128];
            format(string, sizeof(string), "[TEAM]: %s: %s", sendername, result);
            SendTeamMessage(team, 0x7BDDA5AA, string);
            printf("%s", string);
        }
        return 1;
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)