SA-MP Forums Archive
why wont this /mute time work - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: why wont this /mute time work (/showthread.php?tid=492648)



why wont this /mute time work - AIped - 04.02.2014

Hello,

I have been busy trying to make a /mute command with a time parameter using sscanf. I saw alot of examples and gladly used them...BUT somehow it isnt working (otherwise i wont write here duh XD).

I'll try to explain what happens:
Ingame enter' /mute 0 5 ' ( 0 for playerid and 5 for seconds )
but somehow the timer that i use responds faster then that and i always get the message ;

You have been muted by 'playername' for 0 seconds! You cant talk!
it always does...even when i enter 9 or 50 seconds i get this message right away.


I thought it was just sscanf being old or something so i decided to try zcmd.
Without any luck and the exact same problem..here is the code i left the variables out for now
i always check with messages first.

pawn Код:
COMMAND:mute(playerid,params[])
{

            new Target, seconds;
            if(!sscanf(params, "ui", Target, seconds))
            {
                   if(Target == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR_RED,"ERROR: Wrong player ID");
                if(seconds != 0)
                {
                    new tname[MAX_PLAYER_NAME];
                    GetPlayerName(Target,tname,sizeof(tname));
                    new pname[MAX_PLAYER_NAME];
                    GetPlayerName(playerid,pname,sizeof(pname));
                    new tstring[256];
                    new pstring[256];
                    format(tstring,sizeof(tstring),"You have been muted by %s! You cant talk!",pname);
                    format(pstring,sizeof(pstring),"You have muted player %s(%d)",tname,Target);
                    SendClientMessage(Target,COLOR_RED,tstring);
                    SendClientMessage(playerid,COLOR_GREEN,pstring);
       
                }
                else if(seconds >= 0)
                {
                    new tname[MAX_PLAYER_NAME];
                    GetPlayerName(Target,tname,sizeof(tname));
                    new pname[MAX_PLAYER_NAME];
                    GetPlayerName(playerid,pname,sizeof(pname));
                    new tstring[256];
                    new pstring[256];
                    format(tstring,sizeof(tstring),"You have been muted by %s for %d seconds! You cant talk!",pname, seconds);
                    format(pstring,sizeof(pstring),"You have muted player %s(%d) for %d seconds",tname,Target,seconds);
                    SendClientMessage(Target,COLOR_RED,tstring);
                    SendClientMessage(playerid,COLOR_GREEN,pstring);
           
                    SetTimerEx("UnmutePlayer", seconds * 1000, false, "d", Target);
               
                }
            }
            else SendClientMessage(playerid,COLOR_YELLOW,"USAGE: /mute <playerid> <seconds-optional>");

    return 1;
}
forward UnmutePlayer(playerid);
public UnmutePlayer(playerid)
{
    SendClientMessage(playerid,COLOR_GREEN,"[AUTO-UNMUTE]: You are now unmuted and able to talk!");


}



Re: why wont this /mute time work - Borg - 04.02.2014

Firstly, you have such unacceptable condition:
pawn Код:
if(seconds != 0)
{
...
}
else if(seconds >= 0)
{
...
}
It won't work because all numbers except for 0 will lead to the first 'case' and 0 will lead to the second case. But the first case do not use the timer at all. And in the second case the timer will be triggered after 0 seconds.

Secondly, you don't actually mute the player. You just say that he is muted now. For example, the easiest way is to keep flags iMuted[MAX_PLAYERS] that says if the player is muted, and set it to 1 in mute and set it to 0 in unmute. And then you have to return 0 in the beginning of OnPlayerText and return 1 in the beginning of OnPlayerCommandText if the flag is setted to 1.


Re: why wont this /mute time work - AIped - 04.02.2014

yea as i said in the post im using just messages for now to test it out. Thats what i always do iknow i should add variables to actually mute the player.

anyway.. even if i disable this;

pawn Код:
if(seconds != 0)
{
...
}
else if(seconds >= 0)
{
...
}
same problem happens


Re: why wont this /mute time work - Borg - 04.02.2014

You are using sscanf function. Did u update sscanf plugin? And try this code.
pawn Код:
COMMAND:mute(playerid,params[])
{

            new Target, seconds;
            if(!sscanf(params, "ui", Target, seconds))
            {
                if(Target == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR_RED,"ERROR: Wrong player ID");
                if(seconds == 0)
                {
                    new tname[MAX_PLAYER_NAME];
                    GetPlayerName(Target,tname,sizeof(tname));
                    new pname[MAX_PLAYER_NAME];
                    GetPlayerName(playerid,pname,sizeof(pname));
                    new tstring[256];
                    new pstring[256];
                    format(tstring,sizeof(tstring),"You have been muted by %s! You cant talk!",pname);
                    format(pstring,sizeof(pstring),"You have muted player %s(%d)",tname,Target);
                    SendClientMessage(Target,COLOR_RED,tstring);
                    SendClientMessage(playerid,COLOR_GREEN,pstring);
       
                }
                else if(seconds >= 0)
                {
                    new tname[MAX_PLAYER_NAME];
                    GetPlayerName(Target,tname,sizeof(tname));
                    new pname[MAX_PLAYER_NAME];
                    GetPlayerName(playerid,pname,sizeof(pname));
                    new tstring[256];
                    new pstring[256];
                    format(tstring,sizeof(tstring),"You have been muted by %s for %d seconds! You cant talk!",pname, seconds);
                    format(pstring,sizeof(pstring),"You have muted player %s(%d) for %d seconds",tname,Target,seconds);
                    SendClientMessage(Target,COLOR_RED,tstring);
                    SendClientMessage(playerid,COLOR_GREEN,pstring);
           
                    SetTimerEx("UnmutePlayer", seconds * 1000, false, "d", Target);
               
                }
            }
            else SendClientMessage(playerid,COLOR_YELLOW,"USAGE: /mute <playerid> <seconds-optional>");

    return 1;
}
forward UnmutePlayer(playerid);
public UnmutePlayer(playerid)
{
    SendClientMessage(playerid,COLOR_GREEN,"[AUTO-UNMUTE]: You are now unmuted and able to talk!");


}



Re: why wont this /mute time work - AIped - 04.02.2014

the plugin should be up to date but i'll check it out.
after testing your code i noticed the code only returns the if(seconds == 0) part

EDIT: Never mind it wasnt the code i think it was the plugin that needed an update thanks!