Quantcast
Channel: MyBB Community Forums - Tutorials
Viewing all articles
Browse latest Browse all 690

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

$
0
0
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 Smile.


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 - http://www.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$skin00$face_x$face_y,
  
$avatar_width$avatar_height$face_width$face_height);

    
imagecopyresized($avatar$skin00$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:
<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:
<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 Smile

Viewing all articles
Browse latest Browse all 690

Trending Articles