/newbie command
#1

Hi guys, I need some help. It's about how to create /newbie chat command, which will allow non-admin players to use it only 1 time every 30 seconds. Also I want if they have to wait again to write in the newbie chat to return the time. i.e. example: Newbie chat: You have to wait %d seconds before using the chat again!
-Note: I'm using YCMD and ZCMD.

Thanks in advance!
Reply
#2

I think, it's better to use only one, ZCMD or YCMD!

Script:

It's should be something like this ?

At the top of your script!
pawn Код:
new Asked[MAX_PLAYERS];
Then, out of any callback!
pawn Код:
forward AskAgain(playerid);

public AskAgain(playerid)
{
    SendClientMessage(playerid, -1, "You can ask again at the /newbie chat!");
    Asked[playerid] = 0;
    return 1;
}
Your command:
pawn Код:
CMD:newbie(playerid, params[])
{
    if(Asked[playerid] == 1)return SendClientMessage(playerid, -1, "You must wait 30 seconds before you can write a new message!");
    //Your code !
    SetTimerEx("AskAgain", 30000, false, "i", playerid);
    Asked[playerid] = 1;
}
Reply
#3

A timer makes absolutely no sense use GetTickCount() or gettime()
Reply
#4

I wrote an example in a thread few hours ago and like I said there - it's always better to try avoiding timers as much as you can.

That should work.
pawn Код:
new
    Allow_Talk[ MAX_PLAYERS ]
;

public OnPlayerConnect( playerid )
{
    Allow_Talk[ playerid ] = -1;
    return 1;
}

CMD:newbie( playerid, params[ ] )
{
    if( IsPlayerAdmin( playerid ) ) return 1; // non-admins only - change to your variable if you want!
    if( isnull( params ) ) return SendClientMessage( playerid, -1, "Usage: /newbie <message>" );
    if( Allow_Talk[ playerid ] == -1 || ( Allow_Talk[ playerid ] != -1 && ( gettime( ) - Allow_Talk[ playerid ] ) > 30 ) )
    {
        // do your code here and.. send it to all/specific players, depending on your code
        Allow_Talk[ playerid ] = gettime( );
    }
    else if( Allow_Talk[ playerid ] != -1 && ( gettime( ) - Allow_Talk[ playerid ] ) <= 30 )
    {
        new
            error_msg[ 70 ]
        ;
        format( error_msg, sizeof( error_msg ), "Newbie chat: You have to wait %d seconds before using the chat again!", gettime( ) - Allow_Talk[ playerid ] );
        SendClientMessage( playerid, -1, error_msg );
    }
    return 1;
}
Reply
#5

Quote:
Originally Posted by Areax
Посмотреть сообщение
I think, it's better to use only one, ZCMD or YCMD!
I haven't mentioned that I use both of them, I meant that I can use one of them, but not strcmp or the based on it - dcmd.

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
I wrote an example in a thread few hours ago and like I said there - it's always better to try avoiding timers as much as you can.

That should work.
pawn Код:
new
    Allow_Talk[ MAX_PLAYERS ]
;

public OnPlayerConnect( playerid )
{
    Allow_Talk[ playerid ] = -1;
    return 1;
}

CMD:newbie( playerid, params[ ] )
{
    if( IsPlayerAdmin( playerid ) ) return 1; // non-admins only - change to your variable if you want!
    if( isnull( params ) ) return SendClientMessage( playerid, -1, "Usage: /newbie <message>" );
    if( Allow_Talk[ playerid ] == -1 || ( Allow_Talk[ playerid ] != -1 && ( gettime( ) - Allow_Talk[ playerid ] ) > 30 ) )
    {
        // do your code here and.. send it to all/specific players, depending on your code
        Allow_Talk[ playerid ] = gettime( );
    }
    else if( Allow_Talk[ playerid ] != -1 && ( gettime( ) - Allow_Talk[ playerid ] ) <= 30 )
    {
        new
            error_msg[ 70 ]
        ;
        format( error_msg, sizeof( error_msg ), "Newbie chat: You have to wait %d seconds before using the chat again!", gettime( ) - Allow_Talk[ playerid ] );
        SendClientMessage( playerid, -1, error_msg );
    }
    return 1;
}
Thank you! This is exactly what I needed.
Reply
#6

Quote:
Originally Posted by Wizzy951
Посмотреть сообщение
Thank you! This is exactly what I needed.
You are welcome but you'll need to change a line because I did a mistake. My apologies.

Change to:
pawn Код:
format( error_msg, sizeof( error_msg ), "Newbie chat: You have to wait %d seconds before using the chat again!", 30 - ( gettime( ) - Allow_Talk[ playerid ] ) );
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)