Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 10-24-2013, 11:12 AM
Jon12345 Jon12345 is offline
 
Join Date: Nov 2002
Posts: 127
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Randomly running some code

I have some ad code, but only want to show it with a 1 in 10 chance. The code is:

Code:
<div data-type="ad" data-publisher="abc.mysite.site" data-zone="ron" data-format="728x90"></div>
It will be in my postbit legacy template.

Is there any vbulletin code that allows me to do this?

Thanks,

Jon
Reply With Quote
  #2  
Old 10-24-2013, 12:36 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think this would work:
Code:
<if condition="TIMENOW%10==0">
<div data-type="ad" data-publisher="abc.mysite.site" data-zone="ron" data-format="728x90"></div>
</if>

Basically, whenever the current time (in seconds) ends in 0 it will show.
Reply With Quote
Благодарность от:
Max Taxable
  #3  
Old 10-24-2013, 12:42 PM
Jon12345 Jon12345 is offline
 
Join Date: Nov 2002
Posts: 127
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Clever idea, thanks! I will try that.

--------------- Added [DATE]1382625240[/DATE] at [TIME]1382625240[/TIME] ---------------

Seems to work. Would be nice to work out how to vary the probability of display. e.g 1 in 7 or whatever. So, I could say decide to set it to 1 in 7 or 1 in 5 etc.
Reply With Quote
  #4  
Old 10-24-2013, 03:15 PM
squidsk's Avatar
squidsk squidsk is offline
 
Join Date: Nov 2010
Posts: 969
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Jon12345 View Post
Clever idea, thanks! I will try that.

--------------- Added [DATE]1382625240[/DATE] at [TIME]1382625240[/TIME] ---------------

Seems to work. Would be nice to work out how to vary the probability of display. e.g 1 in 7 or whatever. So, I could say decide to set it to 1 in 7 or 1 in 5 etc.
Switch the number (i.e. 10) after the % to whatever you want, so 1 in 7 change the 10 to a 7, 1 in 5 change the 10 to a 5.
Reply With Quote
  #5  
Old 10-24-2013, 06:08 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, what squidsk said. I simplified the explanation a little, the code actually divides the unix time (seconds since Jan 1 1980 or something like that) by ten and checks that the remainder is 0, which happens when the last digit is 0 (since we're dividing by 10). But you can just as easily divide by 7 (or whatever) and check for a remainder of 0 to get a 1 in 7 chance.
Reply With Quote
  #6  
Old 10-25-2013, 12:31 PM
Jon12345 Jon12345 is offline
 
Join Date: Nov 2002
Posts: 127
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've tried using 2 and it showed my ads 1 in 2 chance. But when I tried 4 or 7, it didn't show 1 in 4 or 1 in 7 times. Maybe the maths is a bit out somehow? Do I need to clip off the decimals or something?
Reply With Quote
  #7  
Old 10-25-2013, 12:42 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm...'%' should divide integers and return the remainder, so I don't think decimals should matter. So you're saying condition="TIMENOW%7==0" doesn't work right?
Reply With Quote
  #8  
Old 10-25-2013, 01:02 PM
Jon12345 Jon12345 is offline
 
Join Date: Nov 2002
Posts: 127
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am trying 1 in 4 right now. TIMENOW%4==0

See it in action (or not as the case may be!):http://access-programmers.co.uk/foru...ar#post1301767

The third post has a 300x250 advert. There should be another one appearing to the right of that one 1 in 4 times. But it doesn't.
Reply With Quote
  #9  
Old 10-25-2013, 01:22 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, I ran a test and it seems to work. Are you saying that the exact code works with 10 or 2 but not 4 or 7 (I guess I'm saying, are you sure there's not a typo)? If you do this (add the 1|| in the condition):
Code:
<if condtion="1||TIMENOW%4==0">
Ad code
</if>

then it should show every time and you can make sure there's not something else wrong.

The only other thing I can think of is that it's not exactly random because it's based on the time, so if for example you have it set to 4 and you constantly hit reload, and the page happens to take about 4 seconds to load each time, you may end up with something that looks like it's not a 1 in 4 chance.
Reply With Quote
  #10  
Old 10-25-2013, 02:16 PM
Jon12345 Jon12345 is offline
 
Join Date: Nov 2002
Posts: 127
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

My code is:

Code:
<if condition="TIMENOW%4==0">
<td>
<div data-type="ad" data-publisher="xxx.mysite.site" data-zone="ron" data-format="300x250"></div>
</td>
</if>
I got it to show 2 out of 13 goes. Maybe I was just unlucky with my first few tries. I will try 1 in 3.
Reply With Quote
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. The time now is 05:35 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06982 seconds
  • Memory Usage 2,257KB
  • 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
  • (4)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete