Tester & admin chat
#1

PHP код:
alias:tchat("t");
CMD:tchat(playerid,params[])
{
    new 
Testerstring[257];
    if(
pInfo[playerid][Tester] >= || pInfo[playerid][pAdminLevel] >= 1)
    {
        if(!
strlen(params))
        {
            
SendClientMessage(playerid, -1""COL_RED"TesterCmd: /tchat [Text]");
            return 
1;
        }
        
format(Testerstringsizeof(Testerstring), ""COL_GREEN"[Tester Chat] %s %s[%d]: %s",GetTesterName(playerid),PlayerName(playerid), playeridparams);
        
SendMessageToAllTesters(Testerstring, -1);
    }
    if(
pInfo[playerid][pAdminLevel] >= 1)
    {
        if(!
strlen(params))
        {
            
SendClientMessage(playerid, -1""COL_RED"TesterCmd: /tchat [Mesaj]");
            return 
1;
        }
        
format(Testerstringsizeof(Testerstring), ""COL_GREEN"[Tester Chat] %s %s[%d]: %s",GetAdminName(playerid),PlayerName(playerid), playeridparams);
        
SendMessageToAllTesters(Testerstring, -1);
    }
    else {
        
SendClientMessage(playerid,-1,""COL_RED"EROARE: You are not admin or tester!");
    }
    return 
1;

Problems:

1) If I am admin, it won't work /tchat.
2) If I am tester, when i write /tchat it shows "you are not admin or tester" even if I am, but I can see and write on /tchat.
3) If I am both admin or tester it works fine.


what I want:

if player is admin, to show getAdminName
if player is tester, to show Gettestername.

Player can't be both.
Reply
#2

Please show
SendMessageToAllTesters(Testerstring, -1)
Reply
#3

Код:
if(pInfo[playerid][pAdminLevel] >= 1) 
    { 
        if(!strlen(params)) 
        { 
            SendClientMessage(playerid, -1, ""COL_RED"TesterCmd: /tchat [Mesaj]"); 
            return 1; 
        } 
        format(Testerstring, sizeof(Testerstring), ""COL_GREEN"[Tester Chat] %s %s[%d]: %s",GetAdminName(playerid),PlayerName(playerid), playerid, params); 
        SendMessageToAllTesters(Testerstring, -1); 
    }
This section of code is useless as you've already selected in your first if statement if they're a tester OR admin, if you remove that issue 2 should fix itself.
Reply
#4

Код:
SendMessageToAllTesters(color, string2[])
{
	foreach(Player, i)
	{
		if(pInfo[playerid][Tester] >= 1 || pInfo[playerid][pAdminLevel] >= 1)
			{
				SendClientMessage(i, color, string2);
			}
	}
	return 1;
}
CMD:tchat(playerid, params[])
{
	if(pInfo[playerid][Tester] >= 1 || pInfo[playerid][pAdminLevel] >= 1)
	{
		new msg[128];
		new Testerstring[257];
		if(!sscanf(params, "s[128]", msg))
		{
			format(Testerstring, sizeof(Testerstring), ""COL_GREEN"[Tester Chat] %s %s[%d]: %s",GetTesterName(playerid),PlayerName(playerid), playerid, params);
        	SendMessageToAllTesters(Testerstring, -1);
		}
		else
		{
			SendClientMessage(playerid, -1, ""COL_RED"TesterCmd: /tchat [Text]");
		}
	}
	else SendClientMessage(playerid,-1,""COL_RED"EROARE: You are not admin or tester!");
	return 1;
}
Try this.
Reply
#5

