random face code generator.

Users who are viewing this thread

Sucker Punch

Sergeant at Arms
Ingolifs said:
one of those 'random faces' is consable hareck.
many of them look quite strange. Goes to show that random isn't always good.

Yeah, top left is hareck.  The rest are new faces.
Figured I should have a reference for the NPC I was editing.
 

Yoshiboy

Count
M&BWB
bryce777, its not possible to change the face codes in game. This is external. Sucker Punch, doesn't look too bad but i think it would be better with not completely random. Clearly also you need to make sure it doesnt generate blonde haired asians and the such :razz:
 

bryce777

Count
Yoshiboy said:
bryce777, its not possible to change the face codes in game. This is external. Sucker Punch, doesn't look too bad but i think it would be better with not completely random. Clearly also you need to make sure it doesnt generate blonde haired asians and the such :razz:

That sucks.  I was hoping there was some way to create characters on the fly.
 

jamoecw

Knight
M&BWBWF&SNWVC
a python script would allow for companions to have a random face every time you start a new game, and for troops there is already an in game random face generater, a fairly basic one but i think yoshi wants an external generator for ease of use in making faces for companions and still have them consistant for each mod.
 

Iceblzzrd

Why not have the program select a random face from a list and have the community contribute faces they have made?
 

Voutare

Master Knight
Because he said he has thousands (or hundreds) of NPC's that need faces. And that is a lot of moving sliders around. That would mean that every person on the forum would have to make one. And people that would acctually want to do it, would be minimal (see extra NPC mod). It would take forever too. A simple program (well, not simple) but a program that makes 'normal' faces is just as good. And about 1000 times faster.
 

bryce777

Count
Out of the goodness of my heart, I have made you a face code generator, yoshiboy.

The file format does not work like you think.  Each of the bottom sliders gets 3 bits so there are 4 sliders per 3 hex characters.  Also, there are only 10 leading 0s.

The beauty of this script is that you give it a range of values.  So if you want the script to generate out asians, you just take two asiany faces and the results will all be between those two values. 

I thought of adding in parameters to it so you could specifically give it a list of beards and skins and crap, but this seems to work pretty good already so I didn't bother.  Let me know if you encounter any bugs or anything.

Anyone is free to use it without asking permission!  This is in perl, btw.




Code:
sub generateRawRandomFace
{

    return &generateRandomFace("0000001c0000000000000", 
                               "10940901f8ffffffffffff");
}


