I can't get my /unmute to work properly.
#1

I made a /mute & /unmute command. The /mute command works, but I can't then un-mute the player again.
I appreciate any help.

Код:
new Muted[MAX_PLAYERS];
Код:
public OnPlayerText(playerid, text[])
{
        if(Muted[playerid] == 1)
        {
                SendClientMessage(playerid,-1,"You are currently muted, you can not talk in chat.");
                return 0;
        }
        return 1;
}
MUTE:

Код:
CMD:mute(playerid,params[])
{
        new targetid,string[128];
        if(Muted[playerid] == 0)
        {
                if(PlayerInfo[playerid][pAdmin] >1)
                {
                    if(sscanf(params,"u", targetid)) return SendClientMessage(playerid, -1, "Syntax - /mute [playerid]");
                    {
                        Muted[playerid] = 1;
                        format(string,sizeof(string), "%s has been muted by an administrator.",targetid);
                        SendClientMessageToAll(-1, string);
                     }

                     }
                 }   
            
        return 1;
 }
UN-MUTE

Код:
CMD:unmute(playerid,params[])
{
        new targetid, string[128];
        if(Muted[playerid] == 1)
        {
                if(PlayerInfo[playerid][pAdmin] >1)
                {
                        if(sscanf(params,"u",targetid)) return SendClientMessage(playerid, -1, "Syntax - /unmute [playerid]");
                        {
                            Muted[playerid] = 1;
                            format(string,sizeof(string),"%s has been un-muted by an administrator.",targetid);
                            SendClientMessageToAll(-1, string);
                        }
                }
        }
        return 1;
}
Reply
#2

You are using
Код:
Muted[playerid] = 1;
in the /unmute command.

Change the value to false aka 0 in the unmute command.

Код:
Muted[playerid] = 0;
Reply
#3

Quote:
Originally Posted by TopShooter2
Посмотреть сообщение
You are using
Код:
Muted[playerid] = 1;
in the /unmute command.

Change the value to false aka 0 in the unmute command.

Код:
Muted[playerid] = 0;
Wow. I can't believe I'm that stupid to miss that. Thank you very much. I have one more small problem though. When doing /mute & /un-mute - it doesn't display the players name, it's just blank like this.

Код:
(blank) has been muted/un-muted by an administrator.
I might be doing something stupid again, but I'm really new at this.
Reply
#4

Код:
CMD:mute(playerid, params[])
 {
 	new targetid, targetname[MAX_PLAYER_NAME], string[144];

 	if(!PlayerInfo[playerid][pAdmin])
 		return 0;

 	if(sscanf(params, "u", targetid))
 		return SendClientMessage(playerid, -1, "Syntax: /mute [playerid]");

 	if(Muted[targetid] == 1)
 		return SendClientMessage(playerid, -1, "The player is already muted.");

 	GetPlayerName(playerid, targetname, MAX_PLAYER_NAME);

 	Muted[targetid] = 1;
 	format(string, sizeof(string), "%s (%d) has been muted by an administrator.", targetname, targetid);
 	SendClientMessageToAll(-1, string);

 	return 1;
 }

 CMD:unmute(playerid, params[])
 {
 	new targetid, targetname[MAX_PLAYER_NAME], string[144];

 	if(!PlayerInfo[playerid][pAdmin])
 		return 0;

 	if(sscanf(params, "u", targetid))
 		return SendClientMessage(playerid, -1, "Syntax: /mute [playerid]");

 	if(!Muted[playerid])
 		return SendClientMessage(playerid, -1, "The player is not muted.");

 	GetPlayerName(playerid, targetname, MAX_PLAYER_NAME);

 	Muted[targetid] = 0;
 	format(string, sizeof(string), "%s (%d) has been un-muted by an administrator.", targetname, targetid);
 	SendClientMessageToAll(-1, string);

 	return 1;
 }
Also put under public OnPlayerConnect:
Muted[playerid] = 0;
Reply
#5

Quote:
Originally Posted by Sabur
Посмотреть сообщение
snip
Hey, that looks really clean and seemed like it fixed my issues. Care to explain what you changed?
Reply
#6

Quote:
Originally Posted by ccodey
Посмотреть сообщение
Код:
(blank) has been muted/un-muted by an administrator.
I might be doing something stupid again, but I'm really new at this.
Код:
format(string,sizeof(string),"%s has been un-muted by an administrator.",targetid);
                            SendClientMessageToAll(-1, string);
Because you're using an ID as a string.

In this case you should be using %i (Integer) rather than using %s (String).

However in this instance, it would only return their actual ID, not their name.


All that Sabur has done is made the fixes that were mentioned earlier, and made it display the name for you, rather than simply trying to show the ID. Along with better structure and formatting.
Reply
#7

Quote:
Originally Posted by ccodey
Посмотреть сообщение
Hey, that looks really clean and seemed like it fixed my issues. Care to explain what you changed?
Код:
CMD:mute(playerid,params[])
{
        new targetid,string[128];
        if(Muted[playerid] == 0) // this mute check should be under sscanf and you are checking if you are muted yourself instead of the target player.
        {
                if(PlayerInfo[playerid][pAdmin] >1) // I check if player admin level is 0, what you did here is also correct.
                {
                    if(sscanf(params,"u", targetid)) return SendClientMessage(playerid, -1, "Syntax - /mute [playerid]"); 
                    {
                        Muted[playerid] = 1; // same here, instead of muting the targetid - you mute yourself.
                        format(string,sizeof(string), "%s has been muted by an administrator.",targetid); // you are quoting the targetid, not targetname. To get targetname, you need to create a different variable for that and use GetPlayerName. 
                        SendClientMessageToAll(-1, string);
                     }

                     }
                 }   
            
        return 1;
 }
Reply
#8

Alright, seems they did a little bit more
Reply
#9

Ah. Thank you all for helping me, really appreciate it. You all helped a newbie today.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)