Merge pull request #35 from rubenwardy/mobs_crash_Fix

Fix mobs crash on no XP found
This commit is contained in:
cd2 2016-07-09 09:03:43 +02:00 committed by GitHub
commit 494b061dbe
2 changed files with 21 additions and 20 deletions

View File

@ -8,7 +8,7 @@ end
function mobs.register_mob(name, def)
mobs.mobs[#mobs.mobs+1] = {name, def.lvl}
if not def.hp then
if def.lvl and def.hits then
def.hp = classes.get_dmg(def.lvl)*def.hits
@ -23,7 +23,7 @@ function mobs.register_mob(name, def)
visual_size = def.visual_size or {x=1, y=1},
textures = def.textures,
spritediv = {x=1, y=1},
initial_sprite_basepos = {x=0, y=0},
initial_sprite_basepos = {x=0, y=0},
is_visible = true,
makes_footstep_sound = false,
automatic_rotate = true,
@ -67,7 +67,7 @@ function mobs.register_mob(name, def)
self.object:setyaw(yaw)
found = true
obj:punch(self.object, 10, def.dmg, nil)
obj:punch(self.object, 10, def.dmg, nil)
break
end
end
@ -111,7 +111,7 @@ function mobs.register_mob(name, def)
end
self.object:setyaw(yaw)
end
self.t = 0
self.t = 0
end
end,
})
@ -134,9 +134,9 @@ function mobs.register_mob(name, def)
})
end
function mobs.get_mob(lvl)
a = {}
found_mob = false
function mobs.get_mob(lvl)
local a = {}
local found_mob = false
for i,n in ipairs(mobs.mobs) do
if n[2] < lvl +5 and n[2] > lvl-5 then
found_mob = true
@ -156,7 +156,7 @@ function mobs.get_mob(lvl)
a[#a+1] = n[1]
end
end
if found_mob then
return a[math.random(1, #a)]
end
@ -214,7 +214,7 @@ mobs.register_mob("mobs:big_slime", {
collisionbox = {-0.9, -1, -0.9, 0.9, 1, 0.9},
description = "Big Slime",
range = 3,
})
mobs.register_mob("mobs:dungeon_guardian", {
@ -232,7 +232,7 @@ mobs.register_mob("mobs:dungeon_guardian", {
collisionbox = {-0.8, -1, -0.8, 0.8, 1, 0.8},
description = "Dungeon Guardian",
range = 4,
})
mobs.register_mob("mobs:blue_cube", {
@ -250,7 +250,7 @@ mobs.register_mob("mobs:blue_cube", {
collisionbox = {-0.6, -0.75, -0.6, 0.6, 0.75, 0.6},
description = "Blue Cube",
range = 4,
})
mobs.register_mob("mobs:small_grass_monster", {
@ -269,7 +269,7 @@ mobs.register_mob("mobs:small_grass_monster", {
collisionbox = {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25},
description = "Small Grass Monster",
range = 4,
})
mobs.register_mob("mobs:grass_monster", {
@ -288,7 +288,7 @@ mobs.register_mob("mobs:grass_monster", {
collisionbox = {-0.6, -0.75, -0.6, 0.6, 0.6, 0.6},
description = "Grass Monster",
range = 4,
})
mobs.register_mob("mobs:angry_cloud", {
@ -306,7 +306,7 @@ mobs.register_mob("mobs:angry_cloud", {
collisionbox = {-0.6, -0.25, -0.6, 0.6, 0.25, 0.6},
description = "Angry Cloud",
range = 5,
})
mobs.register_mob("mobs:hedgehog", {
@ -324,7 +324,7 @@ mobs.register_mob("mobs:hedgehog", {
collisionbox = {-0.3, -0.5, -0.3, 0.3, -0.25, 0.3},
description = "Hedgehog",
range = 8,
})
mobs.register_mob("mobs:book", {
@ -380,4 +380,3 @@ mobs.register_mob("mobs:lava_flower", {
range = 2,
drops = {"money:coin 2"}
})

View File

@ -19,7 +19,7 @@ function xp.add_xp(player, num)
xp.player_xp[player:get_player_name()] = num
if not xp.player_levels[player:get_player_name()] then
xp.player_levels[player:get_player_name()] = 1
end
end
end
cmsg.push_message_player(player, "You got "..tostring(num).. " xp!")
@ -71,6 +71,8 @@ minetest.register_on_joinplayer(function(player)
offset = {x=0, y=-(48*2+16)},
})
else
xp.player_xp[player:get_player_name()] = 0
xp.player_levels[player:get_player_name()] = 1
xp.xp_hud[player:get_player_name()] = player:hud_add({
hud_elem_type = "statbar",
position = {x=0.5,y=1.0},
@ -96,7 +98,7 @@ function xp.load_xp()
local str = input:read()
if str then
for k, v in str.gmatch(str,"(%w+)=(%w+)") do
xp.player_xp[k] = tonumber(v)
xp.player_xp[k] = tonumber(v)
end
end
io.close(input)
@ -107,7 +109,7 @@ function xp.save_xp()
if xp.player_xp then
local output = io.open(xp.xp_file, "w")
local str = ""
for k, v in pairs(xp.player_xp) do
for k, v in pairs(xp.player_xp) do
str = str .. k .. "=" .. v .. ","
end
str = str:sub(1, #str - 1)
@ -133,7 +135,7 @@ function xp.save_levels()
if xp.player_xp then
local output = io.open(xp.lvl_file, "w")
local str = ""
for k, v in pairs(xp.player_levels) do
for k, v in pairs(xp.player_levels) do
str = str .. k .. "=" .. v .. ","
end
str = str:sub(1, #str - 1)