add basic spacesuit inventory
This commit is contained in:
parent
2ddb09ec8d
commit
89ee53a491
|
@ -7,16 +7,16 @@ spacesuit.air_block = "gas:oxygen"
|
|||
|
||||
--sp manipulation
|
||||
local stack_one_sp = function(inventory)
|
||||
return string.sub(inventory:get_stack("main", 1):get_name(), 1, 12)=="spacesuit:sp"
|
||||
return string.sub(inventory:get_stack("spacesuit", 1):get_name(), 1, 12)=="spacesuit:sp"
|
||||
end
|
||||
|
||||
local set_wear_sp = function(inventory, wear)
|
||||
local name = inventory:get_stack("main", 1):get_name()
|
||||
inventory:set_stack("main", 1,ItemStack({name=name,wear=wear}))
|
||||
local name = inventory:get_stack("spacesuit", 1):get_name()
|
||||
inventory:set_stack("spacesuit", 1,ItemStack({name=name,wear=wear}))
|
||||
end
|
||||
|
||||
local player_get_sp = function(inventory)
|
||||
return spacesuit.registered_spacesuits[inventory:get_stack("main", 1):get_name()]
|
||||
return spacesuit.registered_spacesuits[inventory:get_stack("spacesuit", 1):get_name()]
|
||||
end
|
||||
|
||||
--skin
|
||||
|
@ -68,7 +68,7 @@ minetest.register_node("spacesuit:air_gasbottle", {
|
|||
end
|
||||
if gas.add_concentration(pos, "gas:oxygen", 64) ~= -1 then
|
||||
itemstack:set_count(itemstack:get_count()-1)
|
||||
user:get_inventory():add_item("main", "spacesuit:air_gasbottle_empty")
|
||||
user:get_inventory():add_item("spacesuit", "spacesuit:air_gasbottle_empty")
|
||||
return itemstack
|
||||
end
|
||||
end,
|
||||
|
@ -97,7 +97,7 @@ minetest.register_node("spacesuit:air_gasbottle_empty", {
|
|||
if current_value > 65 then
|
||||
meta:set_int("gas:concentration", 1)
|
||||
itemstack:set_count(itemstack:get_count()-1)
|
||||
user:get_inventory():add_item("main", "spacesuit:air_gasbottle")
|
||||
user:get_inventory():add_item("spacesuit", "spacesuit:air_gasbottle")
|
||||
minetest.chat_send_player(user:get_player_name(), "oxygen-bottle refilled!")
|
||||
return itemstack
|
||||
else
|
||||
|
@ -162,7 +162,7 @@ minetest.register_globalstep(function(dtime)
|
|||
local inv=player:get_inventory()
|
||||
|
||||
if stack_one_sp(inv) then
|
||||
local wear = inv:get_stack("main", 1):get_wear()
|
||||
local wear = inv:get_stack("spacesuit", 1):get_wear()
|
||||
if n == spacesuit.air_block then
|
||||
local new_wear = wear-(65534/20)
|
||||
if new_wear < 0 then new_wear = 0 end
|
||||
|
@ -175,15 +175,15 @@ minetest.register_globalstep(function(dtime)
|
|||
player:set_breath(11)
|
||||
else
|
||||
local bottle = {name="spacesuit:air_gasbottle", count=1, wear=0, metadata=""}
|
||||
print('bottle', inv:contains_item("main", bottle))
|
||||
if inv:contains_item("main", bottle) then
|
||||
local removed = inv:remove_item("main", bottle)
|
||||
print('bottle', inv:contains_item("spacesuit", bottle))
|
||||
if inv:contains_item("spacesuit", bottle) then
|
||||
local removed = inv:remove_item("spacesuit", bottle)
|
||||
set_wear_sp(inv, 0)
|
||||
removed:set_name(removed:get_name() .. "_empty")
|
||||
inv:add_item("main", removed)
|
||||
inv:add_item("spacesuit", removed)
|
||||
minetest.sound_play("marssurvive_pff", {pos=pos, gain = 1, max_hear_distance = 8,})
|
||||
|
||||
if inv:contains_item("main", bottle) then --have one or more bottles
|
||||
if inv:contains_item("spacesuit", bottle) then --have one or more bottles
|
||||
minetest.chat_send_player(player:get_player_name(), "Warning: one more air-gasbottle is empty!")
|
||||
else
|
||||
minetest.chat_send_player(player:get_player_name(), "Warning: have none air-gssbottle left!")
|
||||
|
@ -218,4 +218,6 @@ minetest.register_on_leaveplayer(function(player)
|
|||
spacesuit.skin[player:get_player_name()]=nil
|
||||
end)
|
||||
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/inventory.lua")
|
||||
|
||||
minetest.log("[MOD] spacesuit loaded")
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
minetest.register_on_joinplayer(function(player)
|
||||
player:get_inventory():set_size("spacesuit", 3)
|
||||
end)
|
||||
|
||||
|
||||
sfinv.register_page("spacesuit:spacesuit", {
|
||||
title = "Spacesuit",
|
||||
get = function(self, player, context)
|
||||
return sfinv.make_formspec(player, context, [[
|
||||
list[current_player;spacesuit;0,0;3,1]
|
||||
image[0,0;1,1;spacesuit_sp_black_inv.png^[colorize:#CCCCCC99]
|
||||
image[1,0;1,1;gasbottle.png^[colorize:#CCCCCC44]
|
||||
image[2,0;1,1;gasbottle.png^[colorize:#CCCCCC44]
|
||||
listring[current_player;main]
|
||||
]], true)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_allow_player_inventory_action(function(player, action, inventory, inventory_info)
|
||||
local inv = player:get_inventory()
|
||||
|
||||
if not inventory:get_location().name
|
||||
or inventory:get_location().name ~= player:get_player_name()
|
||||
then return 0
|
||||
end
|
||||
|
||||
if action == "put" then end
|
||||
print("action")
|
||||
end)
|
||||
|
Loading…
Reference in New Issue