3 local function calculate_attribute_product(player
, attribute
)
4 local a
= minetest
.deserialize(player
:get_attribute("playerphysics:physics"))
6 if a
== nil or a
[attribute
] == nil then
9 local factors
= a
[attribute
]
10 if type(factors
) == "table" then
11 for _
, factor
in pairs(factors
) do
12 product
= product
* factor
18 function playerphysics
.add_physics_factor(player
, attribute
, id
, value
)
19 local a
= minetest
.deserialize(player
:get_attribute("playerphysics:physics"))
21 a
= { [attribute
] = { [id
] = value
} }
22 elseif a
[attribute
] == nil then
23 a
[attribute
] = { [id
] = value
}
25 a
[attribute
][id
] = value
27 player
:set_attribute("playerphysics:physics", minetest
.serialize(a
))
28 local raw_value
= calculate_attribute_product(player
, attribute
)
29 player
:set_physics_override({[attribute
] = raw_value
})
32 function playerphysics
.remove_physics_factor(player
, attribute
, id
)
33 local a
= minetest
.deserialize(player
:get_attribute("playerphysics:physics"))
34 if a
== nil or a
[attribute
] == nil then
38 a
[attribute
][id
] = nil
40 player
:set_attribute("playerphysics:physics", minetest
.serialize(a
))
41 local raw_value
= calculate_attribute_product(player
, attribute
)
42 player
:set_physics_override({[attribute
] = raw_value
})