User Tools

Site Tools


damage_logic

Damage Logic


In RPG in a Box, any time one character attacks another, a calculation is done to determine how much damage is done to the character being attacked. If you'd like to customize this logic for your game, you can do so by creating a script named “damage_logic” in your project. The name must be exact, including case. The script should return a numeric value, which will be used for the damage amount applied to the defending character. The $attacker and $defender variables will be the attacking character and defending character, respectively, so you can use these to check various stats or properties of those characters. The $weapon variable will be the item codex of the attacking character's weapon, or null if no weapon is equipped.

Below is the Bauxite code for the default damage logic. You can take this and customize it as desired, or create your own logic from scratch! The only requirement is that the script returns a numeric value.

$diff = $attacker.stat["attack"] - $defender.stat["defense"];
if $diff <= 0 then
   $damage = random(0, 1);
elseif $weapon == null then
   $damage = $diff + random(-1, 1);
else
   $damage = $diff + random(-1, 1) + random($weapon.min_damage, $weapon.max_damage);
end;
if $damage < 0 then
   $damage = 0;
end;
return $damage;

The default damage logic first calculates the difference between the attacker's “attack” stat and the defender's “defense” stat. If the difference is less than or equal to zero (i.e. the attack stat is less than the defense stat), the resulting damage will be a random value of either 0 or 1 (to give the attacker a chance to do at least 1 damage). Otherwise, it checks if the attacker has a weapon equipped. If not, the resulting damage will be the attack/defense difference plus a random value of other -1, 0, or 1. If a weapon is equipped, it will also add a random value between the weapon's minimum damage and maximum damage.

The default damage logic is loosely based on that of Shining Force, and is subject to change in future releases of RPG in a Box.

damage_logic.txt · Last modified: 2025/04/22 13:45 by justin