Add get_physics_factor
This commit is contained in:
parent
6d12fad9a3
commit
83759ba199
13
API.md
13
API.md
@ -46,6 +46,19 @@ Removes the physics factor of the given ID and updates the player's physics.
|
|||||||
#### Parameters
|
#### Parameters
|
||||||
Same as in `playerphysics.add_physics_factor`, except there is no `value` argument.
|
Same as in `playerphysics.add_physics_factor`, except there is no `value` argument.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### `playerphysics.get_physics_factor(player, attribute, id)`
|
||||||
|
Returns the current physics factor of the given ID, if it exists.
|
||||||
|
If the ID exists, returns a number. If it does not exist, returns nil.
|
||||||
|
|
||||||
|
Note a missing physics factor is mathematically equivalent to a factor of 1.
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
Same as in `playerphysics.add_physics_factor`, except there is no `value` argument.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
### Speed changes
|
### Speed changes
|
||||||
Let's assume this mod is used by 3 different mods all trying to change the speed:
|
Let's assume this mod is used by 3 different mods all trying to change the speed:
|
||||||
|
12
init.lua
12
init.lua
@ -43,3 +43,15 @@ function playerphysics.remove_physics_factor(player, attribute, id)
|
|||||||
local raw_value = calculate_attribute_product(player, attribute)
|
local raw_value = calculate_attribute_product(player, attribute)
|
||||||
player:set_physics_override({[attribute] = raw_value})
|
player:set_physics_override({[attribute] = raw_value})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function playerphysics.get_physics_factor(player, attribute, id)
|
||||||
|
local meta = player:get_meta()
|
||||||
|
local a = minetest.deserialize(meta:get_string("playerphysics:physics"))
|
||||||
|
if a == nil then
|
||||||
|
return nil
|
||||||
|
elseif a[attribute] == nil then
|
||||||
|
return nil
|
||||||
|
else
|
||||||
|
return a[attribute][id]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user