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 08-18-2009, 09:43 PM
James Birkett James Birkett is offline
 
Join Date: Jun 2009
Posts: 633
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default vBulletin Hook Help

I have a custom profile field, and I have multiple options that can fill this field.
I have this profile field displayed on the postbit and I want it to display a result at random.

Scenario:
My profile field is: Username
I have 2 usernames: Username 1 and username 2.

I want the postbit to show username 1 and 2, but not at the same time. Maybe it shows Username 1 first, then username 2 on a refresh etc.

I am not sure which hook to use, would it be a showthread or would it be member_customfields.. or another one?
Reply With Quote
  #2  
Old 08-18-2009, 09:51 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You want the *postbit* template to show it? If so, you probably want a hook location like postbit_display_complete (or postbit_display_start).
Reply With Quote
  #3  
Old 08-18-2009, 09:54 PM
James Birkett James Birkett is offline
 
Join Date: Jun 2009
Posts: 633
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Lynne,
How would I begin this?
PHP Code:
if(($user['userid'] == 1) && ($post[field5] == true)) { 
?
Reply With Quote
  #4  
Old 08-18-2009, 10:11 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, it depends on what you are trying to say with the condition. If you simply care if field5 exists, then you just say && $post['field5'] - you don't need to say equals true. And you are only doing this only for userid 1?
Reply With Quote
  #5  
Old 08-18-2009, 11:28 PM
James Birkett James Birkett is offline
 
Join Date: Jun 2009
Posts: 633
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah.
I was thinking (based off your current code):
PHP Code:
if((user['userid'] == 1) && ($post[field5])) {
$post[field5] == '(some random generic testing text)';

Reply With Quote
  #6  
Old 08-19-2009, 12:07 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah. You may be able to just use rand() to pick a random number and then based on that spit out a different field5. It's hard to guess exactly what to do given the posted information. Something like (not real php below!!!):
PHP Code:
$random rand(1,2);
if (
$random == 1field5 username 1;
else 
field5 username 2
Reply With Quote
  #7  
Old 08-19-2009, 12:59 AM
James Birkett James Birkett is offline
 
Join Date: Jun 2009
Posts: 633
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Lynne, I guessed as much.
My forum is based around an online gaming community, and I have multiple usernames so I want it to randomly display each one. (Can rand() be used with strings?).
Just need it to display either or, really.
PHP Code:
$username = array('Username 1','Username 2');
$rand rand(0,1);
$post[field5] == $username['rand']; 
What about that?
Reply With Quote
  #8  
Old 08-19-2009, 02:56 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't know if that would work. I'm a trial and error coder. (I'm terrible at remembering syntax!) Just try it and see.
Reply With Quote
  #9  
Old 08-19-2009, 02:45 PM
James Birkett James Birkett is offline
 
Join Date: Jun 2009
Posts: 633
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
if(($user['userid'] == 1) && ($post[field5])) {
$array = array("Test 1","Test 2");
shuffle($array);
$post[field5] = $array[0];

I've tried that code on postbit_display_start and postbit_display_complete with no luck.
Reply With Quote
  #10  
Old 08-19-2009, 03:59 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I added this to postbit_display_complete and it worked just fine (and added $testing to my postbit):
PHP Code:
$array = array("Test 1","Test 2");
shuffle($array);
$testing $array[0]; 
So, I'd say your condition is wrong. First off, $user is most likely not valid. If this is the person who is posting, then that would be $this->post['userid'] . And, you should probably be using $post['field5'], not $post[field5].
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 01:14 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.04432 seconds
  • Memory Usage 2,259KB
  • Queries Executed 11 (?)
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
  • (6)bbcode_php
  • (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
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (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_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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete