SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 03/07/2019, 09:48 AM   #1
Fuzzy
Little Clucker
 
Join Date: May 2019
Posts: 37
Reputation: 0
Default Cooldown method Global and for each Player

Player Cooldown

First Step , set it on the top part of gamemode.


Code:
new Number_Time[MAX_PLAYERS];
So now, -> 1000ms it's 1 s so 1 minute it's 60000 ms.
60000 ms -> 1 minute


Second Step , add this to the top of the CMD.

new tick_count = GetTickCount( );


To add a message.

Code:
if ( Number_Time[playerid] > tick_count ) return SendClientMessage(playerid,"Example");
Under the message add this
Code:
Number_Time[playerid] = tick_count + (60000 * 15);
GetTickCount it's time from server start
So...
1. Check time by GetTickCount() -> + result assign to tick_count
2. Your number_time it's tick_count + 15 minutes, so now check:
what's higher, Number_Time[playerid] or tick_count, actually - Number_Time
but after 15 minutes it should have same values
and u can use command again


And don't forget to add this under OnPlayerConnect.

Code:
Number_Time[playerid] = 0;

And now for Global variable
Top part of gamemode.

Code:
new GlobalTime;
And in CMD add those.
Check time:


Code:
new _tick = GetTickCount();
To send message.
Code:
if(GlobalTime > _tick) return...
Code:
GlobalTime = _tick + (60000 * 15);
And under OnPlayerConnect add this:

Code:
GlobalTime = 0;
__________________
My Releases:
Fuzzy is offline   Reply With Quote
Old 03/07/2019, 01:13 PM   #2
ShadowMortar
Big Clucker
 
ShadowMortar's Avatar
 
Join Date: Jul 2016
Location: Croatia
Posts: 87
Reputation: 10
Smile Re: Cooldown method Global and for each Player

I prefer this:
PHP Code:
new PlayerUsedCommandMAX_PLAYERS ];
CMD:helloplayerid )
{
        new 
now gettime( ), str128 ];
        if( 
now < ( PlayerUsedCommandplayerid ] + 20 ) ) 
        {
                
formatstrsizeofstr ), "You've to wait %d seconds before you can use this command again!", ( PlayerUsedCommandplayerid ] +20 ) - now );
                
SendClientMessageplayerid, -1str );
        }
        else
        {
                
SendClientMessageplayerid, -1"Hello!" );
                
PlayerUsedCommandplayerid ] =gettime ( );
        }
        return 
1;

But anyways, good job
ShadowMortar is offline   Reply With Quote
Old 03/07/2019, 01:33 PM   #3
Fuzzy
Little Clucker
 
Join Date: May 2019
Posts: 37
Reputation: 0
Default Re: Cooldown method Global and for each Player

Quote:
Originally Posted by ShadowMortar View Post
I prefer this:
PHP Code:
new PlayerUsedCommandMAX_PLAYERS ];
CMD:helloplayerid )
{
        new 
now gettime( ), str128 ];
        if( 
now < ( PlayerUsedCommandplayerid ] + 20 ) ) 
        {
                
formatstrsizeofstr ), "You've to wait %d seconds before you can use this command again!", ( PlayerUsedCommandplayerid ] +20 ) - now );
                
SendClientMessageplayerid, -1str );
        }
        else
        {
                
SendClientMessageplayerid, -1"Hello!" );
                
PlayerUsedCommandplayerid ] =gettime ( );
        }
        return 
1;

But anyways, good job
Yeah there are a lot better ways or ways that people prefer
but I just posted this tutorial for new people in pawn and maybe help some of the.
Thank you for your reply
__________________
My Releases:
Fuzzy is offline   Reply With Quote
Old 03/07/2019, 05:16 PM   #4
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 274
Reputation: 22
Default Re: Cooldown method Global and for each Player

Use gettime instead of GetTickCount.
To quote the wiki: "GetTickCount will cause problems on servers with uptime of over 24 days as GetTickCount will eventually warp past the integer size constraints."
Another advantage of gettime: You can use seconds and don't have to calculate milliseconds.

The global example will reset GlobalTime every time a player connects and in this case it is not necessary to reset it at all.

ShadowMortars example is definitively the better approach, even though you don't need to use gettime twice
Code:
PlayerUsedCommand[ playerid ] =now;
Plastikmensch is offline   Reply With Quote
Old 04/07/2019, 03:28 PM   #5
ShadowMortar
Big Clucker
 
ShadowMortar's Avatar
 
Join Date: Jul 2016
Location: Croatia
Posts: 87
Reputation: 10
Default Re: Cooldown method Global and for each Player

Quote:
Originally Posted by Fuzzy View Post
Yeah there are a lot better ways or ways that people prefer
but I just posted this tutorial for new people in pawn and maybe help some of the.
Thank you for your reply
But Fuzzy I know you, I'm Shadow
ShadowMortar is offline   Reply With Quote
Old 04/07/2019, 11:13 PM   #6
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,202
Reputation: 390
Default Re: Cooldown method Global and for each Player

Someone previously made a very good tutorial about this method although i can't even state their name lmfao lol, nevertheless yeah everyone by now should know that the use of timers is too irrelevant at most times when doing a cool-down process.
__________________
Quote:
Originally Posted by Andy
I offer paid scripting services, I can do anything except mapping because fuck mapping.

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link
RogueDrifter is offline   Reply With Quote
Old 05/07/2019, 09:58 AM   #7
Fuzzy
Little Clucker
 
Join Date: May 2019
Posts: 37
Reputation: 0
Default Re: Cooldown method Global and for each Player

Quote:
Originally Posted by RogueDrifter View Post
Someone previously made a very good tutorial about this method although i can't even state their name lmfao lol, nevertheless yeah everyone by now should know that the use of timers is too irrelevant at most times when doing a cool-down process.
Yeah I remember that tutorial lmao, forgot the guy name
thanks for your reply
__________________
My Releases:
Fuzzy is offline   Reply With Quote
Old 05/07/2019, 10:07 AM   #8
ShadowMortar
Big Clucker
 
ShadowMortar's Avatar
 
Join Date: Jul 2016
Location: Croatia
Posts: 87
Reputation: 10
Default Re: Cooldown method Global and for each Player

Quote:
Originally Posted by Plastikmensch View Post
Use gettime instead of GetTickCount.
To quote the wiki: "GetTickCount will cause problems on servers with uptime of over 24 days as GetTickCount will eventually warp past the integer size constraints."
Another advantage of gettime: You can use seconds and don't have to calculate milliseconds.

The global example will reset GlobalTime every time a player connects and in this case it is not necessary to reset it at all.

ShadowMortars example is definitively the better approach, even though you don't need to use gettime twice
Code:
PlayerUsedCommand[ playerid ] =now;
Thanks for the advice.
ShadowMortar is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Factory method while saving player state, yes or no? nikotragedy Scripting Help 0 02/12/2018 04:25 PM
Any efficient method to check if a player is using ******? rangerxxll Scripting Help 2 31/10/2015 09:05 AM
Best method to check if a player is aiming with a sniper? rangerxxll Scripting Help 2 26/10/2015 01:40 AM
Creating a per player plugin detection method RajatPawar Scripting Help 3 02/11/2013 04:49 PM
Best player data saving method ziomal432 Help Archive 3 24/02/2010 03:37 PM


All times are GMT. The time now is 03:26 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.