Author Topic: need help  (Read 1363 times)

Offline Aliss

  • Level 9
  • *
  • Posts: 54
  • Reputation: +1/-1
    • View Profile
need help
« on: October 18, 2007, 12:57:07 PM »
I wanna make one function but i don't have to make.

I need perctange calculating 

EXAMPLE

17%  against 100%

succes or faild

100% against 100%

100% succes

I hope someone understend what i mean.

And sry for my terrable english

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: need help
« Reply #1 on: October 18, 2007, 01:10:44 PM »
Code: [Select]
<?php
$percentage 
17//17% out of 100

$rand rand($percentage100);
if (
$rand <= $percentage)
{
echo 
"Success!";
}
else
{
echo 
"Failure!";
}
?>

As a function:

Code: [Select]
<?php
function percent($percentage)
{
$rand rand($percentage100);
if (
$rand <= $percentage)
{
return 
"Success!";
}
else
{
return 
"Failure!";
}
}
?>

Offline Aliss

  • Level 9
  • *
  • Posts: 54
  • Reputation: +1/-1
    • View Profile
Re: need help
« Reply #2 on: October 18, 2007, 01:18:37 PM »
Thx for litle help now i will try to make my script  -|-

Offline Equinox

  • Game Owner
  • Level 10
  • *
  • Posts: 58
  • Reputation: +2/-0
    • View Profile
    • Equinox Gaming Solutions
Re: need help
« Reply #3 on: October 18, 2007, 01:45:38 PM »
Dont want to sound too daft.. but what script are you trying to write :P
Equinox Gaming Solutions Manager
http://www.equinoxgaming.co.uk

Offline Aliss

  • Level 9
  • *
  • Posts: 54
  • Reputation: +1/-1
    • View Profile
Re: need help
« Reply #4 on: October 18, 2007, 02:22:18 PM »
Shield chance to block enemy attack.  :D

Offline Equinox

  • Game Owner
  • Level 10
  • *
  • Posts: 58
  • Reputation: +2/-0
    • View Profile
    • Equinox Gaming Solutions
Re: need help
« Reply #5 on: October 19, 2007, 11:48:23 AM »
Interesting... Full out battle script?
Equinox Gaming Solutions Manager
http://www.equinoxgaming.co.uk

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: need help
« Reply #6 on: October 20, 2007, 03:23:23 AM »
Code: [Select]
$s='Battle begins: ';
if(rand(1,100)<=$hitchance) $s.='you hit the enemy, '; else $s.='you miss the enemy, ';
$s.='for '.rand(1,6).' damage, ';
if(rand(1,100)<=$shieldchance) $s.='the blow is blocked by shield, ';
if(rand(1,100)<=$counterchance) $s.='the enemy countered, ';
if(rand(1,100)<=$divinehelpchance) $s.='a guardian angel came to resque, ';
if($magicuser && rand(1,100)<=$magicaurachance) $s.='a magic aura reflected the blow, ';
if($poisonblade && rand(1,100)<=$poisonchance) $s.='the enemy is poisoned, ';
if($flameblade && rand(1,100)<=$flamechance) $s.='the enemy is enflunged by fire, ';
if($iceblade && rand(1,100)<=$icechance) $s.='the enemy is frozen, ';
if($vorpalblade && rand(1,100)<=$voidchance) $s.='the enemy is thrown into the void, ';
echo $s;
And so on, so on :)

Offline Equinox

  • Game Owner
  • Level 10
  • *
  • Posts: 58
  • Reputation: +2/-0
    • View Profile
    • Equinox Gaming Solutions
Re: need help
« Reply #7 on: October 20, 2007, 04:55:52 AM »
Looks good, is the game viewable at the moment at all? Doesnt have to be pretty yet ;)
Equinox Gaming Solutions Manager
http://www.equinoxgaming.co.uk

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: need help
« Reply #8 on: October 20, 2007, 05:15:49 AM »
Oh yeah, I just noticed, the code I wrote was wrong :P
It's supposed to be rand(1,100) like in Chris's post, not rand($percentage, 100)

Offline Aliss

  • Level 9
  • *
  • Posts: 54
  • Reputation: +1/-1
    • View Profile
Re: need help
« Reply #9 on: October 20, 2007, 05:58:20 AM »
Thx for examples  B)

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal