Extra error checking: init.lua
This commit is contained in:
parent
9efa81d1fe
commit
e1e7745a15
2 changed files with 74 additions and 15 deletions
|
@ -219,12 +219,12 @@ minetest.register_node("fun_caves:stone_with_salt", {
|
|||
drawtype = "glasslike",
|
||||
sunlight_propagates = false,
|
||||
is_ground_content = true,
|
||||
groups = {stone=1, crumbly=3},
|
||||
groups = {stone=1, crumbly=3, cracky=3},
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
})
|
||||
newnode = fun_caves.clone_node("fun_caves:stone_with_salt")
|
||||
|
||||
-- salt, radioactive ore
|
||||
newnode = fun_caves.clone_node("fun_caves:stone_with_salt")
|
||||
newnode.description = "Salt With Radioactive Ore"
|
||||
newnode.tiles = {"fun_caves_radioactive_ore.png"}
|
||||
newnode.light_source = 4
|
||||
|
|
85
init.lua
85
init.lua
|
@ -93,7 +93,7 @@ end
|
|||
-- Modify a node to add a group
|
||||
function minetest.add_group(node, groups)
|
||||
local def = minetest.registered_items[node]
|
||||
if not def then
|
||||
if not (node and def and groups and type(groups) == 'table') then
|
||||
return false
|
||||
end
|
||||
local def_groups = def.groups or {}
|
||||
|
@ -109,6 +109,10 @@ function minetest.add_group(node, groups)
|
|||
end
|
||||
|
||||
function fun_caves.clone_node(name)
|
||||
if not (name and type(name) == 'string') then
|
||||
return
|
||||
end
|
||||
|
||||
local node = minetest.registered_nodes[name]
|
||||
local node2 = table.copy(node)
|
||||
return node2
|
||||
|
@ -117,6 +121,10 @@ end
|
|||
|
||||
fun_caves.registered_status = {}
|
||||
function fun_caves.register_status(def)
|
||||
if not (def and fun_caves.registered_status and type(def) == 'table') then
|
||||
return
|
||||
end
|
||||
|
||||
fun_caves.registered_status[def.name] = {
|
||||
remove = def.remove,
|
||||
start = def.start,
|
||||
|
@ -126,6 +134,10 @@ function fun_caves.register_status(def)
|
|||
end
|
||||
|
||||
function fun_caves.set_status(player_name, status, time, param)
|
||||
if not (player_name and type(player_name) == 'string' and status and type(status) == 'string') and fun_caves.db and fun_caves.db.status and fun_caves.db.status[player_name] then
|
||||
return
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
local def = fun_caves.registered_status[status]
|
||||
if not (def and player) then
|
||||
|
@ -137,18 +149,20 @@ function fun_caves.set_status(player_name, status, time, param)
|
|||
end
|
||||
|
||||
if time then
|
||||
param.remove = minetest.get_gametime() + time
|
||||
param.remove = (minetest.get_gametime() or 0) + time
|
||||
end
|
||||
|
||||
if player_name and status and fun_caves.db.status[player_name] then
|
||||
fun_caves.db.status[player_name][status] = param
|
||||
if def.start then
|
||||
def.start(player)
|
||||
end
|
||||
fun_caves.db.status[player_name][status] = param
|
||||
if def.start then
|
||||
def.start(player)
|
||||
end
|
||||
end
|
||||
|
||||
function fun_caves.remove_status(player_name, status)
|
||||
if not (player_name and type(player_name) == 'string' and status and type(status) == 'string') and fun_caves.db and fun_caves.db.status and fun_caves.db.status[player_name] then
|
||||
return
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
local def = fun_caves.registered_status[status]
|
||||
if player and def then
|
||||
|
@ -196,14 +210,22 @@ local hunger_mod = minetest.get_modpath("hunger")
|
|||
fun_caves.hunger_id = {}
|
||||
|
||||
function fun_caves.hunger_change(player, change)
|
||||
if not (player and change and type(change) == 'number') then
|
||||
return
|
||||
end
|
||||
|
||||
local player_name = player:get_player_name()
|
||||
if hunger_mod then
|
||||
if change < 0 then
|
||||
if change < 0 and hunger and hunger.update_hunger and hunger.players then
|
||||
hunger.update_hunger(player, hunger.players[player_name].lvl + change * 4)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if not (fun_caves.db.hunger and fun_caves.hunger_id) then
|
||||
return
|
||||
end
|
||||
|
||||
local hp = player:get_hp()
|
||||
if change < 0 or hp >= 16 then
|
||||
fun_caves.db.hunger[player_name] = math.min(20, math.max(0, fun_caves.db.hunger[player_name] + change))
|
||||
|
@ -217,6 +239,10 @@ end
|
|||
local hunger_hud
|
||||
if not hunger_mod then
|
||||
hunger_hud = function(player)
|
||||
if not (player and fun_caves.db.hunger and fun_caves.hunger_id) then
|
||||
return
|
||||
end
|
||||
|
||||
local player_name = player:get_player_name()
|
||||
|
||||
if not fun_caves.db.hunger[player_name] then
|
||||
|
@ -238,15 +264,27 @@ if not hunger_mod then
|
|||
end
|
||||
|
||||
minetest.register_on_item_eat(function(hp_change, replace_with_item, itemstack, user, pointed_thing)
|
||||
if not (hp_change and type(hp_change) == 'number') then
|
||||
return
|
||||
end
|
||||
|
||||
if hp_change > 0 then
|
||||
fun_caves.hunger_change(user, hp_change)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_dieplayer(function(player)
|
||||
if not (player and fun_caves.db.hunger and fun_caves.hunger_id) then
|
||||
return
|
||||
end
|
||||
|
||||
local player_name = player:get_player_name()
|
||||
local pos = vector.round(player:getpos())
|
||||
|
||||
if not (player_name and pos) then
|
||||
return
|
||||
end
|
||||
|
||||
if not hunger_mod then
|
||||
fun_caves.db.hunger[player_name] = 20
|
||||
player:hud_change(fun_caves.hunger_id[player_name], 'number', 20)
|
||||
|
@ -260,11 +298,18 @@ local armor_mod = minetest.get_modpath("3d_armor")
|
|||
fun_caves.armor_id = {}
|
||||
local armor_hud
|
||||
if armor_mod then
|
||||
fun_caves.display_armor = function(player)
|
||||
fun_caves.display_armor = function()
|
||||
end
|
||||
else
|
||||
armor_hud = function(player)
|
||||
if not (player and fun_caves.armor_id) then
|
||||
return
|
||||
end
|
||||
|
||||
local player_name = player:get_player_name()
|
||||
if not player_name then
|
||||
return
|
||||
end
|
||||
|
||||
local armor_icon = {
|
||||
hud_elem_type = 'image',
|
||||
|
@ -290,9 +335,13 @@ else
|
|||
end
|
||||
|
||||
fun_caves.display_armor = function(player)
|
||||
if not (player and fun_caves.armor_id) then
|
||||
return
|
||||
end
|
||||
|
||||
local player_name = player:get_player_name()
|
||||
local armor = player:get_armor_groups()
|
||||
if not armor or not armor.fleshy then
|
||||
if not (player_name and armor and armor.fleshy) then
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -302,8 +351,16 @@ end
|
|||
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
if not (player and fun_caves.db.status) then
|
||||
return
|
||||
end
|
||||
|
||||
local player_name = player:get_player_name()
|
||||
|
||||
if not player_name then
|
||||
return
|
||||
end
|
||||
|
||||
if not fun_caves.db.status[player_name] then
|
||||
fun_caves.db.status[player_name] = {}
|
||||
end
|
||||
|
@ -321,8 +378,10 @@ minetest.register_on_joinplayer(function(player)
|
|||
local armor = player:get_armor_groups()
|
||||
armor.fleshy = math.min(100, math.max(1, math.ceil(armor.fleshy * factor)))
|
||||
player:set_armor_groups(armor)
|
||||
minetest.after(1, function()
|
||||
fun_caves.display_armor(player)
|
||||
end)
|
||||
if fun_caves.display_armor then
|
||||
minetest.after(1, function()
|
||||
fun_caves.display_armor(player)
|
||||
end)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue