Veramys Posted March 2, 2013 Share Posted March 2, 2013 ok so I coded in the ability for users to pick what race they want to be on signup, but I wanna make separate stats for each race and I'm not sure how to get it to do it, can anyone help? Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted March 2, 2013 Share Posted March 2, 2013 Well either you save the previous stats on files, or you use a table to save them. But is it all that useful? As your races are mainly or only random, which means, historical data are useless to know which "horse" will win next race. Real life races are over real horses which do have an history, different strength and medical issues. All that, unless simulated will not be the case in your game. Quote Link to comment Share on other sites More sharing options...
Veramys Posted March 4, 2013 Author Share Posted March 4, 2013 by race I mean users have their choice between Elf, Dwarf or being Human, and I want to assign different starting stats for the different races Quote Link to comment Share on other sites More sharing options...
Uridium Posted March 4, 2013 Share Posted March 4, 2013 easiest way would be to add a new Table called race_stats and have it grab the race, userid, and which stats so when needed stats can be updated via an attack loss/win or when a cron runs Quote Link to comment Share on other sites More sharing options...
Veramys Posted March 6, 2013 Author Share Posted March 6, 2013 ok you aren't understanding me, in the register fiile, it adds in the stats of a new player to the user stats table. I created 3 different races users could choose from at register. Human, Elf, and Dwarf. Now instead of just making every race start out with all stats at 10, I want to make some stats different according to race Quote Link to comment Share on other sites More sharing options...
Veramys Posted March 6, 2013 Author Share Posted March 6, 2013 hmm with a little tweaking maybe.. thanks Guest Quote Link to comment Share on other sites More sharing options...
sniko Posted March 6, 2013 Share Posted March 6, 2013 An extension of what Guest wrote; <?php #colours $races = array(1 => 'Human', 2 => 'Elf', 3 => 'Dwarf'); if( array_key_exists('race', $_POST) ) { $race = ( in_array($_POST['race'], $races) ) ? $races[$_POST['race']] : 1; /* Default race is Human */' switch($race) { case 'ELF' : $agility += 10; /* Plus 10 agility */ break; case ' 'HUMAN' : $strength += 20; /* Plus 20 strength */ break; default : $guard += 5; /* Plus 5 guard */ break; } } /* now for the form */ echo '<select name="race">'; foreach($races as $race_id => $race_label) { echo '<option value="'. $race_id .'">'. $race_label .'</option>'; } echo '</select>'; Quote Link to comment Share on other sites More sharing options...
sniko Posted March 6, 2013 Share Posted March 6, 2013 Or you could remove the need to add switch cases each time, and just have data held in the array which is accessed through the page <?php $races = array ( 1 => array('name' => 'Human', 'strength' => 10, 'agility' => 10, 'guard' => 10), 2 => array('name' => 'Elf', 'strength' => 20, 'agility' => 20, 'guard' => 20), 3 => array('name' => 'Dwarf', 'strength' => 30, 'agility' => 30, 'guard' => 30) ); if(($race = $races[ $_POST['race'] ]) > 0) { echo "You chose the race, {$race['name']} to be your character class, so you start with ". "{$race['strength']} strength, {$race['agility']} agility and {$race['guard']} guard."; } echo '<form action="" method="post"> <select name="race">'; foreach($races as $id => $data) { echo '<option value="'. $id .'">' . $data['name'] . '</option>'; } echo '</select> <br /> <input type="submit" name="submit" value="Go!">'; Note: this works as is, so you can test without adding to another code. Very elegant. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.