Question Help: Command limited, with gettickcount or gettime
#1

how to perform this command with a limit.. with gettickcount or gettime ?

the command is usable only 3 minute.. send the message.. you can use that command only 3 minute...

pawn Code:
cmd(world, playerid, params[])
{
     new
         mvID
     ;

     if ( sscanf( params, "d", mvID ) ) return SendClientMessage( playerid, -1, "* usage /world id" );
     if ( mvID < 0 || mvID > 99 ) return SendClientMessage( playerid, -1, "* world id 0 - 99" );
     
     SetPlayerVirtualWorld( playerid, mvID );

     for ( new i = 0; i < 92; i++ ) SendClientMessage( playerid, -1, " " );
     
     format( string, sizeof ( string ), "* You are now in the virtual world %d", mvID );
     SendClientMessage( playerid, -1, string );
     
     for ( new i = 0; i < 6; i++ ) SendClientMessage( playerid, -1, " " );

     return 1;
}
Reply
#2

this may work.
pawn Code:
cmd(world, playerid, params[])
{
     new
         mvID,
         time
     ;
     if(time > gettime()) return SendClientMessage(playerid,-1,"You must wait 3 minutes to use it again");
     if ( sscanf( params, "d", mvID ) ) return SendClientMessage( playerid, -1, "* usage /world id" );
     if ( mvID < 0 || mvID > 99 ) return SendClientMessage( playerid, -1, "* world id 0 - 99" );

     SetPlayerVirtualWorld( playerid, mvID );

     for ( new i = 0; i < 92; i++ ) SendClientMessage( playerid, -1, " " );

     format( string, sizeof ( string ), "* You are now in the virtual world %d", mvID );
     SendClientMessage( playerid, -1, string );

     for ( new i = 0; i < 6; i++ ) SendClientMessage( playerid, -1, " " ); // for what are u using that?
     time = gettime() + 60*3;
     return 1;
}
Reply
#3

Quote:
Originally Posted by leonardo1434
View Post
this may work.
pawn Code:
cmd(world, playerid, params[])
{
     new
         mvID,
         time
     ;
     if(time > gettime()) return SendClientMessage(playerid,-1,"You must wait 3 minutes to use it again");
     if ( sscanf( params, "d", mvID ) ) return SendClientMessage( playerid, -1, "* usage /world id" );
     if ( mvID < 0 || mvID > 99 ) return SendClientMessage( playerid, -1, "* world id 0 - 99" );

     SetPlayerVirtualWorld( playerid, mvID );

     for ( new i = 0; i < 92; i++ ) SendClientMessage( playerid, -1, " " );

     format( string, sizeof ( string ), "* You are now in the virtual world %d", mvID );
     SendClientMessage( playerid, -1, string );

     for ( new i = 0; i < 6; i++ ) SendClientMessage( playerid, -1, " " ); // for what are u using that?
     time = gettime() + 60*3;
     return 1;
}
pawn Code:
for ( new i = 0; i < 92; i++ ) SendClientMessage( playerid, -1, " " );
pawn Code:
for ( new i = 0; i < 6; i++ ) SendClientMessage( playerid, -1, " " ); // for what are u using that?


i use that for clear all the chat... and 6 lines below the message, then the message will be sent..
Reply
#4

EDIT: Don't work...
Reply
#5

pawn Code:
public OnFilterScriptInit()
{
    new n = -1,time = gettime() + 5;
    while(1 != n)
    {
        if(time > gettime()) printf("lol it works.");
    }
}
With this code, it gonna spam the console saying it works until the little time over. it proofs, you did something wrong.


using the same logic, but with gettickcount it will spam for 10 seconds.
pawn Code:
public OnFilterScriptInit()
{
    new n = -1,time = GetTickCount() + 1000*10;
    while(1 != n)
    {
        if(time > GetTickCount()) printf("lol it works.");
    }
}
just try, re-look at what you did, if you copied right.
Reply
#6

Quote:
Originally Posted by leonardo1434
View Post
pawn Code:
public OnFilterScriptInit()
{
    new n = -1,time = gettime() + 5;
    while(1 != n)
    {
        if(time > gettime()) printf("lol it works.");
    }
}
With this code, it gonna spam the console saying it works until the little time over. it proofs, you did something wrong.


using the same logic, but with gettickcount it will spam for 10 seconds.
pawn Code:
public OnFilterScriptInit()
{
    new n = -1,time = GetTickCount() + 1000*10;
    while(1 != n)
    {
        if(time > GetTickCount()) printf("lol it works.");
    }
}
just try, re-look at what you did, if you copied right.
tested this.. and don't work. when type the command send me the message test..

pawn Code:
new
         mvID,
         time = GetTickCount() + 1000*10
     ;

     if(time > GetTickCount()) SendClientMessage(playerid, -1, "Test ?");
   
     if ( sscanf( params, "d", mvID ) ) return SendClientMessage( playerid, -1, "* /world <0-99>" );
     if ( mvID < 0 || mvID > 99 ) return SendClientMessage( playerid, -1, "* <0-99>" );
     
     SetPlayerVirtualWorld( playerid, mvID );

     for ( new i = 0; i < 92; i++ ) SendClientMessage( playerid, -1, " " );
     
     format( string, sizeof ( string), "* You are now in virtual world %d", mvID );
     SendClientMessage( playerid, -1, string );
     
     for ( new i = 0; i < 6; i++ ) SendClientMessage( playerid, -1, " " );
Reply
#7

it should have a return, Return means the function ends there if the condition is true.


Just do what i've said and it gonna work.
Reply
#8

Quote:
Originally Posted by leonardo1434
View Post
it should have a return, Return means the function ends there if the condition is true.


Just do what i've said and it gonna work.
can you explain me how to add this on command ? I did not understand...
Reply
#9

Forgot to tell it should be a global in this case, i did a little mistake. it should work now.

pawn Code:
new time2[MAX_PLAYERS];
cmd(world, playerid, params[])
{
     new
         mvID
     ;
     if(time2[playerid] > gettime()) return SendClientMessage(playerid,-1,"You must wait 3 minutes to use it again");
     if ( sscanf( params, "d", mvID ) ) return SendClientMessage( playerid, -1, "* usage /world id" );
     if ( mvID < 0 || mvID > 99 ) return SendClientMessage( playerid, -1, "* world id 0 - 99" );
     SetPlayerVirtualWorld( playerid, mvID );
     for ( new i = 0; i < 6; i++ ) SendClientMessage( playerid, -1, " " ); // for what are u using that?
     format( string, sizeof ( string ), "* You are now in the virtual world %d", mvID );
     SendClientMessage( playerid, -1, string );
     time2[playerid] = gettime() + 5;
     return 1;
}
Reply
#10

tested... and don't work again
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)