NPC: Fixed bugs around new logs and npc chat functions.
Fixed bug with child texture.
This commit is contained in:
parent
a91160ecc6
commit
caa39d97ab
44
npc.lua
44
npc.lua
@ -49,19 +49,25 @@ npc.log_level = {
|
|||||||
DEBUG = false
|
DEBUG = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
npc.texture_check = {
|
||||||
|
timer = 0,
|
||||||
|
interval = 0
|
||||||
|
}
|
||||||
|
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
-- General functions
|
-- General functions
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
-- Logging
|
-- Logging
|
||||||
function npc.log(level, message)
|
function npc.log(level, message)
|
||||||
if npc.log_level[level] then
|
if npc.log_level[level] then
|
||||||
minetest.log("[advanced_npc] "..type..": "..message)
|
minetest.log("[advanced_npc] "..level..": "..message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- NPC chat
|
-- NPC chat
|
||||||
function npc.chat(npc_name, player_name, message)
|
function npc.chat(npc_name, player_name, message)
|
||||||
minetest.chat_send_player(player_name, npc_name..": "..message)
|
minetest.chat_send_player(player_name, npc_name..": "..message)
|
||||||
|
end
|
||||||
|
|
||||||
-- Gets name of player or NPC
|
-- Gets name of player or NPC
|
||||||
function npc.get_entity_name(entity)
|
function npc.get_entity_name(entity)
|
||||||
@ -123,10 +129,6 @@ local function get_random_texture(sex, age)
|
|||||||
textures = minetest.registered_entities["advanced_npc:npc"].child_texture
|
textures = minetest.registered_entities["advanced_npc:npc"].child_texture
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.log("Textures: "..dump(textures))
|
|
||||||
minetest.log("Sex: "..sex)
|
|
||||||
minetest.log("Age: "..age)
|
|
||||||
|
|
||||||
for i = 1, #textures do
|
for i = 1, #textures do
|
||||||
local current_texture = textures[i][1]
|
local current_texture = textures[i][1]
|
||||||
if (sex == npc.MALE
|
if (sex == npc.MALE
|
||||||
@ -236,8 +238,8 @@ function npc.initialize(entity, pos, is_lua_entity, npc_stats)
|
|||||||
if npc_stats["adult_total"] >= 2 then
|
if npc_stats["adult_total"] >= 2 then
|
||||||
if npc_stats["adult_total"] % 2 == 0
|
if npc_stats["adult_total"] % 2 == 0
|
||||||
and (npc_stats["adult_total"] / 2 > npc_stats["child_total"]) then
|
and (npc_stats["adult_total"] / 2 > npc_stats["child_total"]) then
|
||||||
child_s,child_e = 51, 100
|
child_s,child_e = 26, 100
|
||||||
adult_e = 50
|
adult_e = 25
|
||||||
else
|
else
|
||||||
child_s, child_e = 61, 100
|
child_s, child_e = 61, 100
|
||||||
adult_e = 60
|
adult_e = 60
|
||||||
@ -267,14 +269,16 @@ function npc.initialize(entity, pos, is_lua_entity, npc_stats)
|
|||||||
}
|
}
|
||||||
ent.collisionbox = {-0.10,-0.50,-0.10, 0.10,0.40,0.10}
|
ent.collisionbox = {-0.10,-0.50,-0.10, 0.10,0.40,0.10}
|
||||||
ent.is_child = true
|
ent.is_child = true
|
||||||
|
ent.child = true
|
||||||
end
|
end
|
||||||
-- Set texture accordingly
|
-- Set texture accordingly
|
||||||
local selected_texture = get_random_texture(selected_sex, selected_age)
|
local selected_texture = get_random_texture(selected_sex, selected_age)
|
||||||
--minetest.log("Selected texture: "..dump(selected_texture))
|
--minetest.log("Selected texture: "..dump(selected_texture))
|
||||||
|
-- Store selected texture due to the need to restore it later
|
||||||
|
ent.selected_texture = selected_texture
|
||||||
|
-- Set texture and base texture
|
||||||
ent.textures = {selected_texture}
|
ent.textures = {selected_texture}
|
||||||
if selected_age == npc.age.child then
|
ent.base_texture = {selected_texture}
|
||||||
ent.base_texture = selected_texture
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
-- Get sex based on texture. This is a 50% chance for
|
-- Get sex based on texture. This is a 50% chance for
|
||||||
-- each sex as there's same amount of textures for male and female.
|
-- each sex as there's same amount of textures for male and female.
|
||||||
@ -444,7 +448,9 @@ function npc.initialize(entity, pos, is_lua_entity, npc_stats)
|
|||||||
table.insert(ent.trader_data.custom_trades, offer2)
|
table.insert(ent.trader_data.custom_trades, offer2)
|
||||||
|
|
||||||
--minetest.log(dump(ent))
|
--minetest.log(dump(ent))
|
||||||
npc.log("INFO", "Successfully initialized NPC with name "..dump(ent.npc_name))
|
npc.log("INFO", "Successfully initialized NPC with name "..dump(ent.npc_name)
|
||||||
|
..", sex: "..ent.sex..", is child: "..dump(ent.is_child)
|
||||||
|
..", texture: "..dump(ent.textures))
|
||||||
-- Refreshes entity
|
-- Refreshes entity
|
||||||
ent.object:set_properties(ent)
|
ent.object:set_properties(ent)
|
||||||
end
|
end
|
||||||
@ -968,10 +974,24 @@ mobs:register_mob("advanced_npc:npc", {
|
|||||||
-- favor of a better manual spawning method with customization
|
-- favor of a better manual spawning method with customization
|
||||||
npc.log("WARNING", "Initializing NPC from entity step. This message should only be appearing if an NPC is being spawned from inventory with egg!")
|
npc.log("WARNING", "Initializing NPC from entity step. This message should only be appearing if an NPC is being spawned from inventory with egg!")
|
||||||
npc.initialize(self, self.object:getpos(), true)
|
npc.initialize(self, self.object:getpos(), true)
|
||||||
else
|
|
||||||
self.tamed = false
|
self.tamed = false
|
||||||
self.owner = nil
|
self.owner = nil
|
||||||
|
else
|
||||||
-- NPC is initialized, check other variables
|
-- NPC is initialized, check other variables
|
||||||
|
-- Check child texture issues
|
||||||
|
if self.is_child then
|
||||||
|
npc.texture_check.timer = npc.texture_check.timer + dtime
|
||||||
|
if npc.texture_check.timer > npc.texture_check.interval then
|
||||||
|
-- Reset timer
|
||||||
|
npc.texture_check.timer = 0
|
||||||
|
-- Set correct textures
|
||||||
|
self.texture = {self.selected_texture}
|
||||||
|
self.base_texture = {self.selected_texture}
|
||||||
|
-- Set interval to large interval so this code isn't called frequently
|
||||||
|
npc.texture_check.interval = 60
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Timer function for casual traders to reset their trade offers
|
-- Timer function for casual traders to reset their trade offers
|
||||||
self.trader_data.change_offers_timer = self.trader_data.change_offers_timer + dtime
|
self.trader_data.change_offers_timer = self.trader_data.change_offers_timer + dtime
|
||||||
-- Check if time has come to change offers
|
-- Check if time has come to change offers
|
||||||
|
Loading…
Reference in New Issue
Block a user