server closed when typing a command
#1

i have this me command, why does it close the serveR?

pawn Код:
COMMAND:shout(playerid, params[])
{
    if(sscanf(params, "s", playerid)) return SendClientMessage(playerid, Yellow, "Usage: /shout <message>");
    new string[128];
    if((gettime()-LastShout[playerid]) < 20) {
    format(string, 128, "You have to wait %d seconds before shout", (20-(gettime()-LastShout[playerid])));
    SendClientMessage(playerid, Red, string); return 1;
    }
    GetPlayerName(playerid, string, sizeof(string));
    format(string, sizeof(string), "( SHOUT ) %s(ID: %d) %s:", string);
    SendClientMessageToAll(White, string);
    LastShout[playerid] = gettime();
    return 1;
}
Reply
#2

Is the server crashing as soon as this cmd is typed?
Reply
#3

I think you mean GetTickCount rather than gettime, gettime gets the current server time which is stored in the variables hour, minute and second. gettime(&hour=0,&minute=0,&second=0)
Reply
#4

Quote:
Originally Posted by Infamous
Посмотреть сообщение
Is the server crashing as soon as this cmd is typed?
Yes.

so I just need to replace gettime with GetTickCount?
Reply
#5

Can you show me how I tried to replace gettime with GetTickCount but still , crashed
Reply
#6

Of course the server closes.
You missunderstood how to use SSCANF

pawn Код:
COMMAND:shout(playerid, params[])
{
    if ( sscanf( params, "s", params[ 0 ] ) ) return SendClientMessage(playerid, Yellow, "Usage: /shout <message>");
    new string[128],Name[ 20 ];
    if ( ( GetTickCount( ) - LastShout[ playerid ] ) < 20 )
    {
        format(string, 128, "You have to wait %d seconds before shout", ( 20 - ( gGetTickCount( ) -LastShout[ playerid ] ) ) );
        SendClientMessage( playerid, Red, string );
        return 1;
    }
    GetPlayerName( playerid, Name, sizeof( Name ) );
    format( string, sizeof( string ), "( SHOUT ) %s(ID: %d) %s:", Name, playerid, params[ 0 ]);
    SendClientMessageToAll( White, string );
    LastShout[ playerid ] = GetTickCount( );
    return 1;
}
You used playerid as a paramtere, also used strng to get player's name...
Reply
#7

Thanks it works now, but it keep spamming the timer dont work??
Reply
#8

pawn Код:
#define MAX_INTEGER                     (2147483647)
#define ceil(%0)                        (floatround((%0),floatround_ceil))
#define TickRemaining(%0,%1)            ((((%1)>=(GetTickCount()))?((MAX_INTEGER)-(%1)+(GetTickCount())):((GetTickCount())-(%1)))<(%0))
#define TickTimeDiff(%0,%1)             (((%1)>=(GetTickCount()))?(((%0)/1000)-ceil(((MAX_INTEGER)-(%1)+(GetTickCount()))/1000)):(((%0)/1000)-ceil(((GetTickCount())-(%1))/1000)))
pawn Код:
if ( TickRemaining( 20000, LastShout[ playerid ] ) )
{
    format( string, sizeof ( string ), "You have to wait %i seconds before shouting again!", TickTimeDiff( 20000, LastShout[ playerid ] ) );
    return SendClientMessage( playerid, Red, string );
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)