Less Than More Than

Discussion in 'PHP' started by alex heap, Jan 27, 2013.

  1. #1
    im trying to code a game and in the game there are characters and each character will have a level, for this example lets say i am level 50, and i went to battle someone, how could i code it so i could only battle someone whos level is no less than 45. so i cant battle anyone with a 5 level difference lower than mine.
     
    alex heap, Jan 27, 2013 IP
  2. Tom-Brown

    Tom-Brown Well-Known Member

    Messages:
    105
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    110
    #2
    if(PLAYERLEVEL => 45){ or IF(PLAYERLEVEL > 44)

    Where PLAYERLEVEL is the level of the person your wanting to fight. Loop through the players until it finds one, alternatively group all levels 45-50 into 1 group and then randomly select one.

    If you need any assistance just message me.
     
    Tom-Brown, Jan 27, 2013 IP
  3. ArMouR

    ArMouR Well-Known Member

    Messages:
    161
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    1
    #3
    <?php
    $current_level = 50;
    $enemy_level = 45;
    if ($enemy_level >= ($current_level - 5)) {
    //we can battle
    }
    else {
    //nope, no battle here, unfair fight ;)
    }
    ?>

    of course, you'd want to put this in a for loop if you're searching for a player, you'd have to for loop through users until you find one unless you have a table for groups and when a user reaches a group leve, you put them in a specific table. This will reduce search time within a specific group so your for loop will have to go through less players to find one available
     
    ArMouR, Jan 27, 2013 IP