Fix bug in marriage check for receiving gifts
This commit is contained in:
parent
f53abf7072
commit
47847d2951
37
chat.lua
37
chat.lua
@ -26,6 +26,26 @@
|
||||
|
||||
local options = {"Question 1","Question 2","Question 3","Question 4"}
|
||||
|
||||
npc.dialogue = {}
|
||||
|
||||
npc.dialogue.YES_GIFT_ANSWER_LABEL = "Yes, give wielded item"
|
||||
npc.dialogue.NO_GIFT_ANSWER_LAEBL = "Nevermind"
|
||||
|
||||
-- Yes/No dialogue declaration
|
||||
npc.dialogue.gift_dialogue = smartfs.create("advanced_npc:gift_dialogue", function(state)
|
||||
state:size(7, 2.4)
|
||||
state:button(0.5, 0.7, 6, 0.5, "yes_option", npc.dialogue.YES_GIFT_ANSWER_LABEL)
|
||||
state:button(0.5, 1.4, 6, 0.5, "no_option", npc.dialogue.NO_GIFT_ANSWER_LAEBL, true)
|
||||
|
||||
local dialogue_result
|
||||
state:get("yes_option"):click(function(self, state)
|
||||
dialogue_result = true
|
||||
end)
|
||||
state:get("no_option"):click(function(self, state)
|
||||
dialogue_result = false
|
||||
end)
|
||||
end)
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- Creates a formspec for dialog
|
||||
--------------------------------------------------------------------
|
||||
@ -45,13 +65,16 @@ local function create_formspec(options, close_option)
|
||||
end
|
||||
|
||||
-- New function for getting dialogue formspec
|
||||
local l = smartfs.create("smartfs:load", function(state)
|
||||
state:load(minetest.get_modpath("smartfs").."/docs/example.smartfs")
|
||||
state:get("btn"):click(function(self,state)
|
||||
print("Button clicked!")
|
||||
end)
|
||||
return true
|
||||
end)
|
||||
function npc.dialogue.show_yes_no_dialogue(prompt, player_name)
|
||||
local dialogue_form = npc.dialogue.gift_dialogue
|
||||
|
||||
-- Send prompt message to player
|
||||
minetest.chat_send_player(player_name, prompt)
|
||||
|
||||
dialogue_form:show(player_name)
|
||||
|
||||
return dialogue_result
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- Returns all chatlines for a specific NPC
|
||||
|
2
init.lua
2
init.lua
@ -2,7 +2,7 @@
|
||||
local path = minetest.get_modpath("advanced_npc")
|
||||
|
||||
-- Load SmartFS library by rubenwardy
|
||||
dofile(path .. "lib/smartfs.lua")
|
||||
dofile(path .. "/lib/smartfs.lua")
|
||||
|
||||
-- Intllib
|
||||
local S
|
||||
|
18
npc.lua
18
npc.lua
@ -124,7 +124,7 @@ mobs.npc_drops = {
|
||||
|
||||
-- General functions
|
||||
-- Gets name of player or NPC
|
||||
local function get_entity_name(entity)
|
||||
function npc.get_entity_name(entity)
|
||||
if entity:is_player() then
|
||||
return entity:get_player_name()
|
||||
else
|
||||
@ -314,8 +314,9 @@ end
|
||||
local function check_npc_can_receive_gift(self, clicker_name)
|
||||
for i = 1, #self.relationships do
|
||||
if self.relationships[i].name == clicker_name then
|
||||
-- This checks avoid married NPC to receive from others
|
||||
if clicker_name == self.is_married_to then
|
||||
-- Checks avoid married NPC to receive from others
|
||||
if self.is_married_to == nil
|
||||
or (self.is_married ~= nil and self.is_married_to == clicker_name) then
|
||||
return self.relationships[i].gift_timer_value >= self.relationships[i].gift_interval
|
||||
else
|
||||
return false
|
||||
@ -381,7 +382,7 @@ local function receive_gift(self, clicker)
|
||||
if item:get_name() == "" then return false end
|
||||
|
||||
-- Get clicker name
|
||||
local clicker_name = get_entity_name(clicker)
|
||||
local clicker_name = npc.get_entity_name(clicker)
|
||||
|
||||
-- Create relationship if it doesn't exists
|
||||
if check_relationship_exists(self, clicker_name) == false then
|
||||
@ -517,7 +518,7 @@ end
|
||||
-- Chat functions
|
||||
|
||||
local function start_chat(self, clicker)
|
||||
local name = get_entity_name(clicker)
|
||||
local name = npc.get_entity_name(clicker)
|
||||
-- Married player can tell NPC to follow or to stay at a given place
|
||||
-- TODO: Improve this. There should be a dialogue box for this
|
||||
if self.owner and self.owner == name then
|
||||
@ -600,6 +601,11 @@ mobs:register_mob("advanced_npc:npc", {
|
||||
|
||||
-- Receive gift or start chat
|
||||
if self.can_have_relationship then
|
||||
-- Show dialogue to confirm that player is giving item as gift
|
||||
-- local result = npc.dialogue.show_yes_no_dialogue(
|
||||
-- "Do you want to give your currently wielded item to "..self.nametag.."?",
|
||||
-- name)
|
||||
-- minetest.log("Dialogue outcome: "..dump(result))
|
||||
if receive_gift(self, clicker) == false then
|
||||
start_chat(self, clicker)
|
||||
end
|
||||
@ -615,8 +621,8 @@ mobs:register_mob("advanced_npc:npc", {
|
||||
-- Gift timer check
|
||||
if relationship.gift_timer_value < relationship.gift_interval then
|
||||
relationship.gift_timer_value = relationship.gift_timer_value + dtime
|
||||
-- Relationship decrease timer
|
||||
else
|
||||
-- Relationship decrease timer
|
||||
if relationship.relationship_decrease_timer_value
|
||||
< relationship.relationship_decrease_interval then
|
||||
relationship.relationship_decrease_timer_value =
|
||||
|
Loading…
Reference in New Issue
Block a user