Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 02-20-2009, 02:09 PM
Vaupell's Avatar
Vaupell Vaupell is offline
 
Join Date: Apr 2008
Location: Esbjerg, Denmark
Posts: 1,036
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default counting time from a user action

i want to count 10 minuttes from a action.

A user clicks a botton / or another event happens that triggers a timestamp
to be marked.

how would i go about counting 10 minuttes, and activate a trigger after
those 10 minuttes ?

sort of a delay, and perhaps ewen if the user hits refresh
the display would just show something like 5minuttes togo.

all i need is the counting, i have no clue or no idea where to begin.
Reply With Quote
  #2  
Old 02-21-2009, 03:31 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

And this is used for?
Reply With Quote
  #3  
Old 02-21-2009, 04:13 AM
vbplusme vbplusme is offline
 
Join Date: Sep 2008
Location: CyberSpace
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think you might need to use a javascript function to get were you want to go.
Reply With Quote
  #4  
Old 02-21-2009, 05:34 AM
TigerC10's Avatar
TigerC10 TigerC10 is offline
 
Join Date: Apr 2006
Location: Austin, TX
Posts: 616
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by vbplusme View Post
I think you might need to use a javascript function to get were you want to go.
That would require a user to stay on the page for 10 minutes and not navigate away. Very not cool from a design standpoint.

Quote:
Originally Posted by Vaupell View Post
A user clicks a botton / or another event happens that triggers a timestamp to be marked.
Very easy to add a timestamp to a database.

Quote:
Originally Posted by Vaupell View Post
how would i go about counting 10 minuttes, and activate a trigger after
those 10 minuttes ?
Not very easy to make a "trigger" after 10 minutes. You might consider using what's known as a CRON job. CRON jobs are scripts that get executed every 5/10/15/30/60/1440 minutes. There's no real way to guarantee that the trigger will be executed exactly 10 minutes after someone sets the timestamp - the cron job will just run at the set intervals. So if someone initaties the trigger right before your cron job runs - then the script will pass them over since it hasn't been 10 minutes for them. They may have to wait 12 minutes, or even 15... All the way up to 19 minutes for the next cron job script to come along and unset the delay.

Quote:
Originally Posted by Vaupell View Post
sort of a delay, and perhaps ewen if the user hits refresh
the display would just show something like 5minuttes togo.
Okay, hang on. Do you want a trigger or do you just want a delay? Because delays are much easier...

Say you've got a table in the database called "delay_timestamps"... It would have the fields "userid" and "timestamp".

Insert or update the field with the user like so
PHP Code:
$db->query_write("INSERT INTO ".TABLE_PREFIX."delay_timestamps (userid, timestamp) VALUES ".$userid.", ".time() );
// or...
$db->query_write("UPDATE ".TABLE_PREFIX."delay_timestamps SET timestamp=".time()." WHERE userid=".$userid );


// OR even better - this handles insert and update in 1 SQL statement
// but you have to set the userid field in the table as the key
// shouldn't be a problem since userids should be unique anyway

$db->query_write("INSERT ON DUPLICATE KEY UPDATE INTO ".TABLE_PREFIX."delay_timestamps (userid, timestamp) VALUES ".$userid.", ".time() ); 
Then in your "refresh" page you'll want to have a look see at the timestamp in the database and compare it with the current time:

PHP Code:
$wait_time 5// set the wait time they have before accessing the page again

$current_time time();

$user_timestamp $db->query_first("SELECT timestamp FROM ".TABLE_PREFIX."delay_timestamps WHERE userid=".$userid );

$number_of_seconds_since_stamp $current_time $user_timestamp;

$minutes_since_timestamp $number_of_seconds_since_stamp 60;

if(
$minutes_since_timestamp $wait_time)
{
     echo 
'Sorry, you still have '$wait_time-$minutes_since_timestamp .' minutes left...';
}
else
{
     echo 
'How sweet, you waited for me!';


This, of course, isn't the exact code you'll want... Certainly you'll want to condense the code down, like the $number_of_seconds_since_stamp variable is totally worthless - you can just divide by 60 on the fly. The timestamp variable in the database should probably be of type INTEGER, be careful not to use something like SMALLINT because it's not big enough for the timestamp. However, this will require an action from your user - it's not a trigger. It will require the user to click refresh, or to view the page again in some way.

You might be able to work out some AJAX thing that starts up on every single page that checks for the time remaining and then starts an auto-refresh count down... But it'd be kinda wasteful in my opinion. Plus, some browsers disable the javascript redirects/refreshes.
Reply With Quote
  #5  
Old 02-21-2009, 07:14 AM
vbplusme vbplusme is offline
 
Join Date: Sep 2008
Location: CyberSpace
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

At this point, I am with DM and wondering now what the problem is that needs to be solved?
Reply With Quote
  #6  
Old 02-21-2009, 10:39 AM
TigerC10's Avatar
TigerC10 TigerC10 is offline
 
Join Date: Apr 2006
Location: Austin, TX
Posts: 616
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by vbplusme View Post
At this point, I am with DM and wondering now what the problem is that needs to be solved?
Eh, I guess I'm a programmer at heart. I don't care what I program, I just need a directive. Haha.

But, judging from his recent posts, it looks like he's trying to set a timer on submitting scores to ibProArcade - maybe to prevent cheating...
Reply With Quote
  #7  
Old 02-21-2009, 12:24 PM
vbplusme vbplusme is offline
 
Join Date: Sep 2008
Location: CyberSpace
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Got it. Now, it makes a lot of sense to me, thanks for that update.
Reply With Quote
  #8  
Old 02-23-2009, 04:45 PM
Vaupell's Avatar
Vaupell Vaupell is offline
 
Join Date: Apr 2008
Location: Esbjerg, Denmark
Posts: 1,036
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hi guys, hehe well i have made a small textbased rpg game like the ones you know from
around the web and facebook, but running on vbulletin.
but needed somekind of limit of actions turns pr day or turns pr hour,
and thought well turns pr 10 minuttes would be the way to go.

but got stuck on another project so havent been looking into it the lasy couple of days.
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

Forum Jump


All times are GMT. The time now is 08:57 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04010 seconds
  • Memory Usage 2,237KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_php
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete