minetest.register_on_joinplayer(function(player)
    local name = player:get_player_name()
    local meta = player:get_meta()
    e = meta:get_int("end")
    if e == 1 then
        minetest.kick_player(name,"The player has win the game in easy difficulty")
    elseif e == 2 then
        minetest.kick_player(name,"The player has win the game in mediun difficulty")
    elseif e == 3 then
        minetest.kick_player(name,"The player has win the game in hard difficulty")
    elseif e == 4 then
        minetest.kick_player(name,"The player has win the game in nightmare difficulty")
    elseif e == 6 then
        minetest.kick_player(name,"The player has lose the game")
    end
    player:hud_set_hotbar_itemcount(2)--`: sets number of items in builtin hotbar    
end)

minetest.register_globalstep(function(dtime)
    for _ , player in pairs(minetest.get_connected_players()) do
        local player_name = player:get_player_name()
        local meta = player:get_meta()
        local m1 = meta:get_int("days")
        local m3 = 1
        local m2 = minetest.get_day_count()
        --minetest.chat_send_player(player_name, player_name..  meta:get_int("days"))
        --minetest.chat_send_player(player_name, "eeeeeeeeeeee"..  meta:get_int("end"))
        --minetest.chat_send_player(player_name, "dddddddddddddd"..  meta:get_int("difficulty"))
        --minetest.chat_send_player(player_name, "2".. minetest.get_day_count())
        if m1 == m2 then
            minetest.chat_send_player(player_name, "33333333")
            local days_text   = "Time completed: " .. m1--minetest.get_day_count()
            player:hud_add({
                 hud_elem_type = "text",
                 position      = {x = 0, y = 0},
                 offset        = {x = 0,   y = 0},
                 text          = days_text,
                 alignment     = {x = 5, y = 6},  -- center aligned
                 scale         = {x = 100, y = 100}, -- covered later
                 size          = {x=5},
            })
            minetest.after(2,function(player)
                d = meta:get_int("difficulty")
                dificultad = "mediun"
                meta:set_int("end",2)
                frase = "Now to rest."
                if d == 3 then
                    meta:set_int("end",3)
                    dificultad = "hard"
                elseif d == 4 then
                    dificultad = "nightmare"
                    meta:set_int("end",4)
                    frase = "You know the meaning of life,universe and everithing else ? ."
                end    
                minetest.kick_player(player_name, 'The player has win the game in ' .. dificultad .. ' difficulty,he has survive '..m1.." days.".. frase)                
            end) 
        end
    end
end
)