0

I want like a ranking system that works something like this.

User clicks on something there is a percentage chance that they will suceed. And if they do they get xp. but if they fail they only get like 1 xp. Anyone a mmporg Coder. Because I will Pay up to £100

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by diafol
1

You just need a randomizer.

//carry over $xp from your previous code

$win = 5;
$lose = 1;

$chance = 10; //meaning 10%
$result = mt_rand(1, 100);
$xp += ($result <= $chance) ? $win : $lose;

You could wrap this up into a function to make it easy to reuse.

e.g.

function doThing($xp, $item){
    extract($item);
    $result = mt_rand(1, 100);
    $xp += ($result <= $chance) ? $win : $lose;
    return $xp;
}


//ARRAY FORMAT : win, lose, chance
//list all your thingies
$arrow_strike = array(5,1,10);
$throat_punch = array(2,0,20);

//use
$xp = doThing($xp,$arrow_strike);

OK, this is a pretty poor example as the thingies would probably be stored in an array themselves. But it's just an example.

Votes + Comments
Thanks
0

Darn noticed a mistake:

In order to get extract to work, you need to set an associative array:

$arrow_strike = array('win'=>5,'lose'=>1,'chance'=>10);

So perhaps easier to use list:

$arrow_strike = array(5,1,10);

function doThing($xp, $item){
    list($win,$lose,$chance) = $item;
    $result = mt_rand(1, 100);
    $xp += ($result <= $chance) ? $win : $lose;
    return $xp;
}

echo doThing($xp,$arrow_strike);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.