server closed when typing a command -
xir - 29.01.2011
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;
}
Re: server closed when typing a command -
Infamous - 29.01.2011
Is the server crashing as soon as this cmd is typed?
Re: server closed when typing a command -
JamesC - 29.01.2011
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)
Re: server closed when typing a command -
xir - 29.01.2011
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?
Re: server closed when typing a command -
xir - 29.01.2011
Can you show me how I tried to replace gettime with GetTickCount but still , crashed
Re: server closed when typing a command -
Zh3r0 - 29.01.2011
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...
Re: server closed when typing a command -
xir - 29.01.2011
Thanks it works now, but it keep spamming the timer dont work??
Re: server closed when typing a command -
bigcomfycouch - 29.01.2011
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 );
}