SA-MP Forums Archive
/newbie command - 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: /newbie command (/showthread.php?tid=467000)



/newbie command - Wizzy951 - 30.09.2013

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!


Re: /newbie command - Areax - 30.09.2013

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;
}



Re: /newbie command - Pottus - 30.09.2013

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


Re: /newbie command - Konstantinos - 30.09.2013

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;
}



Re: /newbie command - Wizzy951 - 30.09.2013

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.


Re: /newbie command - Konstantinos - 01.10.2013

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 ] ) );