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

Member Avatar for diafol

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.

commented: Thanks +0
Member Avatar for diafol

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.