3 local function calculate_attribute_product(player
, attribute
)
4 local a
= minetest
.deserialize(player
:get_meta():get_string("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 meta
= player
:get_meta()
20 local a
= minetest
.deserialize(meta
:get_string("playerphysics:physics"))
22 a
= { [attribute
] = { [id
] = value
} }
23 elseif a
[attribute
] == nil then
24 a
[attribute
] = { [id
] = value
}
26 a
[attribute
][id
] = value
28 meta
:set_string("playerphysics:physics", minetest
.serialize(a
))
29 local raw_value
= calculate_attribute_product(player
, attribute
)
30 player
:set_physics_override({[attribute
] = raw_value
})
33 function playerphysics
.remove_physics_factor(player
, attribute
, id
)
34 local meta
= player
:get_meta()
35 local a
= minetest
.deserialize(meta
:get_string("playerphysics:physics"))
36 if a
== nil or a
[attribute
] == nil then
40 a
[attribute
][id
] = nil
42 meta
:set_string("playerphysics:physics", minetest
.serialize(a
))
43 local raw_value
= calculate_attribute_product(player
, attribute
)
44 player
:set_physics_override({[attribute
] = raw_value
})