Difference between revisions of "Proposals/Damage system"

From Minetest Developer Wiki
Jump to navigation Jump to search
(Created page with "For tools: <code> Old: minetest.register_tool("default:sword_steel", { description = "Steel Sword", inventory_image = "default_tool_steelsword.png", tool_capabilit...")
 
m (Rubenwardy moved page Proposals / Damage system to Proposals/Damage system without leaving a redirect)
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
For tools:
+
== Old ==
<code>
+
<pre>
Old:
 
 
minetest.register_tool("default:sword_steel", {
 
minetest.register_tool("default:sword_steel", {
 
     description = "Steel Sword",
 
     description = "Steel Sword",
Line 15: Line 14:
 
     }
 
     }
 
})
 
})
New:
+
</pre>
 +
<pre>
 +
    self.object:set_armor_groups({fleshy=3})
 +
</pre>
 +
 
 +
=== Damage calculation ===
 +
 
 +
Ehm, you don't want to know.
 +
 
 +
== New ==
 +
<pre>
 
minetest.register_tool("default:sword_steel", {
 
minetest.register_tool("default:sword_steel", {
 
     description = "Steel Sword",
 
     description = "Steel Sword",
Line 32: Line 41:
 
     }
 
     }
 
})
 
})
</code>
+
</pre>
 +
<pre>
 +
    self.object:set_armor_groups({fleshy=100})
 +
</pre>
  
For entities:
+
=== Damage calculation ===
<code>
+
 
Old:
+
<pre>
     self.object:set_armor_groups({fleshy=3})
+
damage = 0
New:
+
foreach group in cap.damage_groups:
    self.object:set_armor_groups({fleshy=-1})
+
     damage += cap.damage_groups[group] * limit(actual_interval / cap.full_punch_interval, 0.0, 1.0)
</code>
+
        * (object.armor_groups[group] / 100.0)
 +
        -- Where object.armor_groups[group] is 0 for inexisting values
 +
return damage
 +
</pre>
 +
[[Category:Modding API‏‎]]

Latest revision as of 21:15, 15 August 2022

Old

minetest.register_tool("default:sword_steel", {
    description = "Steel Sword",
    inventory_image = "default_tool_steelsword.png",
    tool_capabilities = {
        full_punch_interval = 0.8,
        max_drop_level=1,
        groupcaps={
            fleshy={times={[1]=2.00, [2]=0.80, [3]=0.40}, uses=10, maxlevel=2},
            snappy={times={[2]=0.70, [3]=0.30}, uses=40, maxlevel=1},
            choppy={times={[3]=0.65}, uses=40, maxlevel=0}
        }
    }
})
    self.object:set_armor_groups({fleshy=3})

Damage calculation

Ehm, you don't want to know.

New

minetest.register_tool("default:sword_steel", {
    description = "Steel Sword",
    inventory_image = "default_tool_steelsword.png",
    tool_capabilities = {
        -- Digging capabilities
        max_drop_level = 1,
        groupcaps = {
            fleshy={times={[1]=2.00, [2]=0.80, [3]=0.40}, uses=10, maxlevel=2},
            snappy={times={[2]=0.70, [3]=0.30}, uses=40, maxlevel=1},
            choppy={times={[3]=0.65}, uses=40, maxlevel=0}
        },
        -- Damage capabilities
        full_punch_interval = 0.8,
        damage_groups = {fleshy=8, snappy=4, choppy=2},
    }
})
    self.object:set_armor_groups({fleshy=100})

Damage calculation

damage = 0
foreach group in cap.damage_groups:
    damage += cap.damage_groups[group] * limit(actual_interval / cap.full_punch_interval, 0.0, 1.0)
        * (object.armor_groups[group] / 100.0)
        -- Where object.armor_groups[group] is 0 for inexisting values
return damage