Jump to content
MakeWebGames

Gym Help Please


Canjucks
 Share

Recommended Posts

Hi, this has been bugging me that I cannot find a solution without firstly understanding 100% (I am about 65% of the way there but assistance on this is needed to help me the rest of the way :)) I need to better understand what the formula does when calculating Will lost training at the gym.

 

 $gain=0;
   for($i=0; $i<$_POST['amnt']; $i++)
   {
     $gain+=rand(1,3)/rand(800,1200)*rand(800,1200)*(($ir['will']+20)/350);
     $ir['will']-=rand(1,3);
     if($ir['will'] < 0) { $ir['will']=0; }

$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");
$db->query("UPDATE `users` SET `exp` = {$ir['exp']} + {$_POST['amnt']} * {$ir['maxwill']} / 350 WHERE `userid` = $userid");

 

What is happening is that, if you have max will at 8000 you will only lose say 10% of that when the maximum Will (available in the game) is 15000 and you lose 2% which is good, probably would rather that at 4%. I have tested this on a range of levels and it works on the higher levels and not the lower levels (up to level 20 no way as well it should but on higher than 30 its almost perfect as in the Will lost will be about what my expectation would be)

Questions: Am I better to make a string so that if your Will = 100 then Will=Will*95% else Will = 200 then Will=Will*92% etc? Then I will not so much have this issue? or could someone please take the time to explain the formula so that this happens without the big ass if statement? or is it possible?

I have been reading through contagiously the posts to do with Gym and haven't found an answer that will help me the rest of the way. I have an idea though. It is funny because I have figured out majority of the other bugs on my own but this one is just out of reach. Please help.

Link to comment
Share on other sites

Re: Gym Help Please

How do I get this if statement to continue to reduce the will by 0.49? I have tried doing an else and all it does is reduce the 49 to 24 and then stops reducing it further to hit 0 which I would want it to do.

if($ir['maxwill'] >= 1500) { $ir['will']=$ir['maxwill']*0.49; } -> gets the desired result of reducing the Will

I If Maxwill >= 1500 Then Will=Maxwill*0.49 While Maxwill >= 1500 and Will >=0 Do Will=Will*0.49 ->something like that

Can someone give me some insight? another angel perhaps, please :)

Link to comment
Share on other sites

Re: Gym Help Please

 

I take it no one knows the answer(s)! too elementry for you all? lol

I'm not sure I understand your question.

I get that you want to understand the equation better. But what are you trying to accomplish here?

Are people gaining more stats than you want them to gain? Are they not gaining enough?

Link to comment
Share on other sites

Re: Gym Help Please

I want to control the Will lost. This is why I am making it specific to the Maxwill of a player. So instead of losing between 1 and 3 percent, I want them to lose a value according to the Maxwill, which will depend on the house they have purchased which of course will range in my games instance between 100 and 15000. I want to make it more attractive to have the most expensive house by being able to gain more but lose less Will.

You have cleared up one point for me about what the $ir does and this will help me I believe. My past programming days all those years ago is telling me that I should be able to use that information. I actually missed it when I was looking at it for so long trying to work things out.

Link to comment
Share on other sites

Re: Gym Help Please

Put this in your global functions file:

// submit a numeric value, and find a percent of where in the range that number is.
function range_to_percent($low, $high, $value) {
$range = $high - $low;
$target = to_percent($value - $low, $range);
return $target;
}

 

Before the for loop in the gym, put this:

$will_mod = (100 - range_to_percent(100, 15000, $ir['maxwill']) * .5) * .01 ;

 

Now change this:

$ir['will']-=rand(1,3);

 

To this:

$ir['will']-=rand(1,3) * $will_mod;

 

Does that help?

Link to comment
Share on other sites

Re: Gym Help Please

That looks real cool but I have added it. and does help except

I added the fnction to my global_func.php and i get a error

Fatal error: Call to undefined function to_percent() in /home/piratesn/public_html/global_func.php.

I did put in the right file?

Link to comment
Share on other sites

Re: Gym Help Please

 

That looks real cool but I have added it. and does help except

I added the fnction to my global_func.php and i get a error

Fatal error: Call to undefined function to_percent() in /home/piratesn/public_html/global_func.php.

I did put in the right file?

his function was range_to_percent...

Make sure you didnt type it wrong...Typo is alot of my errors lol...

look for functionrange to_percent

or

function range to_percent

I would say the last more is a good possiblilty...

Link to comment
Share on other sites

Re: Gym Help Please

 

// Convert number to % where there is a minimum and maximum number
function to_percent($min, $max) {
if (is_null($min)) {
	echo "<h3>Please contact the site administration. Error Code: Division by zero.</h3>";
	global $userid;
	if ($userid < 1) {
		unset($_SESSION['user_id']);
		session_write_close();
		exit;
	}
	return;
}
return $percent = $min * 100 / $max;
}

 

