2012-09-19 23:30:14 +02:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
-- Mob Framework Mod by Sapier
|
|
|
|
--
|
|
|
|
-- You may copy, use, modify or do nearly anything except removing this
|
|
|
|
-- copyright notice.
|
|
|
|
-- And of course you are NOT allow to pretend you have written it.
|
|
|
|
--
|
|
|
|
--! @file debug.lua
|
|
|
|
--! @brief contains debug functions for mob framework
|
|
|
|
--! @copyright Sapier
|
|
|
|
--! @author Sapier
|
|
|
|
--! @date 2012-08-09
|
|
|
|
--!
|
|
|
|
-- Contact sapier a t gmx net
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
--! @defgroup debug_in_game In game debugging functions
|
|
|
|
--! @brief debugging functions to be called from in game
|
|
|
|
--! @ingroup framework_int
|
|
|
|
--! @{
|
|
|
|
|
2013-01-06 23:25:30 +00:00
|
|
|
mobf_debug = {}
|
2013-01-04 23:49:58 +00:00
|
|
|
|
2012-09-19 23:30:14 +02:00
|
|
|
-------------------------------------------------------------------------------
|
2013-01-04 23:49:58 +00:00
|
|
|
-- name: print_usage(player,command,toadd)
|
2012-09-19 23:30:14 +02:00
|
|
|
--
|
|
|
|
--! @brief send errormessage to player
|
|
|
|
--
|
|
|
|
--! @param player name of player to print usage
|
|
|
|
--! @param command display usage for this command
|
|
|
|
--! @param toadd additional information to transfer to player
|
|
|
|
-------------------------------------------------------------------------------
|
2013-01-06 23:25:30 +00:00
|
|
|
function mobf_debug.print_usage(player, command, toadd)
|
2012-09-19 23:30:14 +02:00
|
|
|
|
|
|
|
if toadd == nil then
|
|
|
|
toadd = ""
|
|
|
|
end
|
|
|
|
|
|
|
|
if command == "spawnmob" then
|
|
|
|
print("CMD: ".. player .."> ".. "Usage: /spawnmob <mobname> <X,Y,Z> " .. toadd)
|
|
|
|
minetest.chat_send_player(player, "Usage: /spawnmob <mobname> <X,Y,Z> " .. toadd)
|
|
|
|
end
|
|
|
|
|
|
|
|
if command == "ukn_mob" then
|
|
|
|
print("CMD: ".. player .."> ".. "Unknown mob name "..toadd)
|
|
|
|
minetest.chat_send_player(player, "Unknown mob name "..toadd)
|
|
|
|
end
|
|
|
|
|
|
|
|
if command == "inv_pos" then
|
|
|
|
print("CMD: ".. player .."> ".. "Invalid position "..toadd)
|
|
|
|
minetest.chat_send_player(player, "Invalid position "..toadd)
|
|
|
|
end
|
|
|
|
|
|
|
|
if command == "mob_spawned" then
|
|
|
|
print("CMD: ".. player .."> ".. "Mob successfully spawned "..toadd)
|
|
|
|
minetest.chat_send_player(player, "Mob successfully spawned "..toadd)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
2013-01-04 23:49:58 +00:00
|
|
|
-- name: spawn_mob(name,param)
|
2012-09-19 23:30:14 +02:00
|
|
|
--
|
|
|
|
--! @brief handle a spawn mob command
|
|
|
|
--
|
|
|
|
--! @param name name of player
|
2013-01-04 23:49:58 +00:00
|
|
|
--! @param param parameters received
|
2012-09-19 23:30:14 +02:00
|
|
|
------------------------------------------------------------------------------
|
2013-01-06 23:25:30 +00:00
|
|
|
function mobf_debug.spawn_mob(name,param)
|
2013-01-04 23:49:58 +00:00
|
|
|
print("name: " .. name .. " param: " .. dump(param))
|
|
|
|
|
|
|
|
local parameters = param:split(" ")
|
|
|
|
|
|
|
|
if #parameters ~= 2 then
|
2013-01-06 23:25:30 +00:00
|
|
|
mobf_debug.print_usage(name,"spawnmob")
|
2013-01-04 23:49:58 +00:00
|
|
|
return
|
2012-09-19 23:30:14 +02:00
|
|
|
end
|
2013-01-04 23:49:58 +00:00
|
|
|
|
|
|
|
local pos_strings = parameters[2]:split(",")
|
|
|
|
|
|
|
|
if #pos_strings ~= 3 then
|
2013-01-06 23:25:30 +00:00
|
|
|
mobf_debug.print_usage(name,"spawmob")
|
2013-01-04 23:49:58 +00:00
|
|
|
return
|
2012-09-19 23:30:14 +02:00
|
|
|
end
|
|
|
|
|
2013-01-04 23:49:58 +00:00
|
|
|
if mobf_is_known_mob(parameters[1]) ~= true then
|
2013-01-06 23:25:30 +00:00
|
|
|
mobf_debug.print_usage(name,"ukn_mob", ">"..parameters[1].."<")
|
2012-09-19 23:30:14 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-01-04 23:49:58 +00:00
|
|
|
local spawnpoint = {
|
|
|
|
x=tonumber(pos_strings[1]),
|
|
|
|
y=tonumber(pos_strings[2]),
|
|
|
|
z=tonumber(pos_strings[3])
|
|
|
|
}
|
2012-09-19 23:30:14 +02:00
|
|
|
|
2013-01-04 23:49:58 +00:00
|
|
|
if spawnpoint.x == nil or
|
|
|
|
spawnpoint.y == nil or
|
|
|
|
spawnpoint.z == nil then
|
2013-01-06 23:25:30 +00:00
|
|
|
mobf_debug.print_usage(name,"spawnmob")
|
2013-01-04 23:49:58 +00:00
|
|
|
return
|
2012-09-19 23:30:14 +02:00
|
|
|
end
|
|
|
|
|
2013-01-06 23:25:30 +00:00
|
|
|
spawning.spawn_and_check(parameters[1],"__default",spawnpoint,"mobf_debug_spawner")
|
2012-09-19 23:30:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
2013-01-04 23:49:58 +00:00
|
|
|
-- name: list_active_mobs(name,param)
|
2012-09-19 23:30:14 +02:00
|
|
|
--
|
|
|
|
--! @brief print list of all current active mobs
|
|
|
|
--
|
|
|
|
--! @param name name of player
|
2013-01-04 23:49:58 +00:00
|
|
|
--! @param param parameters received
|
2012-09-19 23:30:14 +02:00
|
|
|
------------------------------------------------------------------------------
|
2013-01-06 23:25:30 +00:00
|
|
|
function mobf_debug.list_active_mobs(name,param)
|
2012-09-19 23:30:14 +02:00
|
|
|
|
|
|
|
local count = 1
|
|
|
|
for index,value in pairs(minetest.luaentities) do
|
2013-01-19 13:50:54 +00:00
|
|
|
if value.data ~= nil and value.data.name ~= nil then
|
2013-01-04 23:49:58 +00:00
|
|
|
local tosend = count .. ": " .. value.data.name .. " at "
|
|
|
|
.. printpos(value.object:getpos())
|
2012-09-19 23:30:14 +02:00
|
|
|
print(tosend)
|
|
|
|
minetest.chat_send_player(name,tosend)
|
|
|
|
count = count +1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
2013-01-04 23:49:58 +00:00
|
|
|
-- name: add_tools(name,param)
|
2012-09-19 23:30:14 +02:00
|
|
|
--
|
|
|
|
--! @brief add toolset for testing
|
|
|
|
--
|
|
|
|
--! @param name name of player
|
2013-01-04 23:49:58 +00:00
|
|
|
--! @param param parameters received
|
2012-09-19 23:30:14 +02:00
|
|
|
------------------------------------------------------------------------------
|
2013-01-06 23:25:30 +00:00
|
|
|
function mobf_debug.add_tools(name,param)
|
2012-09-19 23:30:14 +02:00
|
|
|
local player = minetest.env:get_player_by_name(name)
|
|
|
|
|
|
|
|
if player ~= nil then
|
|
|
|
player:get_inventory():add_item("main", "animalmaterials:lasso 20")
|
|
|
|
player:get_inventory():add_item("main", "animalmaterials:net 20")
|
|
|
|
player:get_inventory():add_item("main", "animalmaterials:scissors 1")
|
|
|
|
player:get_inventory():add_item("main", "animalmaterials:glass 10")
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
2013-01-04 23:49:58 +00:00
|
|
|
-- name: list_defined_mobs(name,param)
|
2012-09-19 23:30:14 +02:00
|
|
|
--
|
|
|
|
--! @brief list all registred mobs
|
|
|
|
--
|
|
|
|
--! @param name name of player
|
2013-01-04 23:49:58 +00:00
|
|
|
--! @param param parameters received
|
2012-09-19 23:30:14 +02:00
|
|
|
------------------------------------------------------------------------------
|
2013-01-06 23:25:30 +00:00
|
|
|
function mobf_debug.list_defined_mobs(name,param)
|
2012-09-19 23:30:14 +02:00
|
|
|
|
|
|
|
local text = ""
|
2013-01-04 23:49:58 +00:00
|
|
|
for i,val in ipairs(mobf_rtd.registred_mob) do
|
2012-09-19 23:30:14 +02:00
|
|
|
text = text .. val .. " "
|
|
|
|
end
|
|
|
|
minetest.chat_send_player(name, "MOBF: "..text)
|
|
|
|
end
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
2013-01-06 23:25:30 +00:00
|
|
|
-- name: init()
|
2012-09-19 23:30:14 +02:00
|
|
|
--
|
|
|
|
--! @brief initialize debug commands chat handler
|
|
|
|
--
|
|
|
|
------------------------------------------------------------------------------
|
2013-01-06 23:25:30 +00:00
|
|
|
function mobf_debug.init()
|
2013-01-04 23:49:58 +00:00
|
|
|
|
|
|
|
minetest.register_chatcommand("spawnmob",
|
|
|
|
{
|
|
|
|
params = "<name> <pos>",
|
|
|
|
description = "spawn a mob at position" ,
|
|
|
|
privs = {mobfw_admin=true},
|
2013-01-06 23:25:30 +00:00
|
|
|
func = mobf_debug.spawn_mob
|
2013-01-04 23:49:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("listactivemobs",
|
|
|
|
{
|
|
|
|
params = "",
|
|
|
|
description = "list all currently active mobs" ,
|
|
|
|
privs = {mobfw_admin=true},
|
2013-01-06 23:25:30 +00:00
|
|
|
func = mobf_debug.list_active_mobs
|
2013-01-04 23:49:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("listdefinedmobs",
|
|
|
|
{
|
|
|
|
params = "",
|
|
|
|
description = "list all currently defined mobs" ,
|
|
|
|
privs = {mobfw_admin=true},
|
2013-01-06 23:25:30 +00:00
|
|
|
func = mobf_debug.list_defined_mobs
|
2013-01-04 23:49:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("mob_add_tools",
|
|
|
|
{
|
|
|
|
params = "",
|
|
|
|
description = "add some mob specific tools to player" ,
|
|
|
|
privs = {mobfw_admin=true},
|
2013-01-06 23:25:30 +00:00
|
|
|
func = mobf_debug.add_tools
|
2013-01-04 23:49:58 +00:00
|
|
|
})
|
2013-01-19 13:50:54 +00:00
|
|
|
|
|
|
|
minetest.register_chatcommand("mobf_version",
|
|
|
|
{
|
|
|
|
params = "",
|
|
|
|
description = "show mobf version number" ,
|
|
|
|
privs = {mobfw_admin=true},
|
|
|
|
func = function(name,param)
|
|
|
|
minetest.chat_send_player(name,"MOBF version: " .. mobf_version)
|
|
|
|
end
|
|
|
|
})
|
2013-01-04 23:49:58 +00:00
|
|
|
|
|
|
|
if mobf_rtd.luatrace_enabled then
|
|
|
|
minetest.register_chatcommand("traceon",
|
|
|
|
{
|
|
|
|
params = "",
|
|
|
|
description = "start luatrace tracing" ,
|
|
|
|
privs = {mobfw_admin=true},
|
|
|
|
func = luatrace.tron()
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("traceon",
|
|
|
|
{
|
|
|
|
params = "",
|
|
|
|
description = "stop luatrace tracing" ,
|
|
|
|
privs = {mobfw_admin=true},
|
|
|
|
func = luatrace.troff()
|
|
|
|
})
|
|
|
|
end
|
2012-09-19 23:30:14 +02:00
|
|
|
end
|
|
|
|
|
2013-01-03 01:08:23 +00:00
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
-- name: handle_spawnhouse(name,message)
|
|
|
|
--
|
|
|
|
--! @brief spawn small house
|
|
|
|
--
|
2013-01-04 23:49:58 +00:00
|
|
|
--! @param entity entity rightclicked
|
|
|
|
--! @param player player doing rightclick
|
2013-01-03 01:08:23 +00:00
|
|
|
------------------------------------------------------------------------------
|
2013-01-06 23:25:30 +00:00
|
|
|
function mobf_debug.rightclick_callback(entity,player)
|
2013-01-04 23:49:58 +00:00
|
|
|
local lifetime = mobf_get_current_time() - entity.dynamic_data.spawning.original_spawntime
|
|
|
|
print("MOBF: " .. entity.data.name .. " is alive for " .. lifetime .. " seconds")
|
|
|
|
print("MOBF: \tCurrent state: " .. entity.dynamic_data.state.current )
|
|
|
|
print("MOBF: \tCurrent movgen: " .. entity.dynamic_data.current_movement_gen.name )
|
2013-01-25 23:07:21 +00:00
|
|
|
if entity.dynamic_data.current_movement_gen.name == "follow_mov_gen" then
|
|
|
|
local basepos = entity.getbasepos(entity)
|
|
|
|
local targetpos = entity.dynamic_data.spawning.spawnpoint
|
|
|
|
if entity.dynamic_data.movement.guardspawnpoint ~= true then
|
|
|
|
targetpos = entity.dynamic_data.movement.target:getpos()
|
|
|
|
end
|
|
|
|
print("MOBF: \t\tmovement state: " .. mgen_follow.identify_movement_state(basepos,targetpos) )
|
|
|
|
end
|
2013-01-04 23:49:58 +00:00
|
|
|
print("MOBF: \tTime to state change: " .. entity.dynamic_data.state.time_to_next_change .. " seconds")
|
2013-01-19 13:50:54 +00:00
|
|
|
print("MOBF: \tCurrent environmental state: " .. environment.pos_is_ok(entity.getbasepos(entity),entity))
|
2013-01-04 23:49:58 +00:00
|
|
|
print("MOBF: \tCurrent accel: " .. printpos(entity.object:getacceleration()))
|
|
|
|
print("MOBF: \tCurrent speed: " .. printpos(entity.object:getvelocity()))
|
|
|
|
return false
|
2013-01-03 01:08:23 +00:00
|
|
|
end
|
|
|
|
|
2013-01-04 23:49:58 +00:00
|
|
|
|
2012-09-19 23:30:14 +02:00
|
|
|
--!@}
|