Mute timer not working
#1

I want to mute a player for some minutes, which is working fine. But I want him to unmute automatically after that time. That time should be the player game time so I used a timer. But it is not working.

PHP код:
new mutetimer
PHP код:
public OnGameModeInit()
{
    for(new 
0MAX_PLAYERSi++)
    {
        if(
Player[i][pIsMuted] == 1)
            
mutetimer SetTimerEx("DecMuteTime"10001"i"i);
    }
    return 
1;

PHP код:
public DecMuteTime(playerid)
{
    
Player[playerid][pMuteTime] -= 1;
    if(
Player[playerid][pMuteTime] == 0)
    {
        
Player[playerid][pIsMuted] = 0;
        
SaveAccount(playerid);
    }
    return 
1;

PHP код:
CMD:mute(playeridparams[])
{
    new 
targetidreason[128], timestring[128];
    if(
Player[playerid][pAdminLevel] >= || IsPlayerAdmin(playerid))
    {
        if(
sscanf(params"us[128]i"targetidreasontime))
                return 
SendClientMessage(playeridCOLOR_LIGHTCYAN"Syntax: /mute [playerid/PartOfName] [reason] [time]");
        if(
IsPlayerConnected(targetid))
        {
            if(
Player[playerid][pIsMuted] == 1)
                return 
SendClientMessage(playeridCOLOR_NEUTRAL"The player is already muted!");
            
Player[targetid][pIsMuted] = 1;
            
Player[targetid][pMuteTime] = time 60;
            
SaveAccount(targetid);
            
format(stringsizeof(string), "You have muted %s for %d minutes. Reason: %s"GetName(targetid), timereason);
            
SendClientMessage(playeridCOLOR_LIGHTBLUEstring);
    return 
1;

Reply
#2

Timer should be assigned [MAX_PLAYERS] so it don't mix with other players;

PHP код:
public OnGameModeInit() 

    for(new 
0MAX_PLAYERSi++) 
    { 
        if(
Player[i][pIsMuted] == 1
            
mutetimer SetTimerEx("DecMuteTime"10001"i"i); 
    } 
    return 
1

Put this under OnPlayerConnect without the loop using mutetimer[playerid] = SetTimerEx("DecMuteTime", 1000, 1, "i", i);

And you will also need to start the timer under the command
edit: and kill KillTimer(mutetimer[playerid]) once mute time is 0
Reply
#3

Quote:
Originally Posted by kovac
Посмотреть сообщение
Timer should be assigned [MAX_PLAYERS] so it don't mix with other players;

PHP код:
public OnGameModeInit() 

    for(new 
0MAX_PLAYERSi++) 
    { 
        if(
Player[i][pIsMuted] == 1
            
mutetimer SetTimerEx("DecMuteTime"10001"i"i); 
    } 
    return 
1

Put this under OnPlayerConnect without the loop using mutetimer[playerid] = SetTimerEx("DecMuteTime", 1000, 1, "i", i);

And you will also need to start the timer under the command
edit: and kill KillTimer(mutetimer[playerid]) once mute time is 0
Thanks a lot. I also had to KillTimer inside OnPlayerDisconnect(playerid).

It really helped.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)