Mute, Unmute Command
#1

Can someone give me Simple Mute Command. I've searched but none of them worked.

That says: <Target> is kicked by administrator <Name> for <Time> minute/s [Reason: <Reason> ]

It doesn't recommend to be like this, just please give me this command. I can't find it.

And /unmute Command

Thanks anyway.
Reply
#2

1st
2nd
3rd
4th
5th
better use goog le
Reply
#3

I Used the 2nd and a little edit and my stock is:

Код:
stock MutePlayer(playerid, iGivedBy, iTime, szReason[])
{
        if(!IsPlayerConnected(playerid)) return SendClientMessage(playerid, COLOR_GREY, "Този играч не е в сървъра!");
        UTS_MuteTime[playerid] = gettime() + 60 * iTime;
        format(szReasonMute[playerid], 32, szReason);
        new szName[MAX_PLAYER_NAME], szString[168];
        new targetid;
        new TargetName[MAX_PLAYER_NAME];
        GetPlayerName(targetid, TargetName, sizeof(TargetName));
        GetPlayerName(iGivedBy, szName, MAX_PLAYER_NAME);
        format(szString, sizeof(szString), "{FF1E00}%s е заглушен от администратор %s за %d минута/и. [Причина: %s]", TargetName, szName, iTime, szReason);
        SendClientMessageToAll(-1, szString);
        return 1;
}
(Ignore the bugged text)

Now the problem is that when i type to mute other player it says <MYNAME> is muted by <MYNAME>

Where is the problem?? I don't know please help!
Reply
#4

PHP код:
#include <sscanf2> 
#include <zcmd> 
new Mute[MAX_PLAYERS]; 
forward MuteTime();
main {}
public 
OnPlayerDisconnect(playeridreason)
{
    if(
Mute[playerid] >= 1)
    {
        new 
mutename[MAX_PLAYER_NAME], string[100]; 
        
GetPlayerName(playeridmutenamesizeof(mutename)); 
        
format(stringsizeof(string), "%s just left the game with a remaining mute time of %d seconds"mutenameMute[playerid]);
        for(new 
0<= MAX_PLAYERS++) 
        {
            if(
IsPlayerConnected(i) && IsPlayerAdmin(i)) 
            {
                
SendClientMessage(i0xAFAFAFFFstring); 
            }
        }
    }
    
Mute[playerid] = 0
    return 
1
}
OnPlayerText(playeridtext[])
{
    if(
Mute[playerid] >= 1
    {
        
SendClientMessage(playerid,-1,"{f00f00}You are muted! you can't talk!");
        return 
0
    }
    return 
1
}
public 
MuteTime()
{
    for(new 
0MAX_PLAYERS++) 
    {
        if(
IsPlayerConnected(i)) 
        {
            if(
Mute[i] >= 1
            {
                
Mute[i] --; 
            }
        }
    }
    return 
1;
}
CMD:mute(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid)) return 0; /
    new 
giveplayeridreason[50], string[120], minutespname1[MAX_PLAYER_NAME], pname2[MAX_PLAYER_NAME]; 
    if(
sscanf(params"uds[50]"giveplayeridminutesreason)) return SendClientMessage(playerid0xFFFFFFFF"Correct usage: /mute [playerid/name] [time in minutes] [reason]");
    if(
giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid0xFFFFFFFF"Player not connected.");
    
GetPlayerName(playeridpname1sizeof(pname1)); 
    
GetPlayerName(giveplayeridpname2sizeof(pname2)); 
    
format(stringsizeof(string), "%s (%d) was muted for %d minutes by admin %s (%d),[REASON: %s]"pname2giveplayeridminutespname1playeridreason);
    
SendClientMessageToAll(0xFFFFFFFFstring); 
    
SetTimerEx("MuteTime"minutesfalse"i"giveplayerid);
    
Mute[giveplayerid] = 1;
    
GameTextForPlayer(giveplayerid"~R~MUTED!"50006);
    return 
1;
}
CMD:unmute(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid)) return 0;
    new 
giveplayeridreason[50], string[120];
    if(
sscanf(params"us[50]"giveplayeridreason)) return SendClientMessage(playerid0xFFFFFFFF"{FFFF00}Syntax: /unmute [playerid/name] [reason]"); 
    if(
giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid0xFFFFFFFF"{FFFF00}Player not connected."); 
    new 
pname1[MAX_PLAYER_NAME], pname2[MAX_PLAYER_NAME];
    
GetPlayerName(playeridpname1sizeof(pname1));
    
