callesson Posted April 23, 2010 Share Posted April 23, 2010 Hello guys! I got this php game were your character has a specify damage and damagemax. Ex: 5-7. Right now I have 3 cases. 2 cases where I hit random number between 5 and 7 and 1 case were I miss. So there is always 66% to hit. You character can also have stats named "Hitchance", what I would like to achieve is to make your hit chance equal to your Stats. Let us say we have 50% Hitchance, then when we attack we'r gonna hit with 50% chance. Link to comment https://forums.phpfreaks.com/topic/199493-procent-chance-php-sql/ Share on other sites More sharing options...
Mchl Posted April 23, 2010 Share Posted April 23, 2010 [code=php:0] mt_srand(); $toHit = 50; if(mt_rand(1,100) < $toHit) { //hit } else { //miss } Link to comment https://forums.phpfreaks.com/topic/199493-procent-chance-php-sql/#findComment-1047026 Share on other sites More sharing options...
callesson Posted April 23, 2010 Author Share Posted April 23, 2010 Ty m8, Could you explain a little bit too ? Link to comment https://forums.phpfreaks.com/topic/199493-procent-chance-php-sql/#findComment-1047035 Share on other sites More sharing options...
Mchl Posted April 23, 2010 Share Posted April 23, 2010 What's to explain? mt_srand initialises random number generator and mt_rand generates a number from 1 to 100. Then you compare a result with your stat, and if it's lower you pass, if not, you fail. Link to comment https://forums.phpfreaks.com/topic/199493-procent-chance-php-sql/#findComment-1047047 Share on other sites More sharing options...
callesson Posted April 23, 2010 Author Share Posted April 23, 2010 Yea, I got it now Ty Btw, Could you help with one more thing. So i dont need to make another topic ? If I have stats like Strenght or Stamina, how can I make a code so 1 Stamina equals 10 Health ? And I want to do it as a equip a new armor or level up. Or that 10 Weapon skill == 10 % Hitchance I would preciate it! Link to comment https://forums.phpfreaks.com/topic/199493-procent-chance-php-sql/#findComment-1047056 Share on other sites More sharing options...
Mchl Posted April 23, 2010 Share Posted April 23, 2010 $health = 10 * $stamina; $toHit = $weaponSkill; Link to comment https://forums.phpfreaks.com/topic/199493-procent-chance-php-sql/#findComment-1047085 Share on other sites More sharing options...
callesson Posted April 23, 2010 Author Share Posted April 23, 2010 So simple xD Ty mate Link to comment https://forums.phpfreaks.com/topic/199493-procent-chance-php-sql/#findComment-1047092 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.