This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

[SOLVED] Best way to check if player's total time is equal to...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-24-2016 , 13:30   [SOLVED] Best way to check if player's total time is equal to...
Reply With Quote #1

Let's say that I have a plugin that saves the player's played time. I need to make it so on every X minutes the player will get a certain bonus. For example, the player will get a bonus on 500, 1000, 1500, 2000, 2500 and so on minutes, or 1000, 2000, 3000, 4000. What is the best way of checking this? For now I have only come up with setting a repeat task on 1 minute and check the player's time for each player separately and for each "time-circle" (1000, 2000, 3000...). Is there a more efficient way to do this?

Last edited by OciXCrom; 06-27-2016 at 17:53.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Depresie
Veteran Member
Join Date: Nov 2013
Old 02-24-2016 , 13:50   Re: Best way to check if player's total time is equal to...
Reply With Quote #2

probably by adding a command so the player can check his time, then another one with which he can use those hours to recieve his bonus

Or set a global task every 5-10 minutes, if player has more than the minutes needed, he should recieve his bonus
__________________

Last edited by Depresie; 02-24-2016 at 13:52.
Depresie is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 02-24-2016 , 15:01   Re: Best way to check if player's total time is equal to...
Reply With Quote #3

On client connect ?
Or you want exactly when he achieves x minutes?
siriusmd99 is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 02-24-2016 , 16:14   Re: Best way to check if player's total time is equal to...
Reply With Quote #4

Are you saving players time with NVault or MYSQL?
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-24-2016 , 18:33   Re: Best way to check if player's total time is equal to...
Reply With Quote #5

I would use a thinking entity set to think every X seconds..depending on how accurate you want to acknowledge the time.

If you are checking at an even increment of the interval, you can use modulus.
PHP Code:
if ( PlayedSeconds  && !( PlayedSeconds TheIntervalSeconds ) )
{
      
//do whatever

Here's a little demo to do something every 5 whatever.
PHP Code:
new iSeconds;
const 
iInterval 5;
    
for ( 
iSeconds iSeconds <= 25 iSeconds++ )
{
    
server_print"%d % %d = %d %s" iSeconds iInterval iSeconds iInterval iSeconds && !( iSeconds iInterval ) ? "DO SOMETHING" "" );

Output
Code:
0  5 = 0 
1  5 = 1 
2  5 = 2 
3  5 = 3 
4  5 = 4 
5  5 = 0 DO SOMETHING
6  5 = 1 
7  5 = 2 
8  5 = 3 
9  5 = 4 
10  5 = 0 DO SOMETHING
11  5 = 1 
12  5 = 2 
13  5 = 3 
14  5 = 4 
15  5 = 0 DO SOMETHING
16  5 = 1 
17  5 = 2 
18  5 = 3 
19  5 = 4 
20  5 = 0 DO SOMETHING
21  5 = 1 
22  5 = 2 
23  5 = 3 
24  5 = 4 
25  5 = 0 DO SOMETHING
Thinking entity example:
PHP Code:
#include <amxmodx>
#include <engine>

const Float:EntityInterval 1.0;

new 
g_Entity;

public 
plugin_init() 
{
    
g_Entity create_entity"info_target" );
    
entity_set_stringg_Entity EV_SZ_classname "BonusChecker" );
    
register_think"BonusChecker" "EntityThink" );
    
    
//Use this when you want to start it.
    
entity_set_floatg_Entity EV_FL_nextthink , ( get_gametime() + EntityInterval ) );
}

public 
EntityThinkiEntity )
{
    if( 
iEntity == g_Entity 
    {
        
//Do stuff here.

        //Use this to make it repeat.
        
entity_set_floatg_Entity EV_FL_nextthink , ( get_gametime() + EntityInterval ) );
    }

__________________

Last edited by Bugsy; 02-24-2016 at 19:36.
Bugsy is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-26-2016 , 08:57   Re: Best way to check if player's total time is equal to...
Reply With Quote #6

Thank you for all the answers. I'll probably use an entity and set it on 60 seconds.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
xSav
Junior Member
Join Date: Jun 2010
Old 04-29-2016 , 06:54   Re: Best way to check if player's total time is equal to...
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post

Thinking entity example:
PHP Code:
#include <amxmodx>
#include <engine>
...
        
entity_set_floatg_Entity EV_FL_nextthink , ( get_gametime() + EntityInterval ) );
    }


Will code work if I change the map?
xSav 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 01:05.


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