use mobs process_weapon function in on_punchplayer callback, adjust energy formula, add physics.freeze_player and physics.unfreeze_player, freeze player on sit and sleep

pull/2/head
Brandon 2014-05-17 22:09:05 -05:00
parent dad7ffe188
commit c948715d24
5 changed files with 34 additions and 26 deletions

View File

@ -27,7 +27,7 @@ You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
License of media (textures and sounds)
License of media (models, textures and sounds)
--------------------------------------
Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
See README.txt in each mod directory for information about other authors.
@ -38,3 +38,5 @@ http://creativecommons.org/licenses/by-sa/3.0/
License of menu/header.png
Copyright (C) 2013 BlockMen CC BY-3.0
License of Spider model
Copyright (C) 2013 AspireMint CC BY-SA

View File

@ -165,7 +165,7 @@ minetest.register_globalstep(function(dtime)
local animation_speed_mod = model.animation_speed or 30
-- Determine if the player is walking
if controls.up or controls.down or controls.left or controls.right then
if ( controls.up or controls.down or controls.left or controls.right ) and physics.player_frozen[name] ~= true then
walking = true
end
@ -195,7 +195,7 @@ minetest.register_globalstep(function(dtime)
player_set_animation(player, "walk", animation_speed_mod)
end
elseif controls.LMB then
if player_anim[name] == "lay" or player_anim[name] == "sit" then
if player_anim[name] == "lay" or player_anim[name] == "sit" and physics.player_frozen[name] ~= true then
player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
if player_sleephuds[name] ~= nil then
player:hud_remove(player_sleephuds[name])
@ -214,23 +214,7 @@ end)
if minetest.register_on_punchplayer ~= nil then
minetest.register_on_punchplayer( function(player, hitter, time_from_last_punch, tool_capabilities, dir)
local weapon = hitter:get_wielded_item()
if tool_capabilities ~= nil then
local wear = ( tool_capabilities.full_punch_interval / 75 ) * 65535
weapon:add_wear(wear)
hitter:set_wielded_item(weapon)
end
if weapon:get_definition().sounds ~= nil then
local s = math.random(0,#weapon:get_definition().sounds)
minetest.sound_play(weapon:get_definition().sounds[s], {
object=hitter,
})
else
minetest.sound_play("default_sword_wood", {
object = hitter,
})
end
process_weapon(player,time_from_last_punch,tool_capabilities)
blood_particles(player:getpos(),0.5,27,"mobs_blood.png")
if player_anim[name] == "lay" or player_anim[name] == "sit" then
player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
@ -238,6 +222,11 @@ if minetest.register_on_punchplayer ~= nil then
player:hud_remove(player_sleephuds[name])
player_sleephuds[name] = nil
end
physics.unfreeze_player(name)
end
if math.random(0,3) == 3 then
local snum = math.random(1,4)
minetest.sound_play("default_hurt"..tostring(snum),{object = player})
end
end)
end

View File

@ -15,7 +15,7 @@ function hud.update_stamina(p,name)
end
local anim = default.player_get_animation(p)
local adj = 0.25
local adj = 0.25 + ( 0.2 * ( skills.player_levels[name].level / 5 ) )
if anim.animation == "lay" then
adj = adj + 0.75
if math.random(0,4) == 1 then
@ -31,11 +31,11 @@ function hud.update_stamina(p,name)
-- adjust their stamina
local vdiff = pos.y - player_lastpos[name].y
if vdiff > 0 then
adj = adj - ( vdiff * 0.06 )
adj = adj - ( vdiff * 0.05 )
end
local hdiff = math.sqrt(math.pow(pos.x-player_lastpos[name].x, 2) + math.pow(pos.z-player_lastpos[name].z, 2))
adj = adj - ( hdiff * 0.03 )
adj = adj - ( hdiff * 0.02 )
player_stamina[name] = player_stamina[name] + adj
if player_stamina[name] < 0 then
@ -95,6 +95,7 @@ minetest.register_chatcommand("sit",{
player:hud_remove(player_sleephuds[name])
player_sleephuds[name] = nil
end
physics.freeze_player(name)
end,
})
@ -112,6 +113,7 @@ minetest.register_chatcommand("sleep",{
alignment = {x=-1,y=-1},
offset = {x=0,y=0},
})
physics.freeze_player(name)
end,
})
@ -124,6 +126,7 @@ minetest.register_chatcommand("stand",{
player:hud_remove(player_sleephuds[name])
player_sleephuds[name] = nil
end
physics.unfreeze_player(name)
end,
})

@ -1 +1 @@
Subproject commit 440cdbf593992a765fc06d3a0caaba4b20d26db8
Subproject commit 019f2379273984e04c5e91a846f2d147eb9bb33b

View File

@ -6,7 +6,7 @@
physics = {}
local physics_file = minetest.get_worldpath() .. "/physics"
physics.player_physics = default.deserialize_from_file(physics_file)
physics.player_frozen = {}
function physics.adjust_physics(player,_physics)
local name = player:get_player_name()
for p,v in pairs(_physics) do
@ -17,7 +17,21 @@ end
function physics.apply(player)
local name = player:get_player_name()
player:set_physics_override(physics.player_physics[name])
if physics.player_frozen[name] ~= true then
player:set_physics_override(physics.player_physics[name])
end
end
function physics.freeze_player(name)
local player = minetest.get_player_by_name(name)
physics.player_frozen[name] = true
player:set_physics_override({speed=0,jump=0})
end
function physics.unfreeze_player(name)
local player = minetest.get_player_by_name(name)
physics.player_frozen[name] = false
physics.apply(minetest.get_player_by_name(name))
end
function physics.remove_item_physics(player,item)