![]() |
|
[TUTORIAL] Minecraft skin as avatar in MyBB - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Webmasters (https://hackforums.net/forumdisplay.php?fid=141) +---- Forum: Website Construction (https://hackforums.net/forumdisplay.php?fid=50) +---- Thread: [TUTORIAL] Minecraft skin as avatar in MyBB (/showthread.php?tid=2640822) Pages: Pages
1
2
|
[TUTORIAL] Minecraft skin as avatar in MyBB - ๖ۣۜZerØ - Jul 2, 2012 Well, I set up a website for a Minecraft forum a while back, and set it so that upon registering, all users had to enter their Minecraft username. This was used to grab their skin, resize it, then replace their avatar with that image everywhere it appears. I got bored and decided to write a tutorial on how to do it. I did not write the PHP code from scratch, I got the idea from a thread I saw on a different website. To start with, you will need to make a custom profile field called "Minecraft name". Note down the ID of this field. By default, if you have no other custom profile fields, it will be 4. This tutorial assumes that you're using fid4. If not, just replace every fid4 with whatever ID your custom profile field has. Now, save the following code as avatar.php and upload it to your website directory: Code <?phpTo call a player's avatar, simply go to avatar.php?user=[NAME]. Now, you have to change the avatar to this image everywhere it appears. The simplest is the postbit. postbit_avatar template, and change the contents to this: Code <a href="{$post['profilelink_plain']}"><img src="avatar.php?user={$post['username']}" alt="" {$avatar_width_height} /></a>The next part depends on your theme. In the welcome box, there is not always an avatar. In my theme, there wasn't, but it's very simple to do this part. Just open the header_welcomeblock_member template, and find the line where it calls the avatar image [I'll post this line when I get a theme with this feature]. Replace the avatar with: Code <img src="avatar.php?user={$mybb->user['fid4']}" alt="" {$avatar_width_height} />This just grabs the user you're logged in as, and displays their minecraft skin. Next is the memberlist section. Open the memberlist_user_avatar template, and replace the whole contents with this: Code <img src="avatar.php?user={$user['fid4']}" alt="" {$avatar_width_height} />Next you will want to edit the avatar displayed on the user's profile. Open the member_profile template, and navigate to this: Code {avatar}And replace it with: Code <img src="avatar.php?user={$userfields['fid4']}" />Next, navigate to usercp_avatar_current. Replace the entire contents of this template with this code: Code <td class="trow1" width="150" align="right"><img src="avatar.php?user={$user['fid4']}" alt="{$lang->avatar_mine}" title="{$lang->avatar_mine}" {$avatar_width_height} /></td>And replace the contents of usercp_currentavatar with: Code <td class="trow1" valign="middle" align="center" width="1"><div class="usercp_container"><img src="avatar.php?user={$mybb->user['fid4']}" alt="{$mybb->user['username']}" title="{$mybb->user['username']}" {$avatar_width_height} /></div></td>Now you'll probably want to prevent users from changing their avatar so it doesn't mess the whole thing up. Open up usercp_nav_profile and find the line: Code <div><a href="usercp.php?action=avatar" class="usercp_nav_item usercp_nav_avatar">{$lang->ucp_nav_change_avatar}</a></div>Now, delete that line. This removes the "Change Avatar" linkfrom the user control panel. Next, open the usercp_avatar template, and replace the entire contents with this: Code <html>This will prevent users from changing their avatar by going directly to the URL. If you have announcements through the portal page enabled on your forum, you will probably want to change the avatar displayed on each announcement to the user's skin too. Unfortunately, I haven't figured out how to do this yet. I'll post here when I figure it out. I think it's: Code <img src="avatar.php?user={$announcement_user['fid4']}" />If anybody can replace the {avatar} line in portal_announcement and tell me if it works, that would be great. Unfinished tutorial. I'll finish this when I have another MyBB site running. * - eikik1 - Jul 2, 2012 Nice tutorial. I have personally been on the website which you used this on, and I think it went very well. It makes it a lot better, I think this tutorial was usefull too :D * - система - Jul 2, 2012 Really simple method to tweak a piece of the char image. If coded yourself good job! * - ๖ۣۜZerØ - Jul 2, 2012 (Jul 2, 2012 02:02 PM)CasvDongen Wrote: Really simple method to tweak a piece of the char image. If coded yourself good job! The actual code was done by me, but a friend told me a method of doing it. So really, he figured out how and I coded it :P * - Focnr - Jul 2, 2012 Wow, very neat. Finally a useful tutorial on here! ;) * - ๖ۣۜZerØ - Jul 3, 2012 (Jul 2, 2012 06:10 PM)Focnr Wrote: Wow, very neat. Finally a useful tutorial on here! ;) Thanks! I've had this for a while, just never really bothered posting it anywhere. I'll add more detail when I have another MyBB site running, all those templates were just from memory, so I'm not entirely sure what line was there originally. * - markofn1 - Jul 3, 2012 Great tutorial, the result is awesome :) * - ๖ۣۜZerØ - Jul 3, 2012 (Jul 3, 2012 08:38 AM)markofn1 Wrote: Great tutorial, the result is awesome :) Glad you liked it! I'll post a link to my website after it's up to give a demonstration of what can be done with this. * - Motivаtion - Aug 14, 2012 Pretty neat tutorial :) (Bumping this because I feel people could benefit from this :D) * - juliando - May 10, 2013 If you need to fix it for 1.6.10 : Replace "{$post['fid4']}" to "{$post['username']}" ! * - ๖ۣۜZerØ - May 11, 2013 (May 10, 2013 07:40 AM)juliando Wrote: If you need to fix it for 1.6.10 : Ah, thanks for that. I'll update the original post with this. * - CatSoup - May 11, 2013 You could always use Minotar, https://minotar.net/ Pretty sure they support this, as well as have a tutorial on how to set this up. The only place i have ever seen this done is with Enjin Forums. O well. Good Luck! 🤝 * - KRMFY - May 26, 2013 The avatar doesn't show up on the postbit and memberlist for me. I'm using 1.6.10. * - ๖ۣۜZerØ - Jul 7, 2013 (May 26, 2013 06:43 PM)KRMFY Wrote: The avatar doesn't show up on the postbit and memberlist for me. I'm using 1.6.10. Yeah, I haven't updated this in a while, I no longer run any MyBB forums, so I'm not up to date with it. * - agentsix1 - Mar 5, 2014 Hey guys after some updating I hope this helps you guys out with letting users get minecraft avatars ps I am not the best at coding php which is why I did not code this into a plugin with a auto installer. I am actually rather new to mybb and thought I would provide something that I have never seen any one use. You are free to make use of this in any way you please. You are also welcome to re doing the code and re releasing it. I was just providing something that i have done. How ever if you keep most of the code the same please give me a little bit of credit thanks :). What does this do: This grabs the minecraft head of the user that is inserted into the box and sets there avatar to it. How does it work: It has a api which grabs the image reconstructs it then out puts a link of which then sets the avatar for the user. Welcome Box Version Lets get into installing this 1. Copy Files To Root Directory of Forums avatar.php PHP Code changeavatar.php PHP Code 2. Edit the template under User Control Panel Templates - usercp Find Something that looks a little bit like : PHP Code Now below this you need to put the following: PHP Code Alright all you need to do now is go to your user CP and it should be working good. If you have issues do not be afraid to ask :) |