Merge pull request #35 from rubenwardy/mobs_crash_Fix
Fix mobs crash on no XP found
This commit is contained in:
commit
494b061dbe
@ -8,7 +8,7 @@ end
|
|||||||
|
|
||||||
function mobs.register_mob(name, def)
|
function mobs.register_mob(name, def)
|
||||||
mobs.mobs[#mobs.mobs+1] = {name, def.lvl}
|
mobs.mobs[#mobs.mobs+1] = {name, def.lvl}
|
||||||
|
|
||||||
if not def.hp then
|
if not def.hp then
|
||||||
if def.lvl and def.hits then
|
if def.lvl and def.hits then
|
||||||
def.hp = classes.get_dmg(def.lvl)*def.hits
|
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},
|
visual_size = def.visual_size or {x=1, y=1},
|
||||||
textures = def.textures,
|
textures = def.textures,
|
||||||
spritediv = {x=1, y=1},
|
spritediv = {x=1, y=1},
|
||||||
initial_sprite_basepos = {x=0, y=0},
|
initial_sprite_basepos = {x=0, y=0},
|
||||||
is_visible = true,
|
is_visible = true,
|
||||||
makes_footstep_sound = false,
|
makes_footstep_sound = false,
|
||||||
automatic_rotate = true,
|
automatic_rotate = true,
|
||||||
@ -67,7 +67,7 @@ function mobs.register_mob(name, def)
|
|||||||
self.object:setyaw(yaw)
|
self.object:setyaw(yaw)
|
||||||
|
|
||||||
found = true
|
found = true
|
||||||
obj:punch(self.object, 10, def.dmg, nil)
|
obj:punch(self.object, 10, def.dmg, nil)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -111,7 +111,7 @@ function mobs.register_mob(name, def)
|
|||||||
end
|
end
|
||||||
self.object:setyaw(yaw)
|
self.object:setyaw(yaw)
|
||||||
end
|
end
|
||||||
self.t = 0
|
self.t = 0
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
@ -134,9 +134,9 @@ function mobs.register_mob(name, def)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function mobs.get_mob(lvl)
|
function mobs.get_mob(lvl)
|
||||||
a = {}
|
local a = {}
|
||||||
found_mob = false
|
local found_mob = false
|
||||||
for i,n in ipairs(mobs.mobs) do
|
for i,n in ipairs(mobs.mobs) do
|
||||||
if n[2] < lvl +5 and n[2] > lvl-5 then
|
if n[2] < lvl +5 and n[2] > lvl-5 then
|
||||||
found_mob = true
|
found_mob = true
|
||||||
@ -156,7 +156,7 @@ function mobs.get_mob(lvl)
|
|||||||
a[#a+1] = n[1]
|
a[#a+1] = n[1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if found_mob then
|
if found_mob then
|
||||||
return a[math.random(1, #a)]
|
return a[math.random(1, #a)]
|
||||||
end
|
end
|
||||||
@ -214,7 +214,7 @@ mobs.register_mob("mobs:big_slime", {
|
|||||||
collisionbox = {-0.9, -1, -0.9, 0.9, 1, 0.9},
|
collisionbox = {-0.9, -1, -0.9, 0.9, 1, 0.9},
|
||||||
description = "Big Slime",
|
description = "Big Slime",
|
||||||
range = 3,
|
range = 3,
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
mobs.register_mob("mobs:dungeon_guardian", {
|
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},
|
collisionbox = {-0.8, -1, -0.8, 0.8, 1, 0.8},
|
||||||
description = "Dungeon Guardian",
|
description = "Dungeon Guardian",
|
||||||
range = 4,
|
range = 4,
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
mobs.register_mob("mobs:blue_cube", {
|
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},
|
collisionbox = {-0.6, -0.75, -0.6, 0.6, 0.75, 0.6},
|
||||||
description = "Blue Cube",
|
description = "Blue Cube",
|
||||||
range = 4,
|
range = 4,
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
mobs.register_mob("mobs:small_grass_monster", {
|
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},
|
collisionbox = {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25},
|
||||||
description = "Small Grass Monster",
|
description = "Small Grass Monster",
|
||||||
range = 4,
|
range = 4,
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
mobs.register_mob("mobs:grass_monster", {
|
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},
|
collisionbox = {-0.6, -0.75, -0.6, 0.6, 0.6, 0.6},
|
||||||
description = "Grass Monster",
|
description = "Grass Monster",
|
||||||
range = 4,
|
range = 4,
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
mobs.register_mob("mobs:angry_cloud", {
|
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},
|
collisionbox = {-0.6, -0.25, -0.6, 0.6, 0.25, 0.6},
|
||||||
description = "Angry Cloud",
|
description = "Angry Cloud",
|
||||||
range = 5,
|
range = 5,
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
mobs.register_mob("mobs:hedgehog", {
|
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},
|
collisionbox = {-0.3, -0.5, -0.3, 0.3, -0.25, 0.3},
|
||||||
description = "Hedgehog",
|
description = "Hedgehog",
|
||||||
range = 8,
|
range = 8,
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
mobs.register_mob("mobs:book", {
|
mobs.register_mob("mobs:book", {
|
||||||
@ -380,4 +380,3 @@ mobs.register_mob("mobs:lava_flower", {
|
|||||||
range = 2,
|
range = 2,
|
||||||
drops = {"money:coin 2"}
|
drops = {"money:coin 2"}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ function xp.add_xp(player, num)
|
|||||||
xp.player_xp[player:get_player_name()] = num
|
xp.player_xp[player:get_player_name()] = num
|
||||||
if not xp.player_levels[player:get_player_name()] then
|
if not xp.player_levels[player:get_player_name()] then
|
||||||
xp.player_levels[player:get_player_name()] = 1
|
xp.player_levels[player:get_player_name()] = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
cmsg.push_message_player(player, "You got "..tostring(num).. " xp!")
|
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)},
|
offset = {x=0, y=-(48*2+16)},
|
||||||
})
|
})
|
||||||
else
|
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({
|
xp.xp_hud[player:get_player_name()] = player:hud_add({
|
||||||
hud_elem_type = "statbar",
|
hud_elem_type = "statbar",
|
||||||
position = {x=0.5,y=1.0},
|
position = {x=0.5,y=1.0},
|
||||||
@ -96,7 +98,7 @@ function xp.load_xp()
|
|||||||
local str = input:read()
|
local str = input:read()
|
||||||
if str then
|
if str then
|
||||||
for k, v in str.gmatch(str,"(%w+)=(%w+)") do
|
for k, v in str.gmatch(str,"(%w+)=(%w+)") do
|
||||||
xp.player_xp[k] = tonumber(v)
|
xp.player_xp[k] = tonumber(v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
io.close(input)
|
io.close(input)
|
||||||
@ -107,7 +109,7 @@ function xp.save_xp()
|
|||||||
if xp.player_xp then
|
if xp.player_xp then
|
||||||
local output = io.open(xp.xp_file, "w")
|
local output = io.open(xp.xp_file, "w")
|
||||||
local str = ""
|
local str = ""
|
||||||
for k, v in pairs(xp.player_xp) do
|
for k, v in pairs(xp.player_xp) do
|
||||||
str = str .. k .. "=" .. v .. ","
|
str = str .. k .. "=" .. v .. ","
|
||||||
end
|
end
|
||||||
str = str:sub(1, #str - 1)
|
str = str:sub(1, #str - 1)
|
||||||
@ -133,7 +135,7 @@ function xp.save_levels()
|
|||||||
if xp.player_xp then
|
if xp.player_xp then
|
||||||
local output = io.open(xp.lvl_file, "w")
|
local output = io.open(xp.lvl_file, "w")
|
||||||
local str = ""
|
local str = ""
|
||||||
for k, v in pairs(xp.player_levels) do
|
for k, v in pairs(xp.player_levels) do
|
||||||
str = str .. k .. "=" .. v .. ","
|
str = str .. k .. "=" .. v .. ","
|
||||||
end
|
end
|
||||||
str = str:sub(1, #str - 1)
|
str = str:sub(1, #str - 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user