sub generateRandomFace
{
    #0x00000000000c600301c2510211a5b292 -marnid
    #0x00000000000c000001c0000000000000 - min face
    #0x0000000000
    #0x00000000000c600301c2510211a5b292
    #            10940901f8ffffffffffff
    my $lowerCode = $_[0];
    my $upperCode = $_[1];

    my $finalCode = "0x0000000000";

    my $lowerHair = substr($lowerCode, 0, 2);
    my $upperHair = substr($upperCode, 0, 2);


    $lowerHair = hex($lowerHair)/4;
    $upperHair = hex($upperHair)/4;

    my $lowerCode = substr($lowerCode, 2);
    my $upperCode = substr($upperCode, 2);

    if($lowerHair>$upperHair)
    {
        my $swap = $upperHair;
        
        $upperHair=$lowerHair;
        $lowerHair=$swap;
    }
 

    my $range = $upperHair-$lowerHair;



    my $randomValue = int(rand($range+1));

    $randomValue = ($randomValue + $lowerHair)*4;



    my $hairCode = sprintf("%x", $randomValue);

    if(length($hairCode)<2)
    {
        $hairCode = "0".$hairCode;
    }


    $finalCode = $finalCode."$hairCode";



    my $lowerSkin = substr($lowerCode, 0, 1);
    my $upperSkin = substr($upperCode, 0, 1);

    if($lowerSkin>$upperSkin)
    {
        my $swap = $upperSkin;
        
        $upperSkin=$lowerSkin;
        $lowerSkin=$swap;
    }
   

    $lowerCode = substr($lowerCode, 1);
    $upperCode = substr($upperCode, 1);

    $range = $upperSkin-$lowerSkin;

    $randomValue = int(rand($range+1));


    my $finalValue = $randomValue + $lowerSkin;

    $finalCode = $finalCode."$finalValue";




    $lowerBeard = substr($lowerCode, 0, 2);
    $upperBeard = substr($upperCode, 0, 2);

    #print "lowerBeard = $lowerBeard\n";
    #print "upperBeard = $upperBeard\n";

    $lowerBeard = hex($lowerBeard)/4;
    $upperBeard = hex($upperBeard)/4;

    if($lowerBeard>$upperBeard)
    {
        my $swap = $upperBeard;

        $upperBeard=$lowerBeard;
        $lowerBeard=$swap;
    }


    $lowerCode = substr($lowerCode, 2);
    $upperCode = substr($upperCode, 2);


    $range = $upperBeard-$lowerBeard;


    $randomValue = int(rand($range+1));

    $randomValue = ($randomValue + $lowerBeard)*4;


    my $beardCode = sprintf("%x", $randomValue);

    if(length($beardCode)<2)
    {
        $beardCode = "0".$beardCode;
    }


    $finalCode = $finalCode."$beardCode";


    my $lowerHair = substr($lowerCode, 0, 1);
    my $upperHair = substr($upperCode, 0, 1);

    if($lowerHair>$upperHair)
    {
        my $swap = $upperHair;

        $upperHair=$lowerHair;
        $lowerHair=$swap;
    }

    $lowerCode = substr($lowerCode, 1);
    $upperCode = substr($upperCode, 1);



    $range = $upperHair-$lowerHair;

    $randomValue = int(rand($range+1));

    my $finalValue = $randomValue + $lowerHair;


    $finalCode = $finalCode."$finalValue";



    #remove that 01 thing
    $lowerCode = substr($lowerCode, 2);
    $upperCode = substr($upperCode, 2);
    $finalCode = $finalCode."01";




    my $lowerEyebrows = substr($lowerCode, 0, 2);
    my $upperEyebrows = substr($upperCode, 0, 2);

    $lowerEyebrows = hex($lowerEyebrows);
    $upperEyebrows = hex($upperEyebrows);


    $lowerEyebrows = $lowerEyebrows-192;
    $upperEyebrows = $upperEyebrows-192;


    $lowerEyebrows2 = $lowerEyebrows%8;
    $upperEyebrows2 = $upperEyebrows%8;

    if($lowerEyebrows2>$upperEyebrows2)
    {
        my $swap = $upperEyebrows2;

        $upperEyebrows2=$lowerEyebrows2;
        $lowerEyebrows2=$swap;
    }


    $lowerEyebrows = int($lowerEyebrows/8);
    $upperEyebrows = int($upperEyebrows/8);

    if($lowerEyebrows>$upperEyebrows)
    {
        my $swap = $upperEyebrows;

        $upperEyebrows=$lowerEyebrows;
        $lowerEyebrows=$swap;
    }


    $range = $upperEyebrows - $lowerEyebrows;


    $randomValue = int(rand($range+1));


    $finalValue = $lowerEyebrows+$randomValue;

    $finalValue = $finalValue*8;
    $finalValue = $finalValue+192;



    $range = $upperEyebrows2 - $lowerEyebrows2;


    $randomValue = int(rand($range+1));


    $finalValue = $finalValue+$randomValue+$lowerEyebrows2;


    $finalValue = sprintf("%x", $finalValue);

    $finalCode = "$finalCode".$finalValue;


    $lowerCode = substr($lowerCode, 2);
    $upperCode = substr($upperCode, 2);



    $finalValue = &chompFace(substr($lowerCode, 0, 3), 
                             substr($upperCode, 0, 3));

    $lowerCode = substr($lowerCode, 3);
    $upperCode = substr($upperCode, 3);


    $finalCode = "$finalCode".$finalValue;


    $finalValue = &chompFace(substr($lowerCode, 0, 3), 
                             substr($upperCode, 0, 3));

    $lowerCode = substr($lowerCode, 3);
    $upperCode = substr($upperCode, 3);


    $finalCode = $finalCode."$finalValue";



    $finalValue = &chompFace(substr($lowerCode, 0, 3), 
                             substr($upperCode, 0, 3));

    $lowerCode = substr($lowerCode, 3);
    $upperCode = substr($upperCode, 3);

    $finalCode = "$finalCode".$finalValue;



    $finalValue = &chompFace(substr($lowerCode, 0, 3), 
                             substr($upperCode, 0, 3));

    $lowerCode = substr($lowerCode, 3);
    $upperCode = substr($upperCode, 3);


    $finalCode = "$finalCode".$finalValue;

    if(length($finalCode)!=34)
    {
        $codeLength = length($finalCode);
        die "Bad code length of $codeLength\n";

    }
    


    return $finalCode;
}

