Jump to content
MakeWebGames

Recommended Posts

Posted

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?

Posted

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.

Posted

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

Posted

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

Posted

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>';
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...