User Tools

Site Tools


damage_logic

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
damage_logic [2025/04/20 11:46] justindamage_logic [2025/04/22 13:45] (current) justin
Line 1: Line 1:
 ======Damage Logic====== ======Damage Logic======
 ---- ----
-If you'd like customize the damage logic for your game, create 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 when one [[character]] attacks another. The **$attacker** and **$defender** variables  will be the attacking [[character]] and defending [[character]], respectively, so you can use these to check various [[stats_editor|stats]] or [[set_entity_property|properties]] of those characters. The **$weapon** variable will be the [[item]] [[codex]] of the attacking character's [[weapons|weapon]], or null if no [[weapons|weapon]] is equipped.+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 [[number|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_editor|stats]] or [[set_entity_property|properties]] of those characters. The **$weapon** variable will be the [[item]] [[codex]] of the attacking character's [[weapons|weapon]], or null if no [[weapons|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.+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 [[number|numeric value]].
 <code bauxite> <code bauxite>
 $diff = $attacker.stat["attack"] - $defender.stat["defense"]; $diff = $attacker.stat["attack"] - $defender.stat["defense"];
Line 18: Line 18:
 return $damage; return $damage;
 </code> </code>
 +
 +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 [[weapons|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 [[weapons|weapon]] is equipped, it will also add a random value between the weapon's minimum damage and maximum damage.
 +
 +<WRAP center round info 100%>
 +The default damage logic is loosely based on that of [[https://en.wikipedia.org/wiki/Shining_Force|Shining Force]], and is subject to change in future releases of RPG in a Box.
 +</WRAP>
  
 ~~NOTOC~~ ~~NOTOC~~
damage_logic.1745174800.txt.gz · Last modified: 2025/04/20 11:46 by justin