get xp from mobs

This commit is contained in:
cale 2016-06-09 18:33:25 +02:00
parent 967b6fedd8
commit 64c3d0a643
3 changed files with 14 additions and 0 deletions

View File

@ -1,2 +1,3 @@
classes
default
xp

View File

@ -27,6 +27,15 @@ function mobs.register_mob(name, def)
speed = 0,
anim = "",
t = 0.0,
on_punch = function(self, player)
if self.object:get_hp() <= 0 then
if player and player:is_player() then
xp.add_xp(player, def.xp or xp.get_xp(def.lvl, 10))
end
end
end,
on_step = function(self, dtime)
self.t = self.t + dtime
if self.t > 1 then

View File

@ -8,6 +8,10 @@ xp.level_hud = {}
xp.xp_file = minetest.get_worldpath() .. "/xp"
xp.lvl_file = minetest.get_worldpath() .. "/levels"
function xp.get_xp(lvl, x)
return (xp.lvl * lvl) / x
end
function xp.add_xp(player, num)
if xp.player_xp[player:get_player_name()] then
xp.player_xp[player:get_player_name()] = xp.player_xp[player:get_player_name()] + num