Jump to content
MakeWebGames

Recommended Posts

Posted

I have been trying to rework my gym so player under 50mill in 1 stat will get 1 set gain and any stat over 50mill will get another gain. I would just like to know if its all correct.

 

 

<?php
$macropage="gym.php";
include_once('globals.php');


// SHOULD MAKE 150 AND 100 ENERGYBAR DECLARE 10 OR 15 TRAINS //
// ILLUSIONS //



if($ir['hospital']) { die("This page cannot be accessed right now."); }
$statnames=array(
'Strength' => 'strength',
'Agility' => 'agility',
'Guard' => 'guard');
if (!isset($_POST['amnt']))
{
   $_POST['amnt'] = 0;
}
$_POST['amnt'] = abs((int) $_POST['amnt']);
if ($ir['jail'] <= 0)
{
   echo "<h3>Gym</h3><hr />";
}
else
{
   echo "<h3>Jail Gym</h3><hr />";
}
if (isset($_POST['stat']) && $_POST['amnt'])
{
   if (!isset($statnames[$_POST['stat']]))
   {
       die("This stat cannot be trained.");
   }
   $stat = $statnames[$_POST['stat']];
   if ($_POST['amnt'] > $ir['energy'])
   {
       print("You do not have enough energy to train that much.<hr />");
   }
   else
   {
       $gain = 0;
       for ($i = 0; $i < $_POST['amnt']; $i++)
       {

         $gain +=
                   $gain += mt_rand(1, 50) / rand(800, 1000) * rand(800, 1000) * (($will + 20) / 150);
                           $ir['will']-=rand(1,3);


           }


if( $ir[$stat] < 50000000 )
{
$gain+=(0.0020*$ir[$stat])+(0.0030*$ir['will']);
$ir['will']-=rand(1,3);
}
if($ir['will'] < 0)
{
$ir['will']=0;
}

       if ($ir['jail'] > 0)
       {
           $gain /= 2;
       }


   $energyloss=$_POST['amnt']*10;

     $db->query(
               "UPDATE `userstats`
                       SET `{$stat}` = `{$stat}` + $gain
                       WHERE `userid` = $userid");
   $db->query("UPDATE `users` SET `will` = {$ir['will']}, energy = energy - $energyloss WHERE `userid` = $userid");
   $inc=$ir[$stat]+$gain;
   $inc2=abs((int) ($ir['energy']/10)-$_POST['amnt']);
   if($stat=="strength")
   {
     print "<center>You begin doing some push-ups.<br />
    <font color=red>You have gained <b>$gain</b> Power by doing <b>{$_POST['amnt']}</b> push ups.</font><br />
    You now have <b>$inc</b> Power  and <b>$inc2</b> push ups left you can do.</center>";
   }
   elseif($stat=="agility")
   {
     print "<center>You begin running .<br />
    <font color=purple>You have gained <b>$gain</b> Agility by doing <b>{$_POST['amnt']}</b> minutes of running.</font><br />
    You now have <b>$inc</b> Agility and <b>$inc2</b> minutes left.</center>";
   }
   elseif($stat=="guard")
   {
     print "<center>You jump into a near by river and begin swimming.<br />
    <font color=green>You have gained <b>$gain</b> Resistance by doing <b>{$_POST['amnt']}</b> minutes of swimming.</font><br />
    You now have <b>{$inc}</b> Resistance and <b>{$inc2}</b> minutes left.</center>";
   }

   print "<hr />";
   $ir['energy']-=($_POST['amnt']*10);
   $ir[$stat]+=$gain;
 }
}
$ir['strank']=get_rank($ir['strength'],'strength');
$ir['agirank']=get_rank($ir['agility'],'agility');
$ir['guarank']=get_rank($ir['guard'],'guard');
$ir['labrank']=get_rank($ir['labour'],'labour');

$numtimes=abs((int)($ir['energy']/10));
if($ir['energy']< 10)
{
print "<center><h3>You need at least 10 force to Exercise!</center></h3><hr />";
}
else
{
print "<center>Choose the stat you want to train and the times you want to train it.<br />
You can train up to {$numtimes} times.<hr />
<form action='gym.php' method='post'>
Stat: <select type='dropdown' name='stat'></center>";

print "<center>
<option style='color:red;' value='Strength'>Power (Have {$ir['strength']}, Ranked {$ir['strank']})
<option style='color:blue;' value='Agility'>Agility (Have {$ir['agility']}, Ranked {$ir['agirank']})
<option style='color:green;' value='Guard'>Resistance (Have {$ir['guard']}, Ranked {$ir['guarank']})
</select><br />
Times to train: <input type='text' name='amnt' value='{$numtimes}' /><br />
<input type='submit' value='Train' /></form></center>";
}
$h->endpage();
?>
Posted

Happy birthday Peter.

I see myself line 46 needs not be there so i have removed it from my file on game.

why 50mill doesn't really matter, but what matters is does the code do what im asking it to do.

Posted

Code in question;

// This will execute anyway
// Resulting in the amount gained to equal $gain
$gain = 0;
       for ($i = 0; $i < $_POST['amnt']; $i++)
       {

          $gain += mt_rand(1, 50) / rand(800, 1000) * rand(800, 1000) * (($will + 20) / 150);
          $ir['will']-=rand(1,3);        
           }

// This will execute if their stat
// is below 50,000,000
//Therefore, overwriting $gain      
if( $ir[$stat] < 50000000 )
{
$gain+=(0.0020*$ir[$stat])+(0.0030*$ir['will']);
$ir['will']-=rand(1,3);
}

 

(See comments in code above) ;)