GetPlayerName(giveplayeridpname2sizeof(pname2)); 
    
format(stringsizeof(string), "%s (%d) was unmuted by %s (%d), [REASON: %s]"pname2giveplayeridpname1playeridreason); 
    
SendClientMessageToAll(0xFFFFFFFFstring); 
    
Mute[giveplayerid] = 0
    
GameTextForPlayer(giveplayerid"~P~UN-MUTED!"50006); 
    return 
1;

O-T: Better to avoid using stock a lot.
Reply
#5

Quote:
Originally Posted by RxErT
Посмотреть сообщение
PHP код:
#include <sscanf2> 
#include <zcmd> 
new Mute[MAX_PLAYERS]; 
forward MuteTime();
main {}
public 
OnPlayerDisconnect(playeridreason)
{
    if(
Mute[playerid] >= 1)
    {
        new 
mutename[MAX_PLAYER_NAME], string[100]; 
        
GetPlayerName(playeridmutenamesizeof(mutename)); 
        
format(stringsizeof(string), "%s just left the game with a remaining mute time of %d seconds"mutenameMute[playerid]);
        for(new 
0<= MAX_PLAYERS++) 
        {
            if(
IsPlayerConnected(i) && IsPlayerAdmin(i)) 
            {
                
SendClientMessage(i0xAFAFAFFFstring); 
            }
        }
    }
    
Mute[playerid] = 0
    return 
1
}
OnPlayerText(playeridtext[])
{
    if(
Mute[playerid] >= 1
    {
        
SendClientMessage(playerid,-1,"{f00f00}You are muted! you can't talk!");
        return 
0
    }
    return 
1
}
public 
MuteTime()
{
    for(new 
0MAX_PLAYERS++) 
    {
        if(
IsPlayerConnected(i)) 
        {
            if(
Mute[i] >= 1
            {
                
Mute[i] --; 
            }
        }
    }
    return 
1;
}
CMD:mute(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid)) return 0; /
    new 
giveplayeridreason[50], string[120], minutespname1[MAX_PLAYER_NAME], pname2[MAX_PLAYER_NAME]; 
    if(
sscanf(params"uds[50]"giveplayeridminutesreason)) return SendClientMessage(playerid0xFFFFFFFF"Correct usage: /mute [playerid/name] [time in minutes] [reason]");
    if(
giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid0xFFFFFFFF"Player not connected.");
    
GetPlayerName(playeridpname1sizeof(pname1)); 
    
GetPlayerName(giveplayeridpname2sizeof(pname2)); 
    
format(stringsizeof(string), "%s (%d) was muted for %d minutes by admin %s (%d),[REASON: %s]"pname2giveplayeridminutespname1playeridreason);
    
SendClientMessageToAll(0xFFFFFFFFstring); 
    
SetTimerEx("MuteTime"minutesfalse"i"giveplayerid);
    
Mute[giveplayerid] = 1;
    
GameTextForPlayer(giveplayerid"~R~MUTED!"50006);
    return 
1;
}
CMD:unmute(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid)) return 0;
    new 
giveplayeridreason[50], string[120];
    if(
sscanf(params"us[50]"giveplayeridreason)) return SendClientMessage(playerid0xFFFFFFFF"{FFFF00}Syntax: /unmute [playerid/name] [reason]"); 
    if(
giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid0xFFFFFFFF"{FFFF00}Player not connected."); 
    new 
pname1[MAX_PLAYER_NAME], pname2[MAX_PLAYER_NAME];
    
GetPlayerName(playeridpname1sizeof(pname1));
    
GetPlayerName(giveplayeridpname2sizeof(pname2)); 
    
format(stringsizeof(string), "%s (%d) was unmuted by %s (%d), [REASON: %s]"pname2giveplayeridpname1playeridreason); 
    
SendClientMessageToAll(0xFFFFFFFFstring); 
    
Mute[giveplayerid] = 0
    
GameTextForPlayer(giveplayerid"~P~UN-MUTED!"50006); 
    return 
1;

O-T: Better to avoid using stock a lot.
I think that would work in seconds and not minutes because you didn't calculate the time.
Reply
#6

