Skip to content

Commit

Permalink
fixed issue when inventory was full
Browse files Browse the repository at this point in the history
  • Loading branch information
berengma committed Apr 6, 2019
1 parent e102e52 commit c0c18c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
25 changes: 19 additions & 6 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ end
if maxdistance > getsetting then force = true end


local function aviator_remove(pos, player)
local function aviator_remove(pos, player, leave)
local name = player:get_player_name()
if aviation[name] ~= nil then
local items = ItemStack("aviator:aviator 1")
Expand All @@ -28,12 +28,25 @@ local function aviator_remove(pos, player)
local elapsed = ntime:get_elapsed()
local inv = minetest.get_inventory({type="player", name=name})
local privs = minetest.get_player_privs(name)


meta.runtime = -1
items:set_metadata(minetest.serialize(meta))

if not inv:room_for_item("main", items) and not leave then
minetest.chat_send_player(name, core.colorize('#ff0000', ">>> ERROR: could not take aviator, inventory full !"))
player:set_pos(aviation[name])
return
end


if vector.distance(pos, aviation[name]) == 0 then
meta.runtime = timeout - elapsed
items:set_metadata(minetest.serialize(meta))
inv:add_item("main", items)
if inv:room_for_item("main", items) then
inv:add_item("main", items)
else
local dpos = player:get_pos()
minetest.spawn_item(dpos, items)
end
ntime:stop()
if aviator_hud_id[name] then
player:hud_remove(aviator_hud_id[name])
Expand Down Expand Up @@ -223,7 +236,7 @@ minetest.register_on_leaveplayer(function(player)
local privs = minetest.get_player_privs(name)
privs.fly = nil
minetest.set_player_privs(name, privs)
aviator_remove(aviation[name], player)
aviator_remove(aviation[name], player, true)
aviation[name] = nil
end
end)
Expand Down Expand Up @@ -251,7 +264,7 @@ minetest.register_on_shutdown(function()
local privs = minetest.get_player_privs(name)
privs.fly = nil
minetest.set_player_privs(name, privs)
aviator_remove(aviation[name], player)
aviator_remove(aviation[name], player, true)
aviation[name] = nil
end
end
Expand Down
4 changes: 2 additions & 2 deletions mod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ title = Aviator
author = Gundul
description = Adds a craftable node to minetest. You get fly priv 50 nodes around that node
optional_depends = technic,moreores,basic_machines
license = WTFPL
license = LGPL
forum = https://forum.minetest.net/viewtopic.php?f=11&t=16661
version = 1.3
version = 1.4

0 comments on commit c0c18c9

Please sign in to comment.