3
« on: June 01, 2014, 04:40:08 AM »
I was going to post this on the original thread, but the topic was too old. This is to help people make a copy of their player avatar in a gui. I basically took iBan's code and rewrote it for my own gui because I didn't understand how it was supposed to work. I know its probably not really needed, but it probably won't hurt to have this code up somewhere. if anyone can explain a bit for me and if i'm doing everything really wrong let me know
code to make the avatar panel in your .gui
new GuiObjectView(MetroGuiStats_Avatar) {
profile = "GuiDefaultProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "0 0";
extent = "185 320";
minExtent = "8 2";
visible = "1";
cameraZRot = "0";
forceFOV = "0";
lightDirection = "-0.57735 0.57735 0.77735";
lightColor = "0.600000 0.580000 0.500000 1.000000";
ambientColor = "0.400000 0.400000 0.400000 1.000000";
};
code to populate the avatar (run from a client.cs)
first it clears your object then goes through your prefs to add nodes to the object
function clientcmdUpdate_Avatar()
{
//clears then adds the avatar object walking
MetroGuiStats_Avatar.setEmpty();
MetroGuiStats_Avatar.dynamicObject = "fffObject";
MetroGuiStats_Avatar.setObject(MetroGuiStats_Avatar.dynamicObject, "base/data/shapes/player/m.dts", "", 0);
MetroGuiStats_Avatar.setSequence(MetroGuiStats_Avatar.dynamicObject, 0, "headup", 0);
MetroGuiStats_Avatar.setSequence(MetroGuiStats_Avatar.dynamicObject, 1, "run", 0.85);
MetroGuiStats_Avatar.setOrbitDist(0);
//hide all nodes
%nodeCount = 0;
%node[%nodeCount++] = "helmet";
%node[%nodeCount++] = "pointyHelmet";
%node[%nodeCount++] = "flareHelmet";
%node[%nodeCount++] = "scoutHat";
%node[%nodeCount++] = "copHat";
%node[%nodeCount++] = "knitHat";
%node[%nodeCount++] = "bicorn";
%node[%nodeCount++] = "Visor";
%node[%nodeCount++] = "plume";
%node[%nodeCount++] = "triPlume";
%node[%nodeCount++] = "septPlume";
%node[%nodeCount++] = "chest";
%node[%nodeCount++] = "femchest";
%node[%nodeCount++] = "pants";
%node[%nodeCount++] = "skirtHip";
%node[%nodeCount++] = "armor";
%node[%nodeCount++] = "bucket";
%node[%nodeCount++] = "cape";
%node[%nodeCount++] = "pack";
%node[%nodeCount++] = "quiver";
%node[%nodeCount++] = "tank";
%node[%nodeCount++] = "epaulets";
%node[%nodeCount++] = "epauletsRankA";
%node[%nodeCount++] = "epauletsRankB";
%node[%nodeCount++] = "epauletsRankC";
%node[%nodeCount++] = "epauletsRankD";
%node[%nodeCount++] = "ShoulderPads";
%node[%nodeCount++] = "LArm";
%node[%nodeCount++] = "LArmSlim";
%node[%nodeCount++] = "LHand";
%node[%nodeCount++] = "LHook";
%node[%nodeCount++] = "RArm";
%node[%nodeCount++] = "RArmSlim";
%node[%nodeCount++] = "RHand";
%node[%nodeCount++] = "RHook";
%node[%nodeCount++] = "pants";
%node[%nodeCount++] = "skirtHip";
%node[%nodeCount++] = "LShoe";
%node[%nodeCount++] = "LPeg";
%node[%nodeCount++] = "RShoe";
%node[%nodeCount++] = "RPeg";
%node[%nodeCount++] = "SkirtTrimLeft";
%node[%nodeCount++] = "SkirtTrimRight";
%node[%nodeCount++] = "LSki";
%node[%nodeCount++] = "RSki";
for(%i = 1; %i <= %nodeCount; %i++)
{
MetroGuiStats_Avatar.hideNode(MetroGuiStats_Avatar.dynamicObject, %node[%i]);
}
MetroGuiStats_Avatar.setIflFrame(MetroGuiStats_Avatar.dynamicObject, "face", getIflFrame("face", $Pref::Avatar::FaceName));
MetroGuiStats_Avatar.setIflFrame(MetroGuiStats_Avatar.dynamicObject, "decal", getIflFrame("decal", $Pref::Avatar::DecalName));
%nodeCount = 0;
%node[%nodeCount++] = "headSkin" TAB $Pref::Avatar::headColor;
if($Pref::Avatar::Chest == 0)
{
%chest = "chest";
} else {
%chest = "femchest";
}
%node[%nodeCount++] = %chest TAB $pref::Avatar::TorsoColor;
if($Pref::Avatar::LArm == 0)
{
%lArm = "LArm";
} else {
%lArm = "LArmSlim";
}
%node[%nodeCount++] = %lArm TAB $Pref::Avatar::lArmColor;
if($Pref::Avatar::RArm == 0)
{
%rArm = "RArm";
} else {
%rArm = "RArmSlim";
}
%node[%nodeCount++] = %rArm TAB $Pref::Avatar::rArmColor;
if($Pref::Avatar::LHand == 0)
{
%LHand = "LHand";
} else {
%LHand = "LHook";
}
%node[%nodeCount++] = %LHand TAB $Pref::Avatar::lHandColor;
if($Pref::Avatar::RHand == 0)
{
%RHand = "RHand";
} else {
%RHand = "RHook";
}
%node[%nodeCount++] = %RHand TAB $Pref::Avatar::rHandColor;
if($Pref::Avatar::Hip == 0)
{
%hip = "pants";
} else {
%hip = "skirtHip";
}
%node[%nodeCount++] = %hip TAB $Pref::Avatar::hipColor;
if($Pref::Avatar::LLeg == 0)
{
%LLeg = "LShoe";
} else {
%LLeg = "LPeg";
}
%node[%nodeCount++] = %LLeg TAB $Pref::Avatar::lLegColor;
if($Pref::Avatar::RLeg == 0)
{
%RLeg = "RShoe";
} else {
%RLeg = "RPeg";
}
%node[%nodeCount++] = %RLeg TAB $Pref::Avatar::rLegColor;
switch($pref::Avatar::Hat)
{
case 1:
%hat = "helmet";
if($pref::Avatar::Accent)
{
%accent = "Visor";
}
case 2:
%hat = "pointyHelmet";
case 3:
%hat = "flareHelmet";
case 4:
%hat = "scoutHat";
%accent = getAccent($pref::Avatar::Accent);
case 5:
%hat = "bicorn";
case 6:
%hat = "copHat";
%accent = getAccent($pref::Avatar::Accent);
case 7:
%hat = "knitHat";
%accent = getAccent($pref::Avatar::Accent);
}
if(%hat !$= "")
{
%node[%nodeCount++] = %hat TAB $pref::Avatar::HatColor;
}
if(%accent !$= "")
{
%node[%nodeCount++] = %accent TAB $pref::Avatar::AccentColor;
}
switch($pref::Avatar::Pack)
{
case 1:
%pack = "armor";
case 2:
%pack = "bucket";
case 3:
%pack = "cape";
case 4:
%pack = "pack";
case 5:
%pack = "quiver";
case 6:
%pack = "tank";
}
if(%pack !$= "")
{
%node[%nodeCount++] = %pack TAB $pref::Avatar::PackColor;
}
switch($pref::Avatar::SecondPack)
{
case 1:
%twopack = "epaulets";
case 2:
%twopack = "epauletsRankA";
case 3:
%twopack = "epauletsRankB";
case 4:
%twopack = "epauletsRankC";
case 5:
%twopack = "epauletsRankD";
case 6:
%twopack = "ShoulderPads";
}
if(%twopack !$= "")
{
%node[%nodeCount++] = %twopack TAB $pref::Avatar::SecondPackColor;
}
//populate nodes
for(%i = 1; %i <= %nodeCount; %i++)
{
MetroGuiStats_Avatar.unHideNode(MetroGuiStats_Avatar.dynamicObject, getField(%node[%i], 0));
MetroGuiStats_Avatar.setNodeColor(MetroGuiStats_Avatar.dynamicObject, getField(%node[%i], 0), getField(%node[%i], 1));
}
}
function getAccent(%accent)
{
switch(%accent)
{
case 1:
return "plume";
case 2:
return "triPlume";
case 3:
return "septPlume";
default:
return 0;
}
}
function getIflFrame(%node, %name)
{
%file = "base/data/shapes/player/" @ %node @ ".ifl";
if(isFile(%file))
{
%name = stripTrailingSpaces(fileBase(%name));
if(%name !$= "")
{
%fo = new FileObject() {};
%fo.openForRead(%file);
%hasFound = false;
%lineNum = 0;
while(!%fo.isEOF())
{
%line = %fo.readLine();
%thisDecal = stripTrailingSpaces(fileBase(%line));
if(%thisDecal $= %name)
{
%hasFound = true;
break;
}
else
{
%lineNum++;
}
}
%fo.close();
%fo.delete();
if(%hasFound)
{
return %lineNum;
}
else
{
return 0;
}
}
else
{
return 0;
}
}
else
{
echo("\c2getIflFrame(\"" @ %node @ "\", \"" @ %name @ "\") : You did not supply a proper IFL file name to read from.");
return 0;
}
}