[Mute] Help with command
#1

Hello.

I made my mute command and now i need some kind of timer which ends when mute time ends.

This is command:

PHP код:
CMD:mute(playerid,params[])
{
    new 
razlog,vrijeme,ime[MAX_PLAYER_NAME],ime2[MAX_PLAYER_NAME],ID,poruka[128],poruka2[128],poruka3[128];
    if(
PlayerInfo[playerid][pAdministrator] < 1) return SendClientMessage(playerid, -1,"{F81414}Greska:{FFFFFF} Nemate dozvolu za tu komandu");
    if(
sscanf(params,"uds",ID,vrijeme,razlog)) return SendClientMessage(playerid, -1,"{FFFFFF}Koristenje:{FFF1AF} /mute (Ime/ID) (Vrijeme) (Razlog)");
    if(
ID == playerid) return SendClientMessage(playerid,-1,"{F81414}Greska:{FFFFFF} Nemozete muteovati sami sebe");
    if(
PlayerInfo[ID][pAdministrator]) return SendClientMessage(playerid,-1,"{F81414}Greska:{FFFFFF} Nemozete muteaovati ostale administratore");
    else
    {
        
GetPlayerName(ID,ime,sizeof(ime));
        
format(poruka,sizeof(poruka),"{00C0FF}WG:{FFFFFF} Muteali ste igraca{FFF1AF} %s[%d]{FFFFFF} na vrijeme od {FFF1AF}%d{FFFFFF} sekundi. Razlog: %s",ime,ID,vrijeme,razlog);
        
SendClientMessage(playerid,-1,poruka);
        
GetPlayerName(playerid,ime2,sizeof(ime2));
        
format(poruka2,sizeof(poruka2),"{00C0FF}WG: {FFFFFF}Muteani ste od strane{FFF1AF} %s[%d] na vrijeme od{FFF1AF} %d{FFFFFF} sekundi. Razlog: %s",ime2,playerid,vrijeme,razlog);
        
SendClientMessage(ID,-1,poruka2);
        
format(poruka3,sizeof(poruka3),"{C3C3C3}[A-Obavijest]:{FFF1AF} %s[%d]{FFFFFF} je muteovo igraca{FFF1AF} %s[%d].{FFFFFF} Razlog: %s",ime2,playerid,ime,ID,razlog);
        
SendAdminMessage(-1,poruka3);
        {
            
PlayerInfo[ID][pMute] = vrijeme;
        }
    }
    return 
1;

I made one timer but it didn't work,and now i don't have any idea how to make timer that ends at the time.

If you need translate for this command just say it is not problem
Reply
#2

I need a translate.
Reply
#3

Just a moment,please
Reply
#4

PHP код:
CMD:mute(playerid,params[])
{
    new 
razlog,vrijeme,ime[MAX_PLAYER_NAME],ime2[MAX_PLAYER_NAME],ID,poruka[128],poruka2[128],poruka3[128];
    if(
PlayerInfo[playerid][pAdministrator] < 1) return SendClientMessage(playerid, -1,"{F81414}Error:{FFFFFF} You don't have permissions");
    if(
sscanf(params,"uds",ID,vrijeme,razlog)) return SendClientMessage(playerid, -1,"{FFFFFF}Syntax:{FFF1AF} /mute (name/ID) (time) (Reason)");
    if(
ID == playerid) return SendClientMessage(playerid,-1,"{F81414}Error:{FFFFFF} You can't mute yourself");
    if(
PlayerInfo[ID][pAdministrator]) return SendClientMessage(playerid,-1,"{F81414}Greska:{FFFFFF} You can't mute other administrators");
    else
    {
        
GetPlayerName(ID,ime,sizeof(ime));
        
format(poruka,sizeof(poruka),"{00C0FF}WG:{FFFFFF} You have muted{FFF1AF} %s[%d]{FFFFFF} for the time of {FFF1AF}%d{FFFFFF} seconds. reason: %s",ime,ID,vrijeme,razlog);
        
SendClientMessage(playerid,-1,poruka);
        
GetPlayerName(playerid,ime2,sizeof(ime2));
        
format(poruka2,sizeof(poruka2),"{00C0FF}WG: {FFFFFF}You have been muted by{FFF1AF} %s[%d] for the time of{FFF1AF} %d{FFFFFF} seconds. reason: %s",ime2,playerid,vrijeme,razlog);
        
SendClientMessage(ID,-1,poruka2);
        
format(poruka3,sizeof(poruka3),"{C3C3C3}[A-Obavijest]:{FFF1AF} %s[%d]{FFFFFF} has just muted{FFF1AF} %s[%d].{FFFFFF} reason: %s",ime2,playerid,ime,ID,razlog);
        
SendAdminMessage(-1,poruka3);
        {
            
PlayerInfo[ID][pMute] = vrijeme;
        }
    }
    return 
1;

Reply
#5

Hello there.

Okay, here it goes:

Basically, you don't need a timer to do that. To my mind, it would be better if you'd do following:

* When muting player, store somewhere, how long player should not be able to send messages
* Get current unix timestamp (gettime()), and then add this 'mute-span' to it
* Whenever player texts, check, if our specific variable (in this case: PlayerInfo[ID][pMute]) is greater than NOW unix timestamp. If so, player can not send any message. Otherwise - he can.

Here's the code:
pawn Код:
CMD:mute(playerid,params[])
{
    new razlog,vrijeme,ime[MAX_PLAYER_NAME],ime2[MAX_PLAYER_NAME],ID,poruka[128],poruka2[128],poruka3[128];
    if(PlayerInfo[playerid][pAdministrator] < 1) return SendClientMessage(playerid, -1,"{F81414}Error:{FFFFFF} You don't have permissions");
    if(sscanf(params,"uds",ID,vrijeme,razlog)) return SendClientMessage(playerid, -1,"{FFFFFF}Syntax:{FFF1AF} /mute (name/ID) (time) (Reason)");
    if(ID == playerid) return SendClientMessage(playerid,-1,"{F81414}Error:{FFFFFF} You can't mute yourself");
    if(PlayerInfo[ID][pAdministrator]) return SendClientMessage(playerid,-1,"{F81414}Greska:{FFFFFF} You can't mute other administrators");
    else
    {
        GetPlayerName(ID,ime,sizeof(ime));
        format(poruka,sizeof(poruka),"{00C0FF}WG:{FFFFFF} You have muted{FFF1AF} %s[%d]{FFFFFF} for the time of {FFF1AF}%d{FFFFFF} seconds. reason: %s",ime,ID,vrijeme,razlog);
        SendClientMessage(playerid,-1,poruka);
        GetPlayerName(playerid,ime2,sizeof(ime2));
        format(poruka2,sizeof(poruka2),"{00C0FF}WG: {FFFFFF}You have been muted by{FFF1AF} %s[%d] for the time of{FFF1AF} %d{FFFFFF} seconds. reason: %s",ime2,playerid,vrijeme,razlog);
        SendClientMessage(ID,-1,poruka2);
        format(poruka3,sizeof(poruka3),"{C3C3C3}[A-Obavijest]:{FFF1AF} %s[%d]{FFFFFF} has just muted{FFF1AF} %s[%d].{FFFFFF} reason: %s",ime2,playerid,ime,ID,razlog);
       
        SendAdminMessage(-1,poruka3);
         
        PlayerInfo[ ID ][ pMute ] = gettime() + vrijeme;
    }
    return 1;
}

// ........

public OnPlayerText(playerid, text[])
{
    if( PlayerInfo[ID][pMute] > gettime() )
    {
        // Player is not able to send any messages..
        new String[64];
        format( String,
                sizeof( String ),
                "You can not send any messages for %d more seconds.", PlayerInfo[ ID ][ pMute ] - gettime()
        );
       
        SendClientMessage(  playerid,
                            -1,
                            String
        );
       
        return 0;
    }
}
Should be working. If there are any problems, post them here, I will try to help You as much as I can

Greetings.
Reply
#6

Hey this is working but when the mute is over i can talk but nothing shows in the chat.
Reply
#7

Quote:
Originally Posted by NoDi522
Посмотреть сообщение
Hey this is working but when the mute is over i can talk but nothing shows in the chat.
Perhaps You don't know how does OnPlayerText callback works, therefore
I would like You to read this SAMP Wikipedia topic.

Anyway, that was just in good interest of Yours.

All you had to do to be able to send messages when not muted, was to return 1 (or true) at the end of the callback (as in Wikipedia: 0 - don't send message, 1 - otherwise)
pawn Код:
public OnPlayerText(playerid, text[])
{
    if( PlayerInfo[ID][pMute] > gettime() )
    {
        // Player is not able to send any messages..
        new String[64];
        format( String,
                sizeof( String ),
                "You can not send any messages for %d more seconds.", PlayerInfo[ ID ][ pMute ] - gettime()
        );
       
        SendClientMessage(  playerid,
                            -1,
                            String
        );
       
        return 0;
    }

    return 1; // << - send message to the server
}
I hope You've learnt something new

Greetings
Reply
#8

I know how it works but i forgot return 1

Thank you however
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)