1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-26 02:30:38 +01:00

Merge branch 'crabman77-fix_physics' into NALC2

This commit is contained in:
sys4-fr 2017-04-05 10:31:58 +02:00
commit 9417e3335d
5 changed files with 263 additions and 117 deletions

View File

@ -0,0 +1,126 @@
local players = {}
player_physics = {}
function player_physics.check(playername)
if players[playername] == nil then
players[playername] = {speed = {}, jump = {}, gravity={}, temp={}}
end
end
minetest.register_on_joinplayer(function(player)
local playername = player:get_player_name()
player_physics.check(playername)
end)
minetest.register_on_leaveplayer(function(player)
local playername = player:get_player_name()
players[playername] = nil
end)
function player_physics.add(player, physicsname , name, value)
if physicsname ~= "speed" and physicsname ~= "jump" and physicsname ~= "gravity" then
return
end
local playername = player:get_player_name()
player_physics.check(playername)
players[playername][physicsname][name] = value
end
function player_physics.remove(player, physicsname, name)
if physicsname ~= "speed" and physicsname ~= "jump" and physicsname ~= "gravity" then
return
end
local playername = player:get_player_name()
player_physics.check(playername)
players[playername][physicsname][name] = nil
end
function player_physics.add_effect(player, physicsname, name, value, time)
if physicsname ~= "speed" and physicsname ~= "jump" and physicsname ~= "gravity" then
return
end
if type(value) ~= "number" or type(time) ~= "number" then
return
end
local playername = player:get_player_name()
player_physics.check(playername)
players[playername]["temp"][name] = {n=physicsname, v=value, t=time}
end
function player_physics.remove_effect(player, name)
local playername = player:get_player_name()
player_physics.check(playername)
players[playername]["temp"][name] = nil
end
minetest.register_globalstep(function(dtime)
for _,player in ipairs(minetest.get_connected_players()) do
local playername = player:get_player_name()
if playername ~= "" then
player_physics.check(playername)
local speed = 1
local jump = 1
local gravity = 1
for _, v in pairs(players[playername]["speed"]) do
speed = speed + v
end
for _, v in pairs(players[playername]["jump"]) do
jump = jump + v
end
for _, v in pairs(players[playername]["gravity"]) do
gravity = gravity + v
end
--temporary effect
for n, k in pairs(players[playername]["temp"]) do
if k.n == "speed" then
speed = speed + k.v
elseif k.n == "jump" then
jump = jump + k.v
elseif k.n == "gravity" then
gravity = gravity + k.v
end
t = k.t-dtime
if t > 0 then
players[playername]["temp"][n]["t"] = t
else
players[playername]["temp"][n] = nil
end
end
if speed > 4 then
speed = 4
elseif speed < 0 then
speed = 0
end
if jump > 3 then
jump = 3
elseif jump < 0 then
jump = 0
end
if gravity > 2 then
gravity = 2
elseif gravity < -2 then
gravity = -2
end
player:set_physics_override({speed=speed,jump=jump, gravity=gravity})
end
end
end)

View File

@ -1 +1,2 @@
hudbars?
player_physics

View File