Try with this. Should compile and work (I didn't test it). Good luck.

PHP код:
#include a_samp 
#include sscanf2
#include zcmd
#include foreach
enum playerinfo
{
    
Name[MAX_PLAYER_NAME 1],
    
boolIsMuted,
    
MuteTime,
    
MuteWarnings,
    
MuteTimer
}
new 
Player[MAX_PLAYERS][playerinfo];
main()
{
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
    
GetPlayerName(playeridPlayer[playerid][Name], MAX_PLAYER_NAME 1);
}
public 
OnPlayerText(playeridtext[])
{
    if(
Player[playerid][IsMuted] == true)
    {
        
SendClientMessage(playerid, -1"You are muted.");
        
Player[playerid][MuteWarnings]++;
        if(
Player[playerid][MuteWarnings] >= 5)
        {
            
//send a message to who you like to say the player is getting kicked because of trying to spam despite he is muted
            // Add a SetTimerEx, and put "Kick(playerid);" in the public function you call with this timer so the player who gets kicked will read the kick reason. If you kick him on this line he will not read that
        
}
        return 
0;
    }
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    if(
Player[playerid][MuteTime] > 0)
    {
        new 
string[128];
        
format(stringsizeof string"%s left with a mute time of %d seconds"Player[playerid][Name], Player[playerid][MuteTime] / 1000);
        
SendClientMessageToAll(-1string);
    }
    
ResetPlayerVariables(playerid);
    return 
1;
}
ResetPlayerVariables(playerid)
{
    
Player[playerid][IsMuted] = false;
    
Player[playerid][MuteTime] = 0;
    
Player[playerid][MuteWarnings] = 0;
}
CMD:mute(playeridparams[])
{
    
// Admin level Check here
    
new idreason[32], amountstring[128];
    if(
sscanf(params"ds[32]d"idreasonamount))return SendClientMessage(playerid, -1"Usage: /mute [playerid][reason][time in seconds]");
    if(!
IsPlayerConnected(id))return SendClientMessage(playerid, -1"Player not connected");
    if(
Player[id][IsMuted]== true)return SendClientMessage(playerid, -1"Player is already muted.");
    if(
amount 0)return SendClientMessage(playerid, -1"Muting time should be higher than 0 seconds");
    
Player[id][IsMuted] = true;
amount =* 1000// amount = amount * 1000. We will need milliseconds 
    
format(stringsizeof string"You muted %s. Reason: %s. Time left: %d seconds"Player[id][Name], reasonamount/1000);
    
SendClientMessage(playerid, -1string);    
    
format(stringsizeof string"You are now muted Reason: %s. Time left: %d seconds"reasonamount/1000);
    
SendClientMessage(id, -1string);
    
Player[id][MuteTimer] = SetTimerEx("UnmutePlayer"amountfalse"i"id);
    return 
1;
}
CMD:unmute(playeridparams[])
{
    
// Admin level Check here
    
new idstring[128];
    if(
sscanf(params"d"id))return SendClientMessage(playerid, -1"Usage: /unmute [playerid]");
    if(!
IsPlayerConnected(id))return SendClientMessage(playerid, -1"Player not connected");
    if(
Player[id][IsMuted]== false)return SendClientMessage(playerid, -1"Player is not muted.");
    
Player[id][IsMuted] = false;
    
format(stringsizeof string"You unmuted %s"Player[id][Name]);
    
SendClientMessage(playerid, -1string);    
    
SendClientMessage(id, -1"You are now unmuted.");
    
KillTimer(Player[id][MuteTimer]);
    return 
1;
}
forward UnmutePlayer(playerid);
public 
UnmutePlayer(playerid)
{
        
Player[playerid][IsMuted] = false;
        
Player[playerid][MuteWarnings] = 0;
        
Player[playerid][MuteTime] = 0;
        return 
1;

Reply
#7

Don't use a timer for this! Use timestamps
pawn Код:
stock MutePlayer(playerid, duration) {
    gPlayerMuteTime[playerid] = gettime() + duration;
}

public OnPlayerText(playerid, text[]) {
    if(gPlayerMuteTime[playerid] > gettime()) {
        SendClientMessage(playerid, 0xFF0000FF, "You are muted.");
        return 0;
    }
    return 1;
}
https://sampforum.blast.hk/showthread.php?tid=254915%5D
Reply
#8

He needed help with the cmd, not in understanding the advantages between using a timer and using gettime() instead. I couldn't make an example any longer than the one i posted that is already long. Instead of trying to correct 0reps users try to help that guy!
Also I see you love stocks... NO!
Reply
#9

Read the thread (and others) regarding the subject and you will know why I will always bring it up when applicable. And my intention is not to correct you, but point out more effective approaches. Beyond that, everything else in the code was well put together. I didn't go line by line but skimmed through it and noticed a timer being used, which is why I mentioned it.

PS: Functions are your friend.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)