sub chompFace
{
   my $lower = $_[0];
   my $upper = $_[1];



   my $lowerValue = hex($lower);
   my $upperValue = hex($upper);


   $lowerValue4 = $lowerValue%8;
   $upperValue4 = $upperValue%8;

   $lowerValue = int($lowerValue/8);
   $upperValue = int($upperValue/8);

   $lowerValue3 = $lowerValue%8;
   $upperValue3 = $upperValue%8;

   $lowerValue = int($lowerValue/8);
   $upperValue = int($upperValue/8);

   $lowerValue2 = $lowerValue%8;
   $upperValue2 = $upperValue%8;

   $lowerValue = int($lowerValue/8);
   $upperValue = int($upperValue/8);

   $lowerValue1 = $lowerValue%8;
   $upperValue1 = $upperValue%8;



   if($lowerValue1>$upperValue1)
   {
       my $swap = $lowerValue1;
       $lowerValue1=$upperValue1;
       $upperValue1=$swap;
   }

   if($lowerValue2>$upperValue2)
   {
       my $swap = $lowerValue2;
       $lowerValue2=$upperValue2;
       $upperValue2=$swap;
   }

   if($lowerValue3>$upperValue3)
   {
       my $swap = $lowerValue3;
       $lowerValue3=$upperValue3;
       $upperValue3=$swap;
   }

   if($lowerValue4>$upperValue4)
   {
       my $swap = $lowerValue4;
       $lowerValue4=$upperValue4;
       $upperValue4=$swap;
   }

   my $range1 = $upperValue1 - $lowerValue1;
   my $range2 = $upperValue2 - $lowerValue2;
   my $range3 = $upperValue3 - $lowerValue3;
   my $range4 = $upperValue4 - $lowerValue4;

   my $randomValue1 = int(rand($range1+1));
   my $randomValue2 = int(rand($range2+1));
   my $randomValue3 = int(rand($range3+1));
   my $randomValue4 = int(rand($range4+1));

   my $finalValue1 = $randomValue1 + $lowerValue1;
   my $finalValue2 = $randomValue2 + $lowerValue2;
   my $finalValue3 = $randomValue3 + $lowerValue3;
   my $finalValue4 = $randomValue4 + $lowerValue4;


   $finalValue1 = $finalValue1*8*8*8;
   $finalValue2 = $finalValue2*8*8;
   $finalValue3 = $finalValue3*8;

   my $finalValue = $finalValue1+$finalValue2+$finalValue3+$finalValue4;


   $finalValue = sprintf("%x", $finalValue);

   if(length($finalValue)<3)
   {
       $finalValue = "0$finalValue";
   }
   if(length($finalValue)<3)
   {
       $finalValue = "0$finalValue";
   }
   if(length($finalValue)<3)
   {
       $finalValue = "0$finalValue";
   }


   return $finalValue;
}
 
Top Bottom