Posted (edited)

Was just looking over your code and it does seem a little incorrect.

 

<?php
$macropage="gym.php";
include_once('globals.php');


// SHOULD MAKE 150 AND 100 ENERGYBAR DECLARE 10 OR 15 TRAINS //
// ILLUSIONS //



if($ir['hospital']) { die("This page cannot be accessed right now."); }
$statnames=array(
'Strength' => 'strength',
'Agility' => 'agility',
'Guard' => 'guard');
if (!isset($_POST['amnt']))
{
   $_POST['amnt'] = 0;
}
$_POST['amnt'] = abs((int) $_POST['amnt']);
if ($ir['jail'] <= 0)
{
   echo "<h3>Gym</h3><hr />";
}
else
{
   echo "<h3>Jail Gym</h3><hr />";
}
if (isset($_POST['stat']) && $_POST['amnt'])
{
   if (!isset($statnames[$_POST['stat']]))
   {
       die("This stat cannot be trained.");
   }
   $stat = $statnames[$_POST['stat']];
   if ($_POST['amnt'] > $ir['energy'])
   {
       print("You do not have enough energy to train that much.<hr />");
   }
   else
   {
   // STAT GAIN -- START
       $gain = 0;
       if( $ir[$stat] > 50000000 )
       {
           // IF STAT IS MORE THAN 50M
           for ($i = 0; $i < $_POST['amnt']; $i++)
           {
             $gain+=(0.0020*$ir[$stat])+(0.0030*$ir['will']);
           }                      
       } else {   
           // IF STAT IS LESS THAN 50M
           for ($i = 0; $i < $_POST['amnt']; $i++)
           {
             $gain += mt_rand(1, 50) / rand(800, 1000) * rand(800, 1000) * (($will + 20) / 150);
           }
       }      
     $ir['will']-=rand(1,3);
   // STAT GAIN -- END  
if($ir['will'] < 0)
{
$ir['will']=0;
}

       if ($ir['jail'] > 0)
       {
           $gain /= 2;
       }


   $energyloss=$_POST['amnt']*10;

     $db->query(
               "UPDATE `userstats`
                       SET `{$stat}` = `{$stat}` + $gain
                       WHERE `userid` = $userid");
   $db->query("UPDATE `users` SET `will` = {$ir['will']}, energy = energy - $energyloss WHERE `userid` = $userid");
   $inc=$ir[$stat]+$gain;
   $inc2=abs((int) ($ir['energy']/10)-$_POST['amnt']);
   if($stat=="strength")
   {
     print "<center>You begin doing some push-ups.
    <font color=red>You have gained <b>$gain</b> Power by doing <b>{$_POST['amnt']}</b> push ups.</font>
    You now have <b>$inc</b> Power  and <b>$inc2</b> push ups left you can do.</center>";
   }
   elseif($stat=="agility")
   {
     print "<center>You begin running .
    <font color=purple>You have gained <b>$gain</b> Agility by doing <b>{$_POST['amnt']}</b> minutes of running.</font>
    You now have <b>$inc</b> Agility and <b>$inc2</b> minutes left.</center>";
   }
   elseif($stat=="guard")
   {
     print "<center>You jump into a near by river and begin swimming.
    <font color=green>You have gained <b>$gain</b> Resistance by doing <b>{$_POST['amnt']}</b> minutes of swimming.</font>
    You now have <b>{$inc}</b> Resistance and <b>{$inc2}</b> minutes left.</center>";
   }

   print "<hr />";
   $ir['energy']-=($_POST['amnt']*10);
   $ir[$stat]+=$gain;
 }
}
$ir['strank']=get_rank($ir['strength'],'strength');
$ir['agirank']=get_rank($ir['agility'],'agility');
$ir['guarank']=get_rank($ir['guard'],'guard');
$ir['labrank']=get_rank($ir['labour'],'labour');

$numtimes=abs((int)($ir['energy']/10));
if($ir['energy']< 10)
{
print "<center><h3>You need at least 10 force to Exercise!</center></h3><hr />";
}
else
{
print "<center>Choose the stat you want to train and the times you want to train it.
You can train up to {$numtimes} times.<hr />
<form action='gym.php' method='post'>
Stat: <select type='dropdown' name='stat'></center>";

print "<center>
<option style='color:red;' value='Strength'>Power (Have {$ir['strength']}, Ranked {$ir['strank']})
<option style='color:blue;' value='Agility'>Agility (Have {$ir['agility']}, Ranked {$ir['agirank']})
<option style='color:green;' value='Guard'>Resistance (Have {$ir['guard']}, Ranked {$ir['guarank']})
</select>
Times to train: <input type='text' name='amnt' value='{$numtimes}' />
<input type='submit' value='Train' /></form></center>";
}
$h->endpage();
?>

 

The changes I made start on line 42 and end on 59. Also I did not test this out.

Edited by Curt

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...