Police Team message! -
Thanks - 26.04.2018
Hello I've creating a command for Police TEAM! But I want a help In the command everything worked and
OnlyCops can use it but there a problem!! I want Only Who joined a COPS/FBI/SWAT/ARMY/CIA Can read the message who! how
PHP Code:
CMD:cm(playerid, params[])
{
if(!PoliceTeam(GetPlayerSkin(playerid))) return SendClientMessage(playerid, 0xE74C3CFF, "{FF0000}Error: {FFFFFF}Only Law Enforcement may use this command.");
{
new string[128];
if(sscanf(params, "s[128]", params)) return SendClientMessage(playerid, COLOR_WHITE, "[SYNTEX]: /CM [Text]");
new pskin = GetPlayerSkin(playerid);
if(pskin == 165 || pskin == 166 || pskin == 267 || pskin == 280 || pskin == 281 || pskin == 284 || pskin == 285 || pskin == 286 || pskin == 287 || pskin == 288)
{
if(pskin == 285)
{
format(string, sizeof(string), "{00FFFF}[S.W.A.T]%s: {1E90FF}%s", RPN(playerid), params);
SendPlayerTeamMessage(playerid, BLUE, string);
}
if(pskin == 287)
{
format(string, sizeof(string), "{8B008B}[ARMY]%s: {1E90FF}%s", RPN(playerid), params);
SendPlayerTeamMessage(playerid, BLUE, string);
}
if(pskin == 165 || pskin == 166)
{
format(string, sizeof(string), "{FFFFFF}[C.I.A]%s: {1E90FF}%s", RPN(playerid), params);
SendPlayerTeamMessage(playerid, BLUE, string);
}
if(pskin == 280 || pskin == 281 || pskin == 282 || pskin == 283 || pskin == 284 || pskin == 300 || pskin == 301 || pskin == 302 || pskin == 307 || pskin == 309)
{
format(string, sizeof(string), "{1E90FF}[Police]%s: {1E90FF}%s", RPN(playerid), params);
SendPlayerTeamMessage(playerid, BLUE, string);
}
SetPlayerChatBubble(playerid,params,COLOR_TEAMCHAT,20.0,5000);
}
else
{
SendClientMessage(playerid, RED, "{FF0000}[ERROR]: {FFFFFF}Only police can use this command.");
}
}
return 1;
}
After some cop type /cm [MESSAGE] Everyone can read it! I want put it only cops can read the message how?
Stocks
PHP Code:
stock SendPlayerTeamMessage(playerid,color, string[])
{
foreach(new i : Player)
{
if(gTeam[i] == gTeam[playerid]) //Here i used gteam(You can use PlayerInfo[playerid][Faction/Gang/Fam]
{
SendClientMessage(i, color, string);
}
}
return 1;
}
stock RPN(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
for(new i = 0; i < MAX_PLAYER_NAME; i++)
{
if(name[i] == '_') name[i] = ' ';
}
return name;
}
Re: Police Team message! -
Zeus666 - 26.04.2018
Check if police gteam is 1,2,3 or whatever than the rest of the players
Ex, when you /invite someone, his gteam it sets to 1.
Because gteam == 0 means civilian
gteam == 1 means PD.
if you didn't set player gTeam to be set at 1 at /invite, it means his gTeam is still 0. (like civilians) and that's why everyone can see it.
Re: Police Team message! -
Thanks - 26.04.2018
What? can you fix the code what I've giving? THANK You
Re: Police Team message! -
kovac - 26.04.2018
PHP Code:
// The way you're checking for player team is very bad, what you should do is:
// On top of the script
new pTeam[MAX_PLAYERS]; // Create a variable to store player team
#define Police 0 // define teams
#define Criminal 1
new pClass[MAX_PLAYERS]; // Another variable to store player class
#define FBI 0 // define classes
#define Swat 1
#define Thief 2
#define Bomber 3
// OnGameModeInit
AddPlayerClass(283,1544.7887,-1675.4630,13.5591,90.0000,0,0,0,0,0,0); // FBI
AddPlayerClass(306,1544.7887,-1675.4630,13.5591,90.0000,0,0,0,0,0,0); // Swat
AddPlayerClass(124,1544.7887,-1675.4630,13.5591,90.0000,0,0,0,0,0,0); // Thief
AddPlayerClass(294,1544.7887,-1675.4630,13.5591,90.0000,0,0,0,0,0,0); // Bomber
public OnPlayerRequestClass(playerid, classid)
{
switch(classid)
{
case 0: // Classes are starting from 0 (The first class you have is 0)
{
pTeam[playerid] = Police;
pClass[playerid] = FBI;
}
case 1:
{
pTeam[playerid] = Police;
pClass[playerid] = Swat;
}
case 2:
{
pTeam[playerid] = Criminal;
pClass[playerid] = Thief;
}
case 3:
{
pTeam[playerid] = Criminal;
pClass[playerid] = Bomber;
}
}
return 1;
}
CMD:cm(playerid, params[])
{
if(pTeam[playerid] != Police) return SendClientMessage(playerid, 0xE74C3CFF, "{FF0000}Error: {FFFFFF}Only Law Enforcement may use this command.");
new string[128], message[128];
if(sscanf(params, "s[128]", message)) return SendClientMessage(playerid, COLOR_WHITE, "[SYNTEX]: /CM [Text]");
switch(pClass[playerid])
{
case FBI: format(string, sizeof(string), "{00FFFF}[FBI]%s: {1E90FF}%s", RPN(playerid), message);
case Swat: format(string, sizeof(string), "{00FFFF}[Swat]%s: {1E90FF}%s", RPN(playerid), message);
}
SendPlayerTeamMessage(playerid, BLUE, string);
return 1;
}
// and yes, the function should look like this then;
stock SendPlayerTeamMessage(playerid, color, string[])
{
foreach(new i : Player)
{
if(pTeam[i] == pTeam[playerid])
{
SendClientMessage(i, color, string);
}
}
return 1;
}
Untested but I hope it's gonna help you.
Re: Police Team message! -
Thanks - 26.04.2018
Hi again! Why did you making it like hard!! Look at my it's ez and worked but I want only COPS/FBI/CIA/SWAT/ARMY can read the message who team say! Only and civ cannot how...
Re: Police Team message! -
kovac - 26.04.2018
It's not hard, its the easiest possible way. Your code is just a hude mess and leading to bugs.
Please take your time to read my reply carefully and you might understand. If not, feel free to ask whatever is unclear to you.
Re: Police Team message! -
kovac - 26.04.2018
If you want all the cops to read the message then use this (along with my code):
PHP Code:
stock SendPlayerTeamMessage(playerid, color, string[])
{
foreach(new i : Player)
{
if(pTeam[i] == Police)
{
SendClientMessage(i, color, string);
}
}
return 1;
}
Re: Police Team message! -
Phreak - 26.04.2018
I'll have to agree with kovac. His code is much more simple and it's a good basis for other commands that are related to teams.
In your case you'll have to re-write a lot of code and it will quickly become an unmaintainable mess.
I strongly recommend you try to understand and apply his code instead.