-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add physics modifiers wrapper mod for player physics overrides (#289)
Closes #288
- Loading branch information
1 parent
3e2b6c0
commit 7212900
Showing
3 changed files
with
56 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
medkits | ||
physics | ||
hudbars? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
physics = {} | ||
|
||
local players = {} | ||
|
||
minetest.register_on_joinplayer(function(player) | ||
players[player:get_player_name()] = {} | ||
end) | ||
|
||
minetest.register_on_leaveplayer(function(player) | ||
players[player:get_player_name()] = nil | ||
end) | ||
|
||
local function update(name) | ||
assert(players[name]) | ||
local player = minetest.get_player_by_name(name) | ||
local override = { | ||
speed = 1, | ||
jump = 1, | ||
gravity = 1 | ||
} | ||
|
||
for _, layer in pairs(players[name]) do | ||
for attr, val in pairs(layer) do | ||
override[attr] = override[attr] * val | ||
end | ||
end | ||
|
||
player:set_physics_override(override) | ||
end | ||
|
||
function physics.set(pname, name, modifiers) | ||
assert(players[pname] and not players[pname][name]) | ||
players[pname][name] = modifiers | ||
update(pname) | ||
end | ||
|
||
function physics.change(pname, name, modifier) | ||
assert(players[pname] and players[pname][name]) | ||
players[pname][name] = modifier | ||
update(pname) | ||
end | ||
|
||
function physics.remove(pname, name) | ||
assert(players[pname] and players[pname][name]) | ||
players[pname][name] = nil | ||
update(pname) | ||
end |