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.
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.
<?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