modded reguser help

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
ZeroComp
Posts: 648
Joined: Thu Oct 29, 2009 8:48 pm

modded reguser help

Post by ZeroComp »

ok so I have modded my reguser.php to fit faction wars' needs and I need a little bit of help on part of it. I am wondering how to piece out a couple lines of code that will put the player in a random faction, I plan on building on that piece of code later on to put players in a faction with the least amount of players to make it fair
Coding-PHP, Javascript, C++, HTML, mySQL
Modeling/Art-Blender, GIMP
Games-Unity, Game Maker 8
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: modded reguser help

Post by Chris »

Make an array of the different factions or pull it from your database or however you do it..
Then make php generate a random number between the length of the array and 0.

Code: Select all

$factions = array( 'gays', 'fags', 'homos', 'queers', 'emos' );

$number = rand(0, (count($factions)-1)); // -1 because the first key is of course 0  and not 1

echo "<select name=\"factions\">\n";

foreach( $factions as $key => $value )
{
    echo "<option". ( $number == $key ? " selected=\"selected\"" : '' )  .">". $value ."</option>\n";
}
echo "</select>";
 
Fighting for peace is declaring war on war. If you want peace be peaceful.
Post Reply

Return to “Advanced Help and Support”