PHP Game Experience System: Algorithms for Player vs Player Combat

I’m building a PHP-based browser game and currently working on the attack script. I need a system to calculate experience points (EXP) gained when attacking another player.

The game is still in early stages, so I’m focusing on core mechanics. Any suggestions for a good algorithm that scales with player levels?

Topic Summary: Hybrid EXP formula for PvP: base on opponent level, multiplier for level difference, plus bonus for veteran kills. Risk factor discussion.

:hammer_and_wrench: Featured GitHub Resource:

  • Fekoz/RPG - JRPG / RPG browser online 2d game Engine / platform with a unique system . Have the creation of the character and account on JavaScript PHP ajax js… (★ 36)

:open_book: Topic Overview (Wikipedia):

An experience point is a unit of measurement used in some tabletop role-playing games (RPGs) and role-playing video games to quantify a player character’s life experience and progression through the game. Experience points are generally awarded for the completion of objectives, overcoming obstacles and opponents, and successful role-playing.
Read more on Wikipedia

:books: Official Documentation & Reference Links:

Here’s an algorithm I used for a text RPG I built into an AIM bot. It assumes different players have different levels, and the EXP gained depends on the defeated player’s level:

((x*x)*1.8)+x*(1+(ceil(x/15)-1)*40)

Where x is the level of the player you killed. This formula gives increasing rewards for higher-level opponents, with a jump every 15 levels. However, you need to balance it with your leveling curve. If you’re struggling with basic algorithms, maybe focus on learning math before diving into game dev.

Instead of using a flat algorithm for player kills, consider basing EXP on damage dealt relative to total HP. For example, if a monster has 2000 HP and gives 1000 EXP, attacking it for 500 HP (25%) would grant 250 EXP.

This approach works well for PvE and can be adapted for PvP by treating the opponent as a ‘monster’ with a level-based EXP value. It’s more intuitive and ties rewards directly to contribution.

Interesting approaches so far. I’ve been tinkering with a similar system for my own PHP game and found that a hybrid model works best. I use a base EXP formula based on the opponent’s level, but then apply a multiplier based on the level difference to prevent high-level players from farming lowbies. Something like:

$baseExp = pow($opponentLevel, 2) * 1.5;
$levelDiff = $playerLevel - $opponentLevel;
$multiplier = max(0.1, 1 - ($levelDiff * 0.1)); // 10% reduction per level difference
$exp = $baseExp * $multiplier;

This ensures that defeating someone at your level gives full EXP, but fighting much lower levels gives diminishing returns. For PvP, I also add a bonus based on the opponent’s total EXP earned to reward taking down veterans. What do you all think about incorporating a risk factor, like losing EXP on death? That could add more strategic depth.