Jump to content
MakeWebGames

EXP function


ShadyCoco

Recommended Posts

Hey..

I've been trying to work out how to make an EXP function for my little project.

I'm honestly lost..

the only way I can get anything to work is with an if statment like so:

<?php

if($_USER['exp'] >= 100) {
echo' You are level one.';
}
elseif ($_USER['exp'] >= 500) {
echo' You are level two';
}
?>

They must be a much better way to do this I just don't know how.

Any help at all, even other function that might help me would be great!

Thanks

Link to comment
Share on other sites

It depends how you want to structure your EXP system, but one of the common ways is to base how much experience is needed on the users level.

For instance;

$expneeded = ($_USER['level']*10)+300;
if($_USER['exp'] >= $expneeded) {
    $_USER['level']++;
    echo "You are now level ".$_USER['level'].";
}

 

With this, you are setting a base amount of experience needed to level (300) and then every level higher they go, they must obtain more experience. In my example, if your player is level 10, they must obtain 400 experience points to level up.

You can modify this however you want to meet your needs.

I hope this gives you a better idea.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...