Raised This Month: $32 Target: $400
 8% 

Give a person a credit after every 15 minutes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Terminator1337
Junior Member
Join Date: Jan 2015
Old 01-07-2015 , 21:02   Give a person a credit after every 15 minutes
Reply With Quote #1

Hi there,

I'm having a little bit of trouble with timers. What I want to do is give a player a credit every 15 minutes, starting from when they join the server. What would be the best way to do this?

Thanks
Terminator1337 is offline
Darkness_
Veteran Member
Join Date: Nov 2014
Old 01-07-2015 , 21:50   Re: Give a person a credit after every 15 minutes
Reply With Quote #2

PHP Code:
public OnClientPutInServer(client)
{
    
CreateTimer((15.0 60.0), GiveCreditclientTIMER_REPEAT);
}

public 
Action:GiveCredit(Handle:timerany:client)
{
    
//give them credits here

Darkness_ is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-08-2015 , 09:36   Re: Give a person a credit after every 15 minutes
Reply With Quote #3

More like:

PHP Code:
public OnClientPutInServer(client)
{
    
CreateTimer((15.0 60.0), GiveCreditGetClientUserId(client), TIMER_REPEAT);
}

public 
Action:GiveCredit(Handle:timerany:userid)
{
    new 
client GetClientOfUserId(userid);
    if (
client == 0)
        return 
Plugin_Stop;

    
//give them credits here
    
return Plugin_Continue;

__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Starbish
AlliedModders Donor
Join Date: Oct 2011
Location: South Korea
Old 01-17-2015 , 12:11   Re: Give a person a credit after every 15 minutes
Reply With Quote #4

Quote:
Originally Posted by Powerlord View Post
More like:

PHP Code:
public OnClientPutInServer(client)
{
    
CreateTimer((15.0 60.0), GiveCreditGetClientUserId(client), TIMER_REPEAT);
}

public 
Action:GiveCredit(Handle:timerany:userid)
{
    new 
client GetClientOfUserId(userid);
    if (
client == 0)
        return 
Plugin_Stop;

    
//give them credits here
    
return Plugin_Continue;

is there any difference between sending GetClientUserId() and get real index of client by using twice?

isn't it better to use GetClientOfUserId() or just putting 'client' var on OnClientPutInServer() ?
__________________
Starbish is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 01-17-2015 , 13:16   Re: Give a person a credit after every 15 minutes
Reply With Quote #5

Quote:
Originally Posted by Starbish View Post
is there any difference between sending GetClientUserId() and get real index of client by using twice?

isn't it better to use GetClientOfUserId() or just putting 'client' var on OnClientPutInServer() ?
If the player disconnects, you need to ensure that the player who connects and takes his slot doesn't receive his "credit." Client indexes are reused, user ID's are not.

You shouldn't EVER pass a client index through a timer. It's just not a good idea. Always run it through GetClientUserId() first, pass that user ID through the timer, and then run the ID through GetClientOfUserId() in the timer callback.
__________________

Last edited by ddhoward; 01-17-2015 at 13:18.
ddhoward is offline
The1Speck
SourceMod Donor
Join Date: Oct 2014
Location: USA
Old 01-17-2015 , 23:11   Re: Give a person a credit after every 15 minutes
Reply With Quote #6

Quote:
Originally Posted by ddhoward View Post
You shouldn't EVER pass a client index through a timer. It's just not a good idea. Always run it through GetClientUserId() first, pass that user ID through the timer, and then run the ID through GetClientOfUserId() in the timer callback.

Time to change all my plugins..
__________________

Add me on Steam for personal inquiries or direct assistance.

Last edited by The1Speck; 01-17-2015 at 23:12.
The1Speck is offline
m_bNightstalker
Senior Member
Join Date: Jan 2015
Location: JWD
Old 01-20-2015 , 23:46   Re: Give a person a credit after every 15 minutes
Reply With Quote #7

I would just create a repeating timer which does that for all player, and just check a var against time (where you saved the last time you gave credits to that client). then just reset that time on connect/disconnect.
m_bNightstalker is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 22:58.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode