Cronwerks MCCode/MCCodes Forums

Please login or register.

Login with username, password and session length

News:

Have you purchased a mod and are struggling to install it? Cronwerks now installs mods for only $3/$2.50 here.


AuthorTopic: Whole number instead of decimal when training?  (Read 211 times)

roxx

  • Basic Member
  • *
  • Reputation Power: 13
  • roxx has no influence.
  • Offline Offline
  • Posts: 4
    • View Profile
Whole number instead of decimal when training?
« on: February 13, 2010, 04:51:54 AM »
Hope i'm posting this in the correct place.But i was wondering if someone could help me with how i would go about changing this:
               
                  You begin lifting some weights.
You have gained 1.70860606061 strength by doing 1 sets of weights.
You now have 41.7086060606 strength and 12 energy left.

to something like this:

                 You begin lifting some weights.
You have gained 2 strength by doing 1 sets of weights.
You now have 42 strength and 12 energy left.

It would be nice to have a whole rounded number,instead of the decimal.Did some searching on here and mwg,but cant really find a specific answer to my question.Thanx for any help and/or suggestions.
Logged

Danny696

  • Excellent Member
  • ***
  • Reputation Power: 276
  • Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.
  • Offline Offline
  • Posts: 457
    • View Profile
Re: Whole number instead of decimal when training?
« Reply #1 on: February 13, 2010, 05:25:32 AM »
Post your gym up
Logged
My Game: GraveYard; Madness || Projects; N/A -  Available for work. Please IM/PM me.

roxx

  • Basic Member
  • *
  • Reputation Power: 13
  • roxx has no influence.
  • Offline Offline
  • Posts: 4
    • View Profile
Re: Whole number instead of decimal when training?
« Reply #2 on: February 13, 2010, 11:43:18 AM »
Thanx danny,here's what i've got: (would have posted sooner,had to get some sleep though)

Code: [Select]
<?php
$macropage
="gym.php";
include 
"globals.php";
if(
$ir['hospital']) { die("This page cannot be accessed while in hospital."); }
$statnames=array(
'Strength' => 'strength',
'Agility' => 'agility',
'Guard' => 'guard',
'Labour' => 'labour');
$_POST['amnt']=abs((int) $_POST['amnt']);
if(!
$ir['jail'])
{
print 
"<h3>Gym</h3><hr />";
}
else
{
  print 
"<h3>Jail Gym</h3><hr />";
}
if(
$_POST['stat'] && $_POST['amnt'])
{
  
$stat=$statnames[$_POST['stat']];
  if(!
$stat)
  {
    die(
"This stat cannot be trained.");
  }
  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+=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 begin lifting some weights.<br />
      You have gained {$gain} strength by doing {$_POST['amnt']} sets of weights.<br />
      You now have {$inc} strength and {$inc2} energy left."
;
    }
    elseif(
$stat=="agility")
    {
      print 
"You begin running on a treadmill.<br />
      You have gained {$gain} agility by doing {$_POST['amnt']} minutes of running.<br />
      You now have {$inc} agility and {$inc2} energy left."
;
    }
    elseif(
$stat=="guard")
    {
      print 
"You jump into the pool and begin swimming.<br />
      You have gained {$gain} guard by doing {$_POST['amnt']} minutes of swimming.<br />
      You now have {$inc} guard and {$inc2} energy left."
;
    }
    elseif(
$stat=="labour")
    {
      print 
"You walk over to some boxes filled with gym equipment and start moving them.<br />
      You have gained {$gain} labour by moving {$_POST['amnt']} boxes.<br />
      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 
"Choose the stat you want to train and the times you want to train it.<br />
You can train up to {$ir['energy']} times.<hr />
<form action='gym.php' method='post'>
Stat: <select type='dropdown' name='stat'>
<option style='color:red;' value='Strength'>Strength (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'>Guard (Have {$ir['guard']}, Ranked {$ir['guarank']})
<option style='color:brown;' value='Labour'>Labour (Have {$ir['labour']}, Ranked {$ir['labrank']})
</select><br />
Times to train: <input type='text' name='amnt' value='{$ir['energy']}' /><br />
<input type='submit' value='Train' /></form>"
;
$h->endpage();
?>
Logged

Danny696

  • Excellent Member
  • ***
  • Reputation Power: 276
  • Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.
  • Offline Offline
  • Posts: 457
    • View Profile
Re: Whole number instead of decimal when training?
« Reply #3 on: February 13, 2010, 01:34:41 PM »
      $gain+=(int)rand(1,3)/rand(800,1000)*rand(800,1000)*(($ir['will']+20)/150);
Logged
My Game: GraveYard; Madness || Projects; N/A -  Available for work. Please IM/PM me.

roxx

  • Basic Member
  • *
  • Reputation Power: 13
  • roxx has no influence.
  • Offline Offline
  • Posts: 4
    • View Profile
Re: Whole number instead of decimal when training?
« Reply #4 on: February 13, 2010, 11:50:02 PM »
Thanx man,i appreciate the help,but it did'nt work for me,everything's still lookin the same.

You jump into the pool and begin swimming.
You have gained 7.40657218867 guard by doing 5 minutes of swimming.
You now have 23.4065721887 guard and 5 energy left.
Logged

catles

  • Basic Member
  • *
  • Reputation Power: 20
  • catles has no influence.
  • Offline Offline
  • Posts: 25
    • View Profile
    • Email
Re: Whole number instead of decimal when training?
« Reply #5 on: February 14, 2010, 12:36:50 AM »
$gain+=floor(rand(1,3)/rand(800,1000)*rand(800,1000)*(($ir['will']+20)/150));

floor rounds it down so the user will end up with less in the long run but should fix it
Logged

roxx

  • Basic Member
  • *
  • Reputation Power: 13
  • roxx has no influence.
  • Offline Offline
  • Posts: 4
    • View Profile
Re: Whole number instead of decimal when training?
« Reply #6 on: February 14, 2010, 02:43:09 AM »
Fantastic  ;D ,thank you guys so much for your help.Not the most advanced user at the moment,buy i'm taking my time and trying to learn.With that said,if theres ever anything i can do to repay you for your help,just send me a message.
Logged

Cronus

  • Administrator
  • Excellent Member
  • *****
  • Reputation Power: 1870
  • Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!
  • Offline Offline
  • Posts: 479
    • View Profile
    • WWW
Re: Whole number instead of decimal when training?
« Reply #7 on: February 14, 2010, 07:25:08 AM »
No problem roxx, that is what we are here for =)
Logged