@ -208,9 +208,13 @@ function setSprinting(playerName, sprinting) --Sets the state of a player (0=sto
if sprint.players[playerName] then
sprint.players[playerName]["sprinting"] = sprinting
if sprinting == true then
player:set_physics_override({speed=SPRINT_SPEED + bonus_speed,jump=SPRINT_JUMP + bonus_jump})
-- player:set_physics_override({speed=SPRINT_SPEED + bonus_speed,jump=SPRINT_JUMP + bonus_jump})
player_physics.add(player, "speed", "sprint_speed", 0.35+ bonus_speed)
player_physics.add(player, "jump", "sprint_jump", 0.1+ bonus_jump)
elseif sprinting == false then
player:set_physics_override({speed=1.0 + bonus_speed,jump=1.0 + bonus_jump})
-- player:set_physics_override({speed=1.0 + bonus_speed,jump=1.0 + bonus_jump})
player_physics.add(player, "speed", "sprint_speed", bonus_speed)
player_physics.add(player, "jump", "sprint_jump", bonus_jump)
end
return true
end

View File

@ -2,6 +2,7 @@ default
vessels
tnt
fire
player_physics
playereffects
farming?
lightning?

View File

@ -1089,8 +1089,6 @@ minetest.register_entity("witchcraft:death_splash", {
end
end
end
end,
})
@ -1136,8 +1134,6 @@ minetest.register_entity("witchcraft:heal_splash", {
end
end
end
end,
})
@ -1168,7 +1164,6 @@ minetest.register_entity("witchcraft:slow_splash", {
local t = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
local n = minetest.env:get_node(p).name
if n ~= "witchcraft:slow_splash" and n ~= "air" then
self.object:remove()
elseif n =="default:dirt_with_grass" or n =="default:dirt_with_dry_grass" then
minetest.sound_play("default_break_glass.1", {
@ -1182,8 +1177,6 @@ minetest.register_entity("witchcraft:slow_splash", {
end
end
end
end,
})
@ -1193,17 +1186,33 @@ minetest.register_entity("witchcraft:fast_splash", {
damage = 2,
collisionbox = {0, 0, 0, 0, 0, 0},
on_step = function(self, obj, pos)
local remove = minetest.after(2, function()
local remove = minetest.after(5, function()
self.object:remove()
end)
local pos = self.object:getpos()
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
for k, obj in pairs(objs) do
if obj:is_player() then
playereffects.apply_effect_type("potion_slow_lv1", 11, obj)
minetest.sound_play("default_break_glass", {
pos = self.object:getpos(),
max_hear_distance = 20,
gain = 10.0,
})
self.object:remove()
return
end
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "witchcraft:fast_splash" and obj:get_luaentity().name ~= "__builtin:item" then
if obj:get_luaentity().name ~= "witchcraft:fast_splash" and obj:get_luaentity().name ~= "__builtin:item" and obj:get_luaentity().name ~= "gauges:hp_bar" then
local vel = obj:getvelocity()
obj:setvelocity({x=vel.x*4, y=vel.y*1, z=vel.z*4})
self.object:remove()
minetest.sound_play("default_break_glass", {
pos = self.object:getpos(),
max_hear_distance = 20,
gain = 10.0,
})
self.object:remove()
return
end
end
end
@ -1214,8 +1223,7 @@ minetest.register_entity("witchcraft:fast_splash", {
local t = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
local n = minetest.env:get_node(p).name
if n ~= "witchcraft:fast_splash" and n ~= "air" then
self.object:remove()
self.object:remove()
elseif n =="default:dirt_with_grass" or n =="default:dirt_with_dry_grass" then
minetest.sound_play("default_break_glass.1", {
pos = self.object:getpos(),
@ -1228,8 +1236,6 @@ minetest.register_entity("witchcraft:fast_splash", {
end
end
end
end,
})
@ -1259,11 +1265,8 @@ minetest.register_entity("witchcraft:antigrav_splash", {
local p = {x=pos.x+dx, y=pos.y, z=pos.z+dz}
local t = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
local n = minetest.env:get_node(p).name
if n ~= "witchcraft:antigrav_splash" and n ~= "air" then
self.object:remove()
elseif n =="default:dirt_with_grass" or n =="default:dirt_with_dry_grass" then
minetest.sound_play("default_break_glass.1", {
if n ~= "air" then
minetest.sound_play("default_break_glass", {
pos = self.object:getpos(),
max_hear_distance = 20,
gain = 10.0,
@ -1274,8 +1277,6 @@ minetest.register_entity("witchcraft:antigrav_splash", {
end
end
end
end,
})
@ -1305,11 +1306,8 @@ minetest.register_entity("witchcraft:jump_splash", {
local p = {x=pos.x+dx, y=pos.y, z=pos.z+dz}
local t = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
local n = minetest.env:get_node(p).name
if n ~= "witchcraft:jump_splash" and n ~= "air" then
self.object:remove()
elseif n =="default:dirt_with_grass" or n =="default:dirt_with_dry_grass" then
minetest.sound_play("default_break_glass.1", {
if n ~= "air" then
minetest.sound_play("default_break_glass", {
pos = self.object:getpos(),
max_hear_distance = 20,
gain = 10.0,
@ -1320,8 +1318,6 @@ minetest.register_entity("witchcraft:jump_splash", {
end
end
end
end,
})
@ -1367,8 +1363,6 @@ minetest.register_entity("witchcraft:murky_splash", {
end
end
end
end,
})
@ -1439,88 +1433,108 @@ minetest.register_entity("witchcraft:smoke_splash", {
playereffects.register_effect_type("potion_speed_lv1", "High speed", nil, {"speed"},
function(player)
player:set_physics_override(2,nil,nil)
--player:set_physics_override(2,nil,nil)
player_physics.add(player, "speed", "potion_speed_lv1", 1)
end,
function(effect, player)
player:set_physics_override(1,nil,nil)
--player:set_physics_override(1,nil,nil)
player_physics.remove(player, "speed", "potion_speed_lv1")
end,
false
)
playereffects.register_effect_type("potion_speed_lv2", "High speed", nil, {"speed"},
function(player)
player:set_physics_override(2.5,nil,nil)
--player:set_physics_override(2.5,nil,nil)
player_physics.add(player, "speed", "potion_speed_lv2", 1.5)
end,
function(effect, player)
player:set_physics_override(1,nil,nil)
--player:set_physics_override(1,nil,nil)
player_physics.remove(player, "speed", "potion_speed_lv2")
end,
false
)
playereffects.register_effect_type("potion_jump_lvx", "High Jump", nil, {"jump"},
function(player)
player:set_physics_override(nil,1.5,0.8)
--player:set_physics_override(nil,1.5,0.8)
player_physics.add(player, "jump", "potion_jump_lvx", 0.5)
player_physics.add(player, "gravity", "potion_jump_lvx", -0.2)
end,
function(effect, player)
player:set_physics_override(nil,1,1)
--player:set_physics_override(nil,1,1)
player_physics.remove(player, "jump", "potion_jump_lvx")
player_physics.remove(player, "gravity", "potion_jump_lvx")
end,
false
)
playereffects.register_effect_type("potion_antigrav_lvx", "Light weight", nil, {"gravity"},
function(player)
player:set_physics_override(nil,nil,0.1)
--player:set_physics_override(nil,nil,0.1)
player_physics.add(player, "gravity", "potion_antigrav_lvx", -0.9)
end,
function(effect, player)
player:set_physics_override(nil,nil,1)
--player:set_physics_override(nil,nil,1)
player_physics.remove(player, "gravity", "potion_antigrav_lvx")
end,
false
)
playereffects.register_effect_type("potion_slow_lv1", "Low speed", nil, {"speed"},
function(player)
player:set_physics_override(0.5,nil,nil)
--player:set_physics_override(0.5,nil,nil)
player_physics.add(player, "speed", "potion_slow_lv1", -0.5)
end,
function(effect, player)
player:set_physics_override(1,nil,nil)
--player:set_physics_override(1,nil,nil)
player_physics.remove(player, "speed", "potion_slow_lv1")
end,
false
)
playereffects.register_effect_type("potion_slow_lv2", "Low speed", nil, {"speed"},
function(player)
player:set_physics_override(0.4,nil,nil)
--player:set_physics_override(0.4,nil,nil)
player_physics.add(player, "speed", "potion_slow_lv2", -0.6)
end,
function(effect, player)
player:set_physics_override(1,nil,nil)
--player:set_physics_override(1,nil,nil)
player_physics.remove(player, "speed", "potion_slow_lv2")
end,
false
)
playereffects.register_effect_type("potion_swim_lv1", "Fast Swim", nil, {"swim"},
function(player)
player:set_physics_override(3,nil,nil)
--player:set_physics_override(3,nil,nil)
player_physics.add(player, "speed", "potion_swim_lv1", 2)
end,
function(effect, player)
player:set_physics_override(1,nil,nil)
--player:set_physics_override(1,nil,nil)
player_physics.remove(player, "speed", "potion_swim_lv1")
end,
false
)
playereffects.register_effect_type("potion_swim_lv2", "Dive", nil, {"swim"},
function(player)
player:set_physics_override(3,nil,4)
--player:set_physics_override(3,nil,4)
player_physics.add(player, "speed", "potion_swim_lv2", 2)
player_physics.add(player, "gravity", "potion_swim_lv2", 3)
end,
function(effect, player)
player:set_physics_override(1,nil,1)
--player:set_physics_override(1,nil,1)
player_physics.remove(player, "speed", "potion_swim_lv2")
player_physics.remove(player, "gravity", "potion_swim_lv2")
end,
false
)
@ -2210,7 +2224,7 @@ minetest.register_entity("witchcraft:fire", {
local p = {x=pos.x+dx, y=pos.y, z=pos.z+dz}
local t = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
local n = minetest.env:get_node(p).name
if n ~= "witchcraft:fire" and n ~= "air" and n ~="default:dirt_with_grass" and n ~="default:dirt_with_dry_grass" and n ~="default:stone" then
if n ~= "witchcraft:fire" and n ~= "air" and n ~="default:dirt_with_grass" and n ~="default:dirt_with_dry_grass" and n ~="default:stone" then
minetest.env:set_node(t, {name="fire:basic_flame"})
elseif n =="default:dirt_with_grass" or n =="default:dirt_with_dry_grass" then
self.object:remove()