forked from Sokomine/yl_speak_up
added yl_speak_up.log_error_with_position
This commit is contained in:
parent
8aad949ee2
commit
97275128d0
@ -49,6 +49,7 @@ end
|
||||
-- The function is called by
|
||||
-- * yl_speak_up.eval_precondition and
|
||||
-- * yl_speak_up.eval_effect.
|
||||
-- The npc also needs a priv to execute this.
|
||||
yl_speak_up.eval_and_execute_function = function(player, x_v, id_prefix)
|
||||
local pname = player:get_player_name()
|
||||
|
||||
@ -60,14 +61,9 @@ yl_speak_up.eval_and_execute_function = function(player, x_v, id_prefix)
|
||||
|
||||
local code = x_v[ id_prefix.."value" ]
|
||||
if code:byte(1) == 27 then
|
||||
local obj = yl_speak_up.speak_to[pname].obj
|
||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||
local npc = yl_speak_up.get_number_from_id(n_id)
|
||||
if obj:get_luaentity() and tonumber(npc) then
|
||||
minetest.log("error","[MOD] yl_speak_up: NPC with ID n_"..npc.." at position "..minetest.pos_to_string(obj:get_pos(),0).." could not compile the content of "..x_id.." :"..dump(code) .. " because of illegal bytecode for player "..pname)
|
||||
else
|
||||
minetest.log("error","[MOD] yl_speak_up: NPC with ID unknown could not compile the content of "..x_id.." :"..dump(code) .. " for player unknown because of illegal bytecode")
|
||||
end
|
||||
yl_speak_up.log_error_with_position(pname, n_id,
|
||||
"could not compile the content of "..tostring(x_id).." :"..dump(code)..
|
||||
" because of illegal bytecode for player "..tostring(pname))
|
||||
end
|
||||
|
||||
local param = "playername"
|
||||
@ -77,28 +73,18 @@ yl_speak_up.eval_and_execute_function = function(player, x_v, id_prefix)
|
||||
local f, msg = loadstring("return function("..param..") " .. code .. " end")
|
||||
|
||||
if not f then
|
||||
local obj = yl_speak_up.speak_to[pname].obj
|
||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||
local npc = yl_speak_up.get_number_from_id(n_id)
|
||||
if obj:get_luaentity() and tonumber(npc) then
|
||||
minetest.log("error","[MOD] yl_speak_up: NPC with ID n_"..npc.." at position "..minetest.pos_to_string(obj:get_pos(),0).." could not compile the content of "..x_id.." :"..dump(code) .. " for player "..pname)
|
||||
else
|
||||
minetest.log("error","[MOD] yl_speak_up: NPC with ID unknown could not compile the content of "..x_id.." :"..dump(code) .. " for player unknown")
|
||||
end
|
||||
yl_speak_up.log_error_with_position(pname, n_id,
|
||||
"could not compile the content of "..tostring(x_id).." :"..dump(code)..
|
||||
" for player "..tostring(pname))
|
||||
else
|
||||
local func = f()
|
||||
|
||||
local ok, ret = pcall(func,pname)
|
||||
|
||||
if not ok then
|
||||
local obj = yl_speak_up.speak_to[pname].obj
|
||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||
local npc = yl_speak_up.get_number_from_id(n_id)
|
||||
if obj:get_luaentity() and tonumber(npc) then
|
||||
minetest.log("error","[MOD] yl_speak_up: NPC with ID n_"..npc.." at position "..minetest.pos_to_string(obj:get_pos(),0).." could not execute the content of "..x_id.." :"..dump(code) .. " for player "..pname)
|
||||
else
|
||||
minetest.log("error","[MOD] yl_speak_up: NPC with ID unknown could not execute the content of "..x_id.." :"..dump(code) .. " for player unknown")
|
||||
end
|
||||
yl_speak_up.log_error_with_position(pname, n_id,
|
||||
"could not execute the content of "..tostring(x_id).." :"..dump(code)..
|
||||
" for player "..tostring(pname))
|
||||
end
|
||||
|
||||
if type(ret) == "boolean" then
|
||||
|
19
fs_log.lua
19
fs_log.lua
@ -26,7 +26,7 @@ yl_speak_up.log_change = function(pname, n_id, text)
|
||||
log_text = tostring(os.date("%Y-%m-%d %H:%M:%S ")..tostring(pname).." "..text.."\n")
|
||||
-- actually append to the logfile
|
||||
local file, err = io.open(yl_speak_up.worldpath..yl_speak_up.log_path..DIR_DELIM..
|
||||
"log_"..n_id..".txt", "a")
|
||||
"log_"..tostring(n_id)..".txt", "a")
|
||||
if err then
|
||||
minetest.log("[yl_speak_up] Error saving NPC logfile: "..minetest.serialize(err))
|
||||
return
|
||||
@ -34,3 +34,20 @@ yl_speak_up.log_change = function(pname, n_id, text)
|
||||
file:write(log_text)
|
||||
file:close()
|
||||
end
|
||||
|
||||
-- this is used by yl_speak_up.eval_and_execute_function(..) in fs_edit_general.lua
|
||||
yl_speak_up.log_error_with_position = function(pname, n_id, text)
|
||||
if(not(pname) or not(yl_speak_up.speak_to[pname])) then
|
||||
yl_speak_up.log_change(pname, n_id,
|
||||
"error: -npc not found- "..tostring(text))
|
||||
return
|
||||
end
|
||||
local obj = yl_speak_up.speak_to[pname].obj
|
||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||
local pos_str = "-unknown-"
|
||||
if obj:get_luaentity() and tonumber(npc) then
|
||||
pos_str = minetest.pos_to_string(obj:get_pos(),0)
|
||||
end
|
||||
yl_speak_up.log_change(pname, n_id,
|
||||
"error: NPC at position "..pos_str.." "..tostring(text))
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user