Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

(MyBB) Minecraft Skin Avatar Changer (grabs there skin and sets it as there avatar)

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

<?php
//Credit For API - ZERO
//I got the API From - https://hackforums.net/showthread.php?tid=2640822
    
$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);
?>

changeavatar.php BE SURE TO EDIT WHAT NEEDS TO BE EDITED
PHP Code

<?php 
////////////////////////////////
/// Created By: Agentsix1 //
///////////////////////////////
//Place The Same Details You Used For Forums Mysql
//EDIT ME
$mysqlhost = "";
$mysqluser = "";
$mysqlpass = "";
$mysqldb = "";

//Do not edit beyond this point
$FUTC = $_POST['FUTC'];
$SA = $_POST['setavatar'];

$avatarcon=mysqli_connect($mysqlhost,$mysqluser,$mysqlpass,$mysqldb);
if (
mysqli_connect_errno()) {
    throw new 
Exception(mysqli_connect_error(), mysqli_connect_errno());
}

$img = "avatar.php?user=".$SA;
mysqli_query($avatarcon,"UPDATE mybb_users SET avatar='$img' WHERE username='$FUTC'");
echo 
'Redirecting To Home Page<br>';
echo 
'<br>Image: <a href='.$img.'><img src='.$img.'></img></a>';

mysqli_close($avatarcon);

echo 
'<meta http-equiv="refresh" content="0; url=usercp.php" />';


?>

2. Edit the template under User Control Panel Templates - usercp
Find Something that looks a little bit like :
PHP Code

<?php 
<td class="trow2">
<
span class="largetext">{$username}</span><br />
<
strong>{$lang->postnum}</strong> <a href="search.php?action=finduser&amp;uid={$mybb->user['uid']}">{$mybb->user['posts']}</a> {$lang->posts_day}<br />
{
$reputation}
<
strong>{$lang->email}</strong> {$mybb->user['email']}<br />
<
strong>{$lang->registration_date}</strong> {$regdate}<br />
<
strong>{$lang->primary_usergroup}</strong> {$usergroup}<br />
{
$referral_info}
</
td>
</
tr>
</
table> 

Now below this you need to put the following:
PHP Code

<?php 
<br>
<
table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder">
<
tr>
<
td class="thead" colspan="{$colspan}"><strong>Set Avatar To Minecraft Skin</strong></td>
</
tr>
<
tr>
<
td class="trow2">
<
center>
<
br>
<
form action="changeavatar.php" method="post"> Enter minecraft username to change avatar: 
<
input style="background-color: black;color:white;" type="text" name="setavatar" value=""> <input type="submit" value="Change Avatar"> <br><br>
<
input type="hidden" name="FUTC" value="{$mybb->user['username']}"></form>
 
Want a different avatar that is not a minecraft character? - 
<
a href="usercp.php?action=avatar">[Click Here]</a><br><br>
</
center>
</
td>
</
tr>
</
table> 

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 :)
I can't seem to get this working on my website, I enter my minecraft username and it gets the skin but doesn't seem to set the avatar? any idea why that may be?


Possibly Related Threads...
Thread / Author Replies Views Last Post
by ๖ۣۜZerØDec 17, 2014 01:31 PM 15 1,680 Dec 17, 2014 01:31 PM
Last Post: Qwe2390
by PpexilMay 7, 2014 12:46 PM 3 274 May 7, 2014 12:46 PM
Last Post: brewery
by rivalzoneNov 30, 2012 03:43 PM 6 269 Nov 30, 2012 03:43 PM
Last Post: rivalzone