Marriage NPC cannot receive gifts from other NPC/players
This commit is contained in:
parent
39224ed644
commit
6e806d1d5b
30
npc.lua
30
npc.lua
@ -314,7 +314,12 @@ end
|
|||||||
local function check_npc_can_receive_gift(self, clicker_name)
|
local function check_npc_can_receive_gift(self, clicker_name)
|
||||||
for i = 1, #self.relationships do
|
for i = 1, #self.relationships do
|
||||||
if self.relationships[i].name == clicker_name then
|
if self.relationships[i].name == clicker_name then
|
||||||
return self.relationships[i].gift_timer_value >= self.relationships[i].gift_interval
|
-- This checks avoid married NPC to receive from others
|
||||||
|
if clicker_name == self.is_married_to then
|
||||||
|
return self.relationships[i].gift_timer_value >= self.relationships[i].gift_interval
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Not found
|
-- Not found
|
||||||
@ -594,9 +599,13 @@ mobs:register_mob("advanced_npc:npc", {
|
|||||||
minetest.log(dump(self))
|
minetest.log(dump(self))
|
||||||
|
|
||||||
-- Receive gift or start chat
|
-- Receive gift or start chat
|
||||||
if receive_gift(self, clicker) == false then
|
if self.can_have_relationship then
|
||||||
start_chat(self, clicker)
|
if receive_gift(self, clicker) == false then
|
||||||
end
|
start_chat(self, clicker)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
start_chat(self, clicker)
|
||||||
|
end
|
||||||
|
|
||||||
end,
|
end,
|
||||||
do_custom = function(self, dtime)
|
do_custom = function(self, dtime)
|
||||||
@ -640,6 +649,12 @@ local function is_female_texture(textures)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Choose whether NPC can have relationships. Only 30% of NPCs cannot have relationships
|
||||||
|
local function can_have_relationships()
|
||||||
|
local chance = math.random(1,10)
|
||||||
|
return chance > 3
|
||||||
|
end
|
||||||
|
|
||||||
local function npc_spawn(self, pos)
|
local function npc_spawn(self, pos)
|
||||||
minetest.log("Spawning new NPC:")
|
minetest.log("Spawning new NPC:")
|
||||||
local ent = self:get_luaentity()
|
local ent = self:get_luaentity()
|
||||||
@ -660,11 +675,18 @@ local function npc_spawn(self, pos)
|
|||||||
disliked_items = select_random_disliked_items(ent.sex),
|
disliked_items = select_random_disliked_items(ent.sex),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- Flag that determines if NPC can have a relationship
|
||||||
|
ent.can_have_relationship = can_have_relationships()
|
||||||
|
|
||||||
-- Initialize relationships object
|
-- Initialize relationships object
|
||||||
ent.relationships = {}
|
ent.relationships = {}
|
||||||
|
|
||||||
|
-- Determines if NPC is married or not
|
||||||
|
ent.is_married_to = nil
|
||||||
|
|
||||||
minetest.log(dump(ent))
|
minetest.log(dump(ent))
|
||||||
|
|
||||||
|
-- Refreshes entity
|
||||||
ent.object:set_properties(ent)
|
ent.object:set_properties(ent)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user