Jump to content
MakeWebGames

Fix my script? Can YOU Find an error in this code?


Joshua

Recommended Posts

if ($ir['race']==1 AND $stat=="guard")
{
$gain += mt_rand(1, 3) / mt_rand(500, 900) * mt_rand(500, 900) * (($will + 20) / 150)*50;
}
elseif ($ir['race']==2 AND $stat=="agility")
{
$gain += mt_rand(1, 3) / mt_rand(500, 900) * mt_rand(500, 900) * (($will + 20) / 150)*50;
}
elseif ($ir['race']==3 AND $stat=="$agility")
{
$gain += mt_rand(1, 3) / mt_rand(500, 900) * mt_rand(500, 900) * (($will + 20) / 150)*50;
}
else
{
$gain += mt_rand(1, 3) / mt_rand(500, 900) * mt_rand(500, 900) * (($will + 20) / 150);
}

$will  = max(0, $will - mt_rand(1, 3));
}

if ($row['jail'])
$gain *= 0.5;

 

Maybe THIS Helps. Full gym code...

 

<?php
$macropage="gym.php";
require "globals.php";
if($ir['hospital']) { die("<prb>This page cannot be accessed while in hospital.</prb>"); }
$statnames=array(
'Strength' => 'strength',
'Agility' => 'agility',
'Guard' => 'guard',
'Labour' => 'labour');
$_POST['amnt']=abs((int) $_POST['amnt']);
if(!$ir['jail'])
{
print "<h1>Gym</h1><hr width='90%' align='left' />";
}
else
{
 print "<h1>Jail Gym</h1><hr width='90%' align='left' />";
}
if($_POST['stat'] && $_POST['amnt'])
{
 $stat=$statnames[$_POST['stat']];
 if(!$stat)
 {
   die("<prb>This stat cannot be trained.</prb>");
 }
 if($_POST['amnt'] > $ir['energy'])
 {
   print("<prb>You do not have enough energy to train that much.</prb><hr width='90%' align='left' />");
 }
 else
 {
   $gain=0;
   for($i=0; $i<$_POST['amnt']; $i++)
   {
     $gain+=rand(1,3)/rand(800,1000)*rand(800,1000)*(($ir['will']+20)/150);
     $ir['will']-=rand(1,3);
     if($ir['will'] < 0) { $ir['will']=0; }
   }
   if($ir['jail']) { $gain/=2; }
   $db->query("UPDATE `userstats` SET `{$stat}` = `{$stat}` + $gain WHERE `userid` = $userid");
   $db->query("UPDATE `users` SET `will` = {$ir['will']}, energy = energy - {$_POST['amnt']} WHERE `userid` = $userid");






if ($ir['race']=='1' AND $stat=='guard')
{
$inc=$ir[$stat]+$gain*200000;
}
elseif ($ir['race']== '2' AND $stat=='agility')
{
$inc=$ir[$stat]+$gain*200000;
}
elseif ($ir['race']=='3' AND $stat=='strength')
{
$inc=$ir[$stat]+$gain*200000;
}
else
{
$inc=$ir[$stat]+$gain;
}






   $inc2=$ir['energy']-$_POST['amnt'];
   if($stat=="strength")
   {
     print "You start to lift some weights, You go heavier and heavier until You are out of energy.

     You have gained {$gain} strength by doing {$_POST['amnt']} sets of weights.

     You now have {$inc} strength and {$inc2} energy left.";
   }
   elseif($stat=="agility")
   {
     print "You Begin to run on the treadmill, You keep tapping the faster button till you fly off the damn thing!.

     You have gained {$gain} agility by doing {$_POST['amnt']} minutes of running.

     You now have {$inc} agility and {$inc2} energy left.";
   }
   elseif($stat=="guard")
   {
     print "You jump into the pool and begin swimming, you keep flapping your arms in the water like Michael Felps, you get a cramp and almost drown.

     You have gained {$gain} guard by doing {$_POST['amnt']} minutes of swimming.

     You now have {$inc} guard and {$inc2} energy left.";
   }
   elseif($stat=="labour")
   {
     print "You walk over to the front desk, and ask the manager If you can volunteer to help the gym out, He says unload the boxes In the back, You unload boxes until the gym closes

     You have gained {$gain} labour by unloading {$_POST['amnt']} boxes.

     You now have {$inc} labour and {$inc2} energy left.";
   }
   print "<hr />";
   $ir['energy']-=$_POST['amnt'];
   $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');
print "<table width='90%'><tr><td>

POST WHAT YOU WANT HERE, THIS IS THE WELCOME PAGE TO THE GYM.

You can train up to <prb>{$ir['energy']}</prb> times with your
current energy.</p></td></tr></table>
<hr width='90%' align='left' />

<table width='90%' class='table'>
<tr>
<form action='gym.php' method='post'>
<input type='hidden' name='stat' value='Strength'></input>
<th width='15%'><ph2>Strength:</ph2></th>
<td width='15%'>{$ir['strength']}</td>
<td width='10%'>(Rank {$ir['strank']})</td>
<td width='40%'>Times to train: <input type='text' name='amnt' value='{$ir['energy']}' length='5'></input></td>
<td width='20%'><input type='submit' value='Go!'></input></td>
</form>
</tr>
<tr>
<form action='gym.php' method='post'>
<input type='hidden' name='stat' value='Agility'></input>
<th width='15%'><ph2>Agility:</ph2></th>
<td width='15%'>{$ir['agility']}</td>
<td width='10%'>(Rank {$ir['agirank']})</td>
<td width='40%'>Times to train: <input type='text' name='amnt' value='{$ir['energy']}'></input></td>
<td width='20%'><input type='submit' value='Go!'></input></td>
</form>
</tr>
<tr>
<form action='gym.php' method='post'>
<input type='hidden' name='stat' value='Guard'></input>
<th width='15%'><ph2>Guard:</ph2></th>
<td width='15%'>{$ir['guard']}</td>
<td width='10%'>(Rank {$ir['guarrank']})</td>
<td width='40%'>Times to train: <input type='text' name='amnt' value='{$ir['energy']}'></input></td>
<td width='20%'><input type='submit' value='Go!'></input></td>
</form>
</tr>
<tr>
<form action='gym.php' method='post'>
<input type='hidden' name='stat' value='Labour'></input>
<th width='15%'><ph2>Labour:</ph2></th>
<td width='15%'>{$ir['labour']}</td>
<td width='10%'>(Rank {$ir['labrank']})</td>
<td width='40%'>Times to train: <input type='text' name='amnt' value='{$ir['energy']}'></input></td>
<td width='20%'><input type='submit' value='Go!'></input></td>
</form>
</tr>
</table>
<hr width='90%' align='left' />

";
$h->endpage();
?>

Ok, So can't for the life of me figure out why the Race isnt getting the Benefit when work-out. Everything is working just like it should. I even tried raising the multiplier to 50 as you can see so it would be an obvious differance.

Can you spot the error?

tnx

Link to comment
Share on other sites

try this one m8.

 

<?php 
$macropage="gym.php"; 
require "globals.php"; 
if($ir['hospital']) { die("<prb>This page cannot be accessed while in hospital.</prb>"); 
} 
$statnames=array( 
'Strength' => 'strength', 
'Agility' => 'agility', 
'Guard' => 'guard', 
'Labour' => 'labour'); 
$_POST['amnt']=abs((int) $_POST['amnt']); 
if(!$ir['jail']) 
{ 
print "<h1>Gym</font></h1><hr width='100%' align='left' />"; 
} 
else 
{ 
print "<h1>Jail Gym</font></h1><hr width='100%' align='left' />"; 
} 
if($_POST['stat'] && $_POST['amnt']) 
{ 
$stat=$statnames[$_POST['stat']]; 
if(!$stat) 
{ 
die("<prb>This stat cannot be trained.</prb>"); 
} 
if($_POST['amnt'] > $ir['energy']) 
{ 
print("<prb>You do not have enough energy to train that much.</font></prb><hr width='100%' align='left' />"); 
} 
else 
{ 

$gain=0; 
for($i=0; $i<$_POST['amnt']; $i++) 
{ 
$gain+=rand(1,3)/rand(800,1000)*rand(800,1000)*(($ir['will']+20)/150); 
$ir['will']-=rand(1,3); 
if($ir['will'] < 0) { $ir['will']=0; } 
} 
if($ir['jail']) { $gain/=2; } 
$db->query("UPDATE `userstats` SET `{$stat}` = `{$stat}` + $gain WHERE `userid` = $userid"); 
$db->query("UPDATE `users` SET `will` = {$ir['will']}, energy = energy - {$_POST['amnt']} WHERE `userid` = $userid"); 
$inc=$ir[$stat]+$gain; 
$inc2=$ir['energy']-$_POST['amnt']; 

if($stat=="strength") 
{ 
print "You start to lift some weights, You go heavier and heavier until You are out of energy.

You have gained {$gain} strength by doing {$_POST['amnt']} sets of weights.

You now have {$inc} strength and {$inc2} energy left.</font>"; 
} 
elseif($stat=="agility") 
{ 
print "You Begin to run on the treadmill, You keep tapping the faster button till you fly off the damn thing!.

You have gained {$gain} agility by doing {$_POST['amnt']} minutes of running.

You now have {$inc} agility and {$inc2} energy left."; 
} 
elseif($stat=="guard") 
{ 
print "You jump into the pool and begin swimming, you keep flapping your arms in the water like Michael Felps, you get a cramp and almost drown.

You have gained {$gain} guard by doing {$_POST['amnt']} minutes of swimming.

You now have {$inc} guard and {$inc2} energy left."; 
} 
elseif($stat=="labour") 
{ 
print "You walk over to the front desk, and ask the manager If you can volunteer to help the gym out, He says unload the boxes In the back, You unload boxes until the gym closes

You have gained {$gain} labour by unloading {$_POST['amnt']} boxes.

You now have {$inc} labour and {$inc2} energy left."; 

} 
print "<hr />"; 
$ir['energy']-=$_POST['amnt']; 
$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'); 
print "<table width='100%'><tr><td> 

You can train up to <prb>{$ir['energy']}</prb> times with your 
current energy.</td></tr></table> 
<hr width='100%' align='left' />

<table width='100%' class='table'> 
<tr> 
<form action='gym.php' method='post'> 
<input type='hidden' name='stat' value='Strength'></input> 
<th width='15%'><ph2>Strength:</ph2></th> 
<td width='15%'>{$ir['strength']}</td> 
<td width='10%'>(Rank {$ir['strank']})</td> 
<td width='40%'>Times to train: <input type='text' name='amnt' value='{$ir['energy']}' length='5'></input></td> 
<td width='20%'><input type='submit' value='Train!'></input></td> 
</form> 
</tr> 
<tr> 
<form action='gym.php' method='post'> 
<input type='hidden' name='stat' value='Agility'></input> 
<th width='15%'><ph2>Agility:</ph2></th> 
<td width='15%'>{$ir['agility']}</td> 
<td width='10%'>(Rank {$ir['agirank']})</td> 
<td width='40%'>Times to train: <input type='text' name='amnt' value='{$ir['energy']}'></input></td> 
<td width='20%'><input type='submit' value='Train!'></input></td> 
</form> 
</tr> 
<tr> 
<form action='gym.php' method='post'> 
<input type='hidden' name='stat' value='Guard'></input> 
<th width='15%'><ph2>Guard:</ph2></th> 
<td width='15%'>{$ir['guard']}</td> 
<td width='10%'>(Rank {$ir['guarank']})</td> 
<td width='40%'>Times to train: <input type='text' name='amnt' value='{$ir['energy']}'></input></td> 
<td width='20%'><input type='submit' value='Train!'></input></td> 
</form> 
</tr> 
<tr> 
<form action='gym.php' method='post'> 
<input type='hidden' name='stat' value='Labour'></input> 
<th width='15%'><ph2>Labour:</ph2></th> 
<td width='15%'>{$ir['labour']}</td> 
<td width='10%'>(Rank {$ir['labrank']})</td> 
<td width='40%'>Times to train: <input type='text' name='amnt' value='{$ir['energy']}'></input></td> 
<td width='20%'><input type='submit' value='Train!'></input></td> 
</form> 
</tr> 
</table>
<hr width='100%' align='left' />

"; 
$h->endpage(); 
?>
Link to comment
Share on other sites

I'm not 100% sure on anything at this point as I can't seem to get this to work, and if it IS working i dont even notice it..

Basically what this is, I have a Race mod, where users with a differant race, get differant stats when Working out. "ie" agility may go up faster than strength etc etc.

My problem is actually seeing the differance.

 

Should just be able to find

 

1

$inc=$ir[$stat]+$gain;  in gym.php

 

and turn that into

 

if ($ir['race']==1 AND $stat=="guard")
{
$inc=$ir[$stat]+$gain*3;
}
elseif ($ir['race']==2 AND $stat=="strength")
{
$inc=$ir[$stat]+$gain*3;
}
elseif ($ir['race']==3 AND $stat=="agility")
{
$inc=$ir[$stat]+$gain*1.1;
}
else
{
$inc=$ir[$stat]+$gain;
}
Link to comment
Share on other sites

try using this.

 

if ($ir['race']==1 AND $stat=="guard")
{
$gain = mt_rand(1, 3) / mt_rand(500, 900) * mt_rand(500, 900) * (($will + 20) / 150)*50;
}
elseif ($ir['race']==2 AND $stat=="agility")
{
$gain = mt_rand(1, 3) / mt_rand(500, 900) * mt_rand(500, 900) * (($will + 20) / 150)*50;
}
elseif ($ir['race']==3 AND $stat=="$agility")
{
$gain = mt_rand(1, 3) / mt_rand(500, 900) * mt_rand(500, 900) * (($will + 20) / 150)*50;
}
else
{
$gain = mt_rand(1, 3) / mt_rand(500, 900) * mt_rand(500, 900) * (($will + 20) / 150);
}

$will  = max(0, $will - mt_rand(1, 3));

if ($row['jail'])  { 
} 
Link to comment
Share on other sites

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