Clan Chat -
CoDeZ - 20.07.2012
Hello..
I wanted to make a chat for my clan
For example if my tag name is [TH] , i want to make it like that :
/t Hey , and it arrives to all players who have [TH] tag at their name
I've tried using ZCMD+sscanf but couldn't do it.
Any help would be apperciated , thanks.
Re: Clan Chat -
Kindred - 20.07.2012
Something like this could be done:
pawn Код:
CMD:t(playerid, params[])
{
if(IsPlayerConnected(playerid))
{
new text[128];
if(sscanf(params, "s[128]", text)) return SendClientMessage(playerid, -1, "Usage: /t [text]");
GetPlayerName(playerid, Name, sizeof(Name));
if(strfind(Name, "[TH]", true) != -1)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
GetPlayerName(i, Name, sizeof(Name));
if(strfind(Name, "[TH]", true) != -1)
{
SendClientMessage(i, -1, text);
}
}
}
//More tags like done about
}
return 1;
}
Of course this would require you to add all the clan tags manually.
Re: Clan Chat -
Matz - 20.07.2012
Made it for ! or if you want, you can change it to command.
pawn Код:
enum pCinfo
{
cid
};
new clan[MAX_PLAYERS][pCinfo];
public OnPlayerConnect(playerid)
{
new name[30];
GetPlayerName(playerid, name, 30);
for(new i=0;i< 30;i++)
{
if(name[i] == '[') SetPVarInt(playerid, "tagb", i);
if(name[i] == ']') SetPVarInt(playerid, "tags", i);
}
if(GetPVarInt(playerid, "tags") != 0)
{
strdel(name, GetPVarInt(playerid, "tags"), 30);
format(clan[playerid][cid], 30, "%s", name[1]);
}
return 1;
}
public OnPlayerText(playerid, text[])
{
if(text[0] == '!') // Clan chat
{
new pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
if(!strfind(pname,"[",true) && !strfind(pname,"]",true))
{
SendClientMessage(playerid, -1, "ERROR: You're not in a clan, you cannot send clan message!");
return 0;
}
new string[128]; GetPlayerName(playerid,string,sizeof(string));
format(string,sizeof(string),"%s (ID: %d): %s",string,playerid,text[1]); SendMessageToClan(clan[playerid][cid], string);
return 0;
}
return 1;
}
stock SendMessageToClan(clanid, message[])
{
for(new x; x<MAX_PLAYERS; x++) if(clan[x][cid] == clanid) SendClientMessage(x, -1, message);
return 1;
}
Re: Clan Chat -
CoDeZ - 20.07.2012
Quote:
Originally Posted by Kindred
Something like this could be done:
pawn Код:
CMD:t(playerid, params[]) { if(IsPlayerConnected(playerid)) { new text[128]; if(sscanf(params, "s[128]", text)) return SendClientMessage(playerid, -1, "Usage: /t [text]"); GetPlayerName(playerid, Name, sizeof(Name)); if(strfind(Name, "[TH]", true) != -1) { for(new i = 0; i < MAX_PLAYERS; i++) { GetPlayerName(i, Name, sizeof(Name)); if(strfind(Name, "[TH]", true) != -1) { SendClientMessage(i, -1, text); } } } //More tags like done about } return 1; }
Of course this would require you to add all the clan tags manually.
|
Thank you, that's what i've been looking for
Quote:
Originally Posted by Matz
Made it for ! or if you want, you can change it to command.
pawn Код:
enum pCinfo { cid };
new clan[MAX_PLAYERS][pCinfo];
public OnPlayerConnect(playerid) { new name[30]; GetPlayerName(playerid, name, 30); for(new i=0;i< 30;i++) { if(name[i] == '[') SetPVarInt(playerid, "tagb", i); if(name[i] == ']') SetPVarInt(playerid, "tags", i); } if(GetPVarInt(playerid, "tags") != 0) { strdel(name, GetPVarInt(playerid, "tags"), 30); format(clan[playerid][cid], 30, "%s", name[1]); } return 1; }
public OnPlayerText(playerid, text[]) { if(text[0] == '!') // Clan chat { new pname[MAX_PLAYER_NAME]; GetPlayerName(playerid, pname, sizeof(pname)); if(!strfind(pname,"[",true) && !strfind(pname,"]",true)) { SendClientMessage(playerid, -1, "ERROR: You're not in a clan, you cannot send clan message!"); return 0; } new string[128]; GetPlayerName(playerid,string,sizeof(string)); format(string,sizeof(string),"%s (ID: %d): %s",string,playerid,text[1]); SendMessageToClan(clan[playerid][cid], string); return 0; } return 1; }
stock SendMessageToClan(clanid, message[]) { for(new x; x<MAX_PLAYERS; x++) if(clan[x][cid] == clanid) SendClientMessage(x, -1, message); return 1; }
|
Thanks bro