Random Percentages

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.

Re: Random Percentages

Postby Callan S. » Thu Oct 09, 2014 9:41 pm

You need some sleep, E!
User avatar
Callan S.
 
Posts: 2043
Joined: Sun Jan 24, 2010 12:43 am
Location: http://philosophergamer.blogspot.com/
Has thanked: 4 times
Been thanked: 10 times
Blog: View Blog (2)

Re: Random Percentages

Postby Sim » Thu Oct 09, 2014 11:22 pm

Epiales wrote:Okay, I have this code written below now:
Code: Select all

<?php
$rand_num 
= rand(1,2);
$atk_player = ($rand_num /100) * $_POST['dropdown'] * $row['defense'];
$atk_player2 = round($atk_player);
echo "$atk_player2%";
echo "Your percentage ejaculation bonus was $rand_num%";

$updatehpoints = "UPDATE users SET hpoints=hpoints - $atk_player2 WHERE username = '$_SESSION[username]'";
$query = mysqli_query($db_conx, $updatehpoints);
}}
?>


It showed that it was 6% one time but it was really .6%

Another time it was 12% but it was really 1.2%

How can I fix that accordingly? So it says it's 1.2% health loss instead of the 12 % that is isn't?

Thank you so very, very much for helping here. :mrgreen:


Do you not know your own formula?
1 bullet, it would be 1% * defense
2 bullet, it would be 2% * defense
3 bullet, it would be 3% * defense



Code: Select all

<?php
$bullet_count 
rand(1,3);
$atk_player = ($bullet_count /100) * $_POST['dropdown'] * $row['defense'];
$atk_player2 round($atk_player);
echo 
"$atk_player2%<br>";
echo 
"Your percentage ejaculation bonus was $bullet_count%";

$updatehpoints "UPDATE users SET hpoints=hpoints - $atk_player2 WHERE username = '$_SESSION[username]'";
$query mysqli_query($db_conx$updatehpoints);
}}
?>


first echo is damage
second echo is the random % generated which is your bullet counter


But after reading the thread again, it said there selecting the # of bullets?
So you can remove the $bullet_count LINES. Not 1, 2 lines.

this code is assuming that $_POST[['dropdown'] is the # of bullets selected
Code: Select all
$atk_player = ($_POST['dropdown'] / 100) *  $row['defense'];
oRPG Creator - Make Your Own Browser Game
oRPG Creator on Facebook
Sim
 
Posts: 412
Joined: Sat Dec 26, 2009 12:37 pm
Location: Baltimore
Has thanked: 39 times
Been thanked: 13 times
Blog: View Blog (1)

Re: Random Percentages

Postby MikuzA » Fri Oct 10, 2014 12:47 am

Ok, perhaps some sleep for you Epiales ;)

I'm a bit confused on the formula here..

Code: Select all
$rand_num = rand(1,2);
$atk_player = ($rand_num /100) * $_POST['dropdown'] * $row['defense'];
$atk_player2 = round($atk_player);


So what I see is,

$rand_num can be 1 or 2.
$rand_num/100 can be 0.01 or 0.02
$_POST['dropdown'] not sure what this value is, weapon attack damage? So let's say its... 5
$row['defense'] is probably 5.

By doing this calculation,

0.01 * 5 * 5 = 0,25
And if you ROUND() that one, that will result as a 0.

So, I guess you need to define the usage of this percentage,
If you have a 'weapon' that has its damage-range from 10-15, you might want to rand(10,15) that.

Also, if you just wish to add a 'damage-modifier'-percentage, you should just do the normal calculation first and then do the rand() multiplier.
If you are trying to do a positive percentual buff on your defence for example, you might need to modify the formula to go over 100%, and in calculative that would be above 1.

So if you have rand(1,5)/100, just add a +1 for positive buff, and -1 for negative buff.

Defence * ((rand(1,5)/100)+1) = 50 * 1,05 (105%) = 52,5.

Hope this helps or not :D

This is just math here but giving you some examples on your approach, as the current one doesn't make sense to me when you are actually substracting the calc result from the hitpoints.




PS, 'Your percentage ejaculation' :D I couldn't help to burst in laughter there mate, thanks for that :D
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
User avatar
MikuzA
 
Posts: 395
Joined: Thu Aug 08, 2013 3:57 am
Location: Helsinki, Finland
Has thanked: 0 time
Been thanked: 21 times

Re: Random Percentages

Postby Sim » Fri Oct 10, 2014 1:23 am

MikuzA wrote:Ok, perhaps some sleep for you Epiales ;)
as the current one doesn't make sense to me when you are actually substracting the calc result from the hitpoints.

PS, 'Your percentage ejaculation' :D I couldn't help to burst in laughter there mate, thanks for that :D



That was my thoughts exactly. He did mentioned they was choosen the # of bullets. I am guessing that's what the $_POST['dropdown'] is. So I still believe this would be his best bet if that's the case.

Code: Select all
$atk_player = ( $_POST['dropdown'] /100) * $row['defense'];


A quote from one his earlier post.
So if they chose
1 bullet, it would be 1% * defense
2 bullet, it would be 2% * defense
3 bullet, it would be 3% * defense
ect....


So the dropdown / 100 makes it a % then * the defense.
I think we all overlooked this simplicity of this even though it would of helped a lot more if he told us what $_POST['dropdown'] was from the get go.


No problem about the launch.
oRPG Creator - Make Your Own Browser Game
oRPG Creator on Facebook
Sim
 
Posts: 412
Joined: Sat Dec 26, 2009 12:37 pm
Location: Baltimore
Has thanked: 39 times
Been thanked: 13 times
Blog: View Blog (1)

Previous

Return to Beginner Help and Support

Who is online

Users browsing this forum: No registered users and 1 guest

x