smc Posted August 2, 2006 Share Posted August 2, 2006 Hello,I'm trying to create a script to determine a users "Level" by analyzing the number "exp" in the MySQL database, then comparing it to the experiance number of the different levels.Here is the simple statement I thought of:[code]if ($dbexpaccuracy > $lvl1m || $dbexpaccuracy < $lvl2m){$accuracy = "1";}if ($dbexpaccuracy == $lvl1m){$accuracy = "1";}[/code]But for this I would have to define this statement for all 150 levels, then do it again for all 20 some other skills.I was wondering if there was a way I could have the experiance anaylzed to determinie what level it was, then plug it in for all the appropriate variables for echoing.Thanks!!-SmC Quote Link to comment Share on other sites More sharing options...
bltesar Posted August 2, 2006 Share Posted August 2, 2006 You'll have to provide more specific and detailed information. What do you mean by 'level' and 'exp'? Quote Link to comment Share on other sites More sharing options...
smc Posted August 2, 2006 Author Share Posted August 2, 2006 [quote author=bltesar link=topic=102737.msg408199#msg408199 date=1154537570]You'll have to provide more specific and detailed information. What do you mean by 'level' and 'exp'?[/quote]Well basically the level is in a game for example. If you have more than this amount of "exp" (or a number) but less than another amount of exp then you are this level.For example. Level 1 is 0 exp, Level 2 is 200 exp. If your 132 exp your obviously level 1, so I need a script to determine that the number (exp) is greator than lvl1m (variable defining level 1's exp) but less than lvl2m, and return that the level is one.Hope this clears it up a bit more Quote Link to comment Share on other sites More sharing options...
bpops Posted August 2, 2006 Share Posted August 2, 2006 You could input all the level requirements into an array, then loop through the array to find the appropriate level. Quote Link to comment Share on other sites More sharing options...
smc Posted August 2, 2006 Author Share Posted August 2, 2006 [quote author=bpops link=topic=102737.msg408209#msg408209 date=1154538053]You could input all the level requirements into an array, then loop through the array to find the appropriate level.[/quote]Would this be able to do it for all the different "skills." For example, I need to find a level for skill 1, skill 2, skill 3, etc. but they all use the same numbers for experiance.If so, could you show me an example of what your talking about? I'm a newbie when it comes to things like this, I know stuff in some areas but not in others :PThanks! Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted August 2, 2006 Share Posted August 2, 2006 If you don't want to hard code what XP values each level has, then you'll need to create an algorithm that will have an exponential increase for each level. This could work experience, skills, etc...I came across a web page where someone dissected the XP mechanics for FF7, which may help you get started.Check it out [url=http://astro.berkeley.edu/~dperley/ff7/expmechanics.html]HERE[/url] Quote Link to comment Share on other sites More sharing options...
ober Posted August 2, 2006 Share Posted August 2, 2006 Might I suggest the following:[code]<?phpswitch($dbexpaccuracy){ case ($dbexpaccuracy < 500) : $accuracy = 10; case ($dbexpaccuracy < 450) : $accuracy = 9; ... default : $accuracy = 1;}?>[/code]It basically falls through the switch until it finds what it's looking for. Keep in mind, I didn't test this, but it should work in theory. You may have to adjust it or flip it so that it goes up instead of down. Quote Link to comment Share on other sites More sharing options...
smc Posted August 2, 2006 Author Share Posted August 2, 2006 [quote author=ober link=topic=102737.msg408215#msg408215 date=1154538389]Might I suggest the following:[code]<?phpswitch($dbexpaccuracy){ case ($dbexpaccuracy < 500) : $accuracy = 10; case ($dbexpaccuracy < 450) : $accuracy = 9; ... default : $accuracy = 1;}?>[/code]It basically falls through the switch until it finds what it's looking for. Keep in mind, I didn't test this, but it should work in theory. You may have to adjust it or flip it so that it goes up instead of down.[/quote]For that script though wouldn't I need to mimic that for all that "skills?" Is there any way I can get around that? Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted August 2, 2006 Share Posted August 2, 2006 Depending on how many levels you allow, that could be one [b]HUGE[/b] switch statement.I still say an algorithm would be the way to go. The source code for [url=http://phprpg.org/]phpRPG[/url] is available as well. You could get some ideas from the way they calculate experience, skills etc... ;) Quote Link to comment Share on other sites More sharing options...
smc Posted August 2, 2006 Author Share Posted August 2, 2006 [quote author=HeyRay2 link=topic=102737.msg408219#msg408219 date=1154538716]Depending on how many levels you allow, that could be one [b]HUGE[/b] switch statement.I still say an algorithm would be the way to go. The source code for [url=http://phprpg.org/]phpRPG[/url] is available as well. You could get some ideas from the way they calculate experience, skills etc... ;)[/quote]Yeah thats my problem, because there is 20 something skills and 150 levels for each of them.The exp for the code though is hard coded as the game operates on set values of experiance. Quote Link to comment Share on other sites More sharing options...
sasa Posted August 2, 2006 Share Posted August 2, 2006 creat table 'levels' in DB with columns: skil, level and expto get level use[code]SELECT level FROM levels WHERE skil=$user_skil AND exp <= $user_exp ORDER BY level DESC LIMIT 1[/code] Quote Link to comment Share on other sites More sharing options...
smc Posted August 4, 2006 Author Share Posted August 4, 2006 Well unfortunatly the way the game operates it dosen't store it in level form.I was wondering if an array is the best bet. I'm not really sure how to do the array but something like$variable = new_array("0", "27", "58", "92", "130", "173", "220", ............But if I did something like that, how would I cycle through it until it found which it was greator then, with which level it was less than? I suppose it could stop at the number it is less than, but I'm just not farmilar with PHP enough to devise that kind of function.Help :( Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 4, 2006 Share Posted August 4, 2006 This example should help good luck.[code]<?php session_start();$level=array('admin'=>"1",'normal'=>"2",'lower'=>"3",'medium'=>"4");$user=$_SESSION['user']='redarrow';$user=$level['admin'];if($user=='1') {echo "hello";} ?>[/code] Quote Link to comment Share on other sites More sharing options...
bltesar Posted August 8, 2006 Share Posted August 8, 2006 define the exp values for the various levels in an array, e.g.-$level=array(0,200,400,750,...);level 1 is 0-200, level 2 is 201-400, level 3 is 401-750then use the following code to find your level:$i=1;$exp_score;while($level[$i]<$exp_score){ $i++;}$i is the level for $exp_score Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.