trade_inv now calls extra functions so that the code can be changed at runtime with npc_talk_reload, too
This commit is contained in:
parent
3104889208
commit
2b58aac1dc
@ -862,29 +862,23 @@ yl_speak_up.get_fs_trade_simple = function(player, trade_id)
|
||||
end
|
||||
|
||||
|
||||
-- create a detached inventory for the *player* for trading with the npcs
|
||||
-- (called in minetest.register_on_joinplayer)
|
||||
yl_speak_up.player_joined_add_trade_inv = function(player, last_login)
|
||||
local pname = player:get_player_name()
|
||||
-- functions for handling the detached trade inventory of players
|
||||
-- these functions exist as extra functions so that they can be changed with /npc_talk_reload
|
||||
|
||||
-- create the detached inventory;
|
||||
-- the functions for monitoring changes will be important later on
|
||||
-- only the the player owning this detached inventory may access it
|
||||
local trade_inv = minetest.create_detached_inventory("yl_speak_up_player_"..tostring(pname), {
|
||||
-- moving of items between diffrent lists is not allowed
|
||||
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
if(not(player) or player:get_player_name() ~= pname) then
|
||||
yl_speak_up.trade_inv_allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
if(not(player)) then
|
||||
return 0
|
||||
end
|
||||
if(from_list ~= to_list) then
|
||||
return 0
|
||||
end
|
||||
return count
|
||||
end,
|
||||
end
|
||||
|
||||
-- these all require calling special functions, depending on context
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
if(not(player) or player:get_player_name() ~= pname) then
|
||||
yl_speak_up.trade_inv_allow_put = function(inv, listname, index, stack, player)
|
||||
if(not(player)) then
|
||||
return 0
|
||||
end
|
||||
-- the "buy" slot is managed by the NPC; the player only takes from it
|
||||
@ -908,9 +902,10 @@ yl_speak_up.player_joined_add_trade_inv = function(player, last_login)
|
||||
end
|
||||
end
|
||||
return stack:get_count()
|
||||
end,
|
||||
allow_take = function(inv, listname, index, stack, player)
|
||||
if(not(player) or player:get_player_name() ~= pname) then
|
||||
end
|
||||
|
||||
yl_speak_up.trade_inv_allow_take = function(inv, listname, index, stack, player)
|
||||
if(not(player)) then
|
||||
return 0
|
||||
end
|
||||
-- can the trade be made?
|
||||
@ -918,10 +913,12 @@ yl_speak_up.player_joined_add_trade_inv = function(player, last_login)
|
||||
return yl_speak_up.can_trade_simple(player, stack:get_count())
|
||||
end
|
||||
return stack:get_count()
|
||||
end,
|
||||
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
end,
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
end
|
||||
|
||||
yl_speak_up.trade_inv_on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
end
|
||||
|
||||
yl_speak_up.trade_inv_on_put = function(inv, listname, index, stack, player)
|
||||
if(listname == "pay") then
|
||||
local pname = player:get_player_name()
|
||||
-- show formspec with updated information (perhaps sale is now possible)
|
||||
@ -931,8 +928,9 @@ yl_speak_up.player_joined_add_trade_inv = function(player, last_login)
|
||||
-- monitor changes in order to adjust the formspec
|
||||
yl_speak_up.action_inv_changed(inv, listname, index, stack, player, "put")
|
||||
end
|
||||
end,
|
||||
on_take = function(inv, listname, index, stack, player)
|
||||
end
|
||||
|
||||
yl_speak_up.trade_inv_on_take = function(inv, listname, index, stack, player)
|
||||
-- the player may have put something wrong in the payment slot
|
||||
-- -> show updated formspec
|
||||
if(listname == "pay") then
|
||||
@ -974,6 +972,37 @@ yl_speak_up.player_joined_add_trade_inv = function(player, last_login)
|
||||
-- monitor changes in order to adjust the formspec
|
||||
yl_speak_up.action_inv_changed(inv, listname, index, stack, player, "take")
|
||||
end
|
||||
end
|
||||
|
||||
-- create a detached inventory for the *player* for trading with the npcs
|
||||
-- (called in minetest.register_on_joinplayer)
|
||||
yl_speak_up.player_joined_add_trade_inv = function(player, last_login)
|
||||
local pname = player:get_player_name()
|
||||
|
||||
-- create the detached inventory;
|
||||
-- the functions for monitoring changes will be important later on
|
||||
-- only the the player owning this detached inventory may access it
|
||||
local trade_inv = minetest.create_detached_inventory("yl_speak_up_player_"..tostring(pname), {
|
||||
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
return yl_speak_up.trade_inv_allow_move(inv, from_list, from_index, to_list,
|
||||
to_index, count, player)
|
||||
end,
|
||||
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
return yl_speak_up.trade_inv_allow_put(inv, listname, index, stack, player)
|
||||
end,
|
||||
allow_take = function(inv, listname, index, stack, player)
|
||||
return yl_speak_up.trade_inv_allow_take(inv, listname, index, stack, player)
|
||||
end,
|
||||
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
return yl_speak_up.trade_inv_on_move(inv, from_list, from_index, to_list,
|
||||
to_index, count, player)
|
||||
end,
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
return yl_speak_up.trade_inv_on_put(inv, listname, index, stack, player)
|
||||
end,
|
||||
on_take = function(inv, listname, index, stack, player)
|
||||
return yl_speak_up.trade_inv_on_take(inv, listname, index, stack, player)
|
||||
end,
|
||||
})
|
||||
-- prepare the actual inventories
|
||||
|
Loading…
Reference in New Issue
Block a user