Jul 2, 2012 01:18 PM
(This post was last modified: May 11, 2013 09:27 AM by ๖ۣۜZerØ.)
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:
To 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:
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:
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:
Next you will want to edit the avatar displayed on the user's profile. Open the member_profile template, and navigate to this:
And replace it with:
Next, navigate to usercp_avatar_current. Replace the entire contents of this template with this code:
And replace the contents of usercp_currentavatar with:
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:
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:
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:
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.
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
<?php
$face_x = 8;
$face_y = 8;
$face_width = 8;
$face_height = 8;
$mask_x = 40;
$mask_y = 8;
$mask_width = 8;
$mask_height = 8;
$avatar_width = 96;
$avatar_height = 96;
$default_skin_url = 'http://www.minecraft.net/images/char.png';
if (isset($_GET['user'])) {
$user = $_GET['user'];
$skin = @imagecreatefrompng("http://s3.amazonaws.com/MinecraftSkins/$user.png");
}
if (!$skin) {
$skin = imagecreatefrompng($default_skin_url);
}
$avatar = imagecreatetruecolor($avatar_width, $avatar_height);
imagecopyresized($avatar, $skin, 0, 0, $face_x, $face_y,
$avatar_width, $avatar_height, $face_width, $face_height);
imagecopyresized($avatar, $skin, 0, 0, $mask_x, $mask_y,
$avatar_width, $avatar_height, $mask_width, $mask_height);
header('Content-Type: image/png');
imagepng($avatar);
imagedestroy($avatar);
?>To 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>
<head>
<title>{$mybb->settings['bbname']} - {$lang->change_avatar}</title>
{$headerinclude}
</head>
<body>
{$header}
<table width="100%" border="0" align="center">
<tr>
{$usercpnav}
<td valign="top">
Sorry, avatars are disabled on this board.
</td>
</tr>
</table>
{$footer}
</body>
</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.



