View Full Version : vBulletin Hook Help
James Birkett
08-18-2009, 09:43 PM
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?
Lynne
08-18-2009, 09:51 PM
You want the *postbit* template to show it? If so, you probably want a hook location like postbit_display_complete (or postbit_display_start).
James Birkett
08-18-2009, 09:54 PM
Thanks Lynne,
How would I begin this?
if(($user['userid'] == 1) && ($post[field5] == true)) {?
Lynne
08-18-2009, 10:11 PM
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?
James Birkett
08-18-2009, 11:28 PM
Yeah.
I was thinking (based off your current code):
if((user['userid'] == 1) && ($post[field5])) {
$post[field5] == '(some random generic testing text)';
}
Lynne
08-19-2009, 12:07 AM
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!!!):
$random = rand(1,2);
if ($random == 1) field5 = username 1;
else field5 = username 2;
James Birkett
08-19-2009, 12:59 AM
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.
$username = array('Username 1','Username 2');
$rand = rand(0,1);
$post[field5] == $username['rand'];
What about that?
Lynne
08-19-2009, 02:56 AM
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.
James Birkett
08-19-2009, 02:45 PM
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.
Lynne
08-19-2009, 03:59 PM
I added this to postbit_display_complete and it worked just fine (and added $testing to my postbit):
$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].
James Birkett
08-19-2009, 11:09 PM
Thanks Lynne, that seems to have worked.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.