PHP код:
CMD:tchat(playerid,params[])
{
    if(
pInfo[playerid][pAdminLevel] < && pInfo[playerid][Tester] < 1) return SendClientMessage(playerid, -1""COL_RED"EROARE: You are not admin or tester!");
    if(!
strlen(params)) return SendClientMessage(playerid, -1""COL_RED"TesterCmd: /tchat [Text]");
    new 
Testerstring[144];
    
format(Testerstringsizeof(Testerstring), ""COL_GREEN"[Tester Chat] %s %s[%d]: %s",
        (
pInfo[playerid][pAdminLevel]) ? (GetAdminName(playerid)) : (GetTesterName(playerid)), PlayerName(playerid), playeridparams);
    
SendMessageToAllTesters(Testerstring, -1);
    return 
1;

This method uses 'ternary operators'. https://sampforum.blast.hk/showthread.php?tid=612076

In your original code, you had two statements that queried whether the player was an admin, so if an admin was to use the command it would result in the message being sent twice. You should use 'return' to break the code to prevent it from continuing when you've achieved the result you want.

EDIT:
Quote:

If player is not helper but admin, the statement will be true because of OR. Change it to AND.

The downside of copying and pasting :>

Quote:

There is `isnull` macro, it is better checking first or second character than all of them (strlen).

I'm aware of that.
Reply
#6

Quote:
Originally Posted by Threshold
Посмотреть сообщение
PHP код:
CMD:tchat(playerid,params[])
{
    if(
pInfo[playerid][pAdminLevel] < || pInfo[playerid][Tester] < 1) return SendClientMessage(playerid, -1""COL_RED"EROARE: You are not admin or tester!");
    if(!
strlen(params)) return SendClientMessage(playerid, -1""COL_RED"TesterCmd: /tchat [Text]");
    new 
Testerstring[144];
    
format(Testerstringsizeof(Testerstring), ""COL_GREEN"[Tester Chat] %s %s[%d]: %s",
        (
pInfo[playerid][pAdminLevel]) ? (GetAdminName(playerid)) : (GetTesterName(playerid)), PlayerName(playerid), playeridparams);
    
SendMessageToAllTesters(Testerstring, -1);
    return 
1;

This method uses 'ternary operators'. https://sampforum.blast.hk/showthread.php?tid=612076

In your original code, you had two statements that queried whether the player was an admin, so if an admin was to use the command it would result in the message being sent twice. You should use 'return' to break the code to prevent it from continuing when you've achieved the result you want.
If player is not helper but admin, the statement will be true because of OR. Change it to AND.
There is `isnull` macro, it is better checking first or second character than all of them (strlen).
Reply
#7

Quote:
Originally Posted by Threshold
Посмотреть сообщение
PHP код:
CMD:tchat(playerid,params[])
{
    if(
pInfo[playerid][pAdminLevel] < || pInfo[playerid][Tester] < 1) return SendClientMessage(playerid, -1""COL_RED"EROARE: You are not admin or tester!");
    if(!
strlen(params)) return SendClientMessage(playerid, -1""COL_RED"TesterCmd: /tchat [Text]");
    new 
Testerstring[144];
    
format(Testerstringsizeof(Testerstring), ""COL_GREEN"[Tester Chat] %s %s[%d]: %s",
        (
pInfo[playerid][pAdminLevel]) ? (GetAdminName(playerid)) : (GetTesterName(playerid)), PlayerName(playerid), playeridparams);
    
SendMessageToAllTesters(Testerstring, -1);
    return 
1;

This method uses 'ternary operators'. https://sampforum.blast.hk/showthread.php?tid=612076

In your original code, you had two statements that queried whether the player was an admin, so if an admin was to use the command it would result in the message being sent twice. You should use 'return' to break the code to prevent it from continuing when you've achieved the result you want.

If I am tester, i don't have acces to use tchat. But If i'm admin, I do.

PHP код:
stock SendMessageToAllTesters(message[], color)
{
    foreach(
Playeri)
    {
        if(
pInfo[i][Tester] >= || pInfo[i][pAdminLevel] >=1)
        {
             
SendClientMessage(icolormessage);
         }
     }
    return 
1;

Reply
#8

PHP код:
if(pInfo[playerid][pAdminLevel] < || pInfo[playerid][Tester] < 1) return SendClientMessage(playerid, -1""COL_RED"EROARE: You are not admin or tester!"); 
replace it with

PHP код:
if(pInfo[playerid][pAdminLevel] < && pInfo[playerid][Tester] < 1) return SendClientMessage(playerid, -1""COL_RED"EROARE: You are not admin or tester!"); 
this will work ah
Reply
#9

Код:
SendMessageToAllTesters(string2[], color)
{
	foreach(Player, i)
	{
		if(pInfo[i][Tester] < 1 || pInfo[i][pAdminLevel] < 1)
		{
			SendClientMessage(i, color, string2);
		}
	}
}
CMD:tchat(playerid, params[])
{
	if(pInfo[playerid][Tester] == 0)
	     if(pInfo[playerid][pAdminLevel] == 0)
					 return SendClientMessage(playerid,-1,""COL_RED"EROARE: You are not admin or tester!");

		new msg[128];
		new Testerstring[257];
		if(sscanf(params, "s[128]", msg)) return SendClientMessage(playerid, -1, ""COL_RED"TesterCmd: /tchat [Text]");
		format(Testerstring, sizeof(Testerstring), ""COL_GREEN"[Tester Chat] %s %s[%d]: %s",GetTesterName(playerid),PlayerName(playerid), playerid, msg);
    	SendMessageToAllTesters(Testerstring, -1);
	    return 1;
}
try this , Editted!
Reply
#10

Simple but works, feel free to edit this to your liking.

Код:
SendTesterMessage(message[])
{
	for(new i; i < MAX_PLAYERS; i++)
	{
		if(PlayerData[i][pAdmin] > 0 || PlayerData[i][pTester] > 0)
		{
			SendClientMessage(i, -1, message);
		}
	}
}

CMD:tchat(playerid, params[])
{
	if(PlayerData[playerid][pAdmin] == 0 && PlayerData[playerid][pTester] == 0) return SendClientMessage(playerid, -1, "You are not an admin/tester.");
	if(isnull(params)) return SendClientMessage(playerid, -1, "CMD: /tchat [text]");

	new testerMsg[128], pName[MAX_PLAYER_NAME+1];
	GetPlayerName(playerid, pName, sizeof(pName));
	format(testerMsg, sizeof(testerMsg), "[Tester Chat] %s: %s", pName, params);
	SendTesterMessage(testerMsg);
	return 1;
}
For showing admin rank you could do something like this
Код:
	if(PlayerData[playerid][pAdmin] > 0) format(testerMsg, sizeof(testerMsg), "[Tester Chat] %s %s: %s", GetAdminRank(playerid), pName, params);
	else format(testerMsg, sizeof(testerMsg), "[Tester Chat] %s %s: %s", GetTesterRank(playerid), pName, params);
Else If wouldn't really be needed since you've already checked if the player should be able to use the chat or not at the start of the command.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)