My bad. There's the function that the range_to_percent() function is dependant on.

 

How's that workin for ya?

Link to comment
Share on other sites

Guest Anonymous

Re: Gym Help Please

Sorry to point out the obvious .... But why check for is_null($min) and informing the user of an division by zero error when the formula used actually divides by $max?

Handling errors like this IMO should be done gracefully, in the background, with no need to inform the user by using the standard error handling tools. No need to kick the user out of the system either - it's not a low-level library function's place to perform that operation.

Link to comment
Share on other sites

Re: Gym Help Please

Thanks for you help floydian i appreciate it greatly but it made very little difference to what was happening in Will you lose.

This is the code I have been playing around with to get the reduced Will I want for each level of maxwill.

if($ir['maxwill'] >= 100) { $ir['will']=$ir['maxwill']*0.01; }
     if($ir['maxwill'] >= 125) { $ir['will']=$ir['maxwill']*0.03; }
     if($ir['maxwill'] >= 200) { $ir['will']=$ir['maxwill']*0.05; }
     if($ir['maxwill'] >= 300) { $ir['will']=$ir['maxwill']*0.09; }
     if($ir['maxwill'] >= 400) { $ir['will']=$ir['maxwill']*0.12; }
     if($ir['maxwill'] >= 500) { $ir['will']=$ir['maxwill']*0.16; }
     if($ir['maxwill'] >= 600) { $ir['will']=$ir['maxwill']*0.19; }
     if($ir['maxwill'] >= 700) { $ir['will']=$ir['maxwill']*0.23; }
     if($ir['maxwill'] >= 700) { $ir['will']=$ir['maxwill']*0.26; }
     if($ir['maxwill'] >= 800) { $ir['will']=$ir['maxwill']*0.29; }
     if($ir['maxwill'] >= 900) { $ir['will']=$ir['maxwill']*0.33; }
     if($ir['maxwill'] >= 1000) { $ir['will']=$ir['maxwill']*0.36; }
     if($ir['maxwill'] >= 1100) { $ir['will']=$ir['maxwill']*0.39; }
     if($ir['maxwill'] >= 1200) { $ir['will']=$ir['maxwill']*0.43; }
     if($ir['maxwill'] >= 1300) { $ir['will']=$ir['maxwill']*0.45; }
     if($ir['maxwill'] >= 1400) { $ir['will']=$ir['maxwill']*0.47; }
     if($ir['maxwill'] >= 1500) { $ir['will']=$ir['maxwill']*0.49; } 
     if($ir['maxwill'] >= 2000) { $ir['will']=$ir['maxwill']*0.53; }
     if($ir['maxwill'] >= 2500) { $ir['will']=$ir['maxwill']*0.57; }
     if($ir['maxwill'] >= 3000) { $ir['will']=$ir['maxwill']*0.61; }
     if($ir['maxwill'] >= 3500) { $ir['will']=$ir['maxwill']*0.65; }
     if($ir['maxwill'] >= 4000) { $ir['will']=$ir['maxwill']*0.68; }
     if($ir['maxwill'] >= 4500) { $ir['will']=$ir['maxwill']*0.71; }
     if($ir['maxwill'] >= 5000) { $ir['will']=$ir['maxwill']*0.74; }
     if($ir['maxwill'] >= 5500) { $ir['will']=$ir['maxwill']*0.77; }
     if($ir['maxwill'] >= 6000) { $ir['will']=$ir['maxwill']*0.80; }
     if($ir['maxwill'] >= 6500) { $ir['will']=$ir['maxwill']*0.83; }
     if($ir['maxwill'] >= 7000) { $ir['will']=$ir['maxwill']*0.85; }
     if($ir['maxwill'] >= 7500) { $ir['will']=$ir['maxwill']*0.87; }
     if($ir['maxwill'] >= 8000) { $ir['will']=$ir['maxwill']*0.89; }
     if($ir['maxwill'] >= 10000) { $ir['will']=$ir['maxwill']*0.94; }
     if($ir['maxwill'] >= 15000) { $ir['will']=$ir['maxwill']*0.97; }
}   

 

What it is doing is finding the correct the maxwill for the player but when you gym again it just stays at that value and doesn't continue to divide by x amount until Will=0. It might be the long way (and ugly) around things but it works initially so I like that part.

Link to comment
Share on other sites

Re: Gym Help Please

Would this be a better way around it by adding a percentage to multiply by column in the table that refers to table and then it would liook something like this rather than a messy if statement.

Find users 'Maxwill' from table

Find house 'Percentage' from table

While Will > 0

Will = maxwill*percentage

Until Will = 0;

I would hope that would have the same effect as what I am having now but also having the desired result of continuing until it hits 0.

Link to comment
Share on other sites

  • 2 weeks later...

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.

 Share

×
×
  • Create New...