SA-MP Forums Archive
Question Help: Command limited, with gettickcount or gettime - 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: Question Help: Command limited, with gettickcount or gettime (/showthread.php?tid=363816)



Question Help: Command limited, with gettickcount or gettime - Speed++ - 28.07.2012

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



Re: Question Help: Command limited, with gettickcount or gettime - leonardo1434 - 28.07.2012

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



Re: Question Help: Command limited, with gettickcount or gettime - Speed++ - 28.07.2012

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..


Re: Question Help: Command limited, with gettickcount or gettime - Speed++ - 28.07.2012

EDIT: Don't work...


Re: Question Help: Command limited, with gettickcount or gettime - leonardo1434 - 28.07.2012

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.


Re: Question Help: Command limited, with gettickcount or gettime - Speed++ - 28.07.2012

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, " " );



Re: Question Help: Command limited, with gettickcount or gettime - leonardo1434 - 28.07.2012

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.


Re: Question Help: Command limited, with gettickcount or gettime - Speed++ - 28.07.2012

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...


Re: Question Help: Command limited, with gettickcount or gettime - leonardo1434 - 28.07.2012

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



Re: Question Help: Command limited, with gettickcount or gettime - Speed++ - 28.07.2012

tested... and don't work again