falling_light/petting/mobtamer.lua

86 lines
2.3 KiB
Lua
Raw Normal View History

2016-08-25 16:26:52 +01:00
minetest.register_tool("petting:mobtamer", {
2016-11-09 17:58:16 +00:00
description = "Mob Converter (place mob egg to the left of this item)",
inventory_image = "petting_mobtamer.png",
wield_image = "petting_mobtamer.png",
range = 10,
2016-08-20 12:00:21 +01:00
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
local maxuses = 30
local pos = {}
if pointed_thing.type ~= "node" then
pos = user:getpos()
2016-09-19 22:41:14 +01:00
local airnodes = minetest.find_nodes_in_area(
{x = pos.x -1, y = pos.y - 1, z = pos.z -1},
{x = pos.x +1, y = pos.y + 1, z = pos.z +1},
{"air","default:water_source","default:river_water_source"}
)
pos = airnodes[math.random(1,#airnodes)]
else
pos = pointed_thing.under
2016-09-29 22:29:07 +01:00
pos = {x=pos.x,y=pos.y+1,z=pos.z}
end
2016-08-20 12:00:21 +01:00
-- here get the mob to the left
local inventory = user:get_inventory()
2016-09-01 13:43:26 +01:00
local eggname = nil
2016-08-20 12:00:21 +01:00
for idx,x in pairs(inventory:get_list("main") ) do
2016-08-25 16:26:52 +01:00
if x:get_name() == "petting:mobtamer" then
2016-08-20 12:00:21 +01:00
break
end
eggname = x:get_name()
end
2016-09-01 13:43:26 +01:00
if eggname == nil then
minetest.chat_send_player(user:get_player_name(), ".... what. Report Mob Tamer failure to DuCake with screenshot of your inventory.")
return
end
if eggname:sub(1,1) == ":" then
minetest.chat_send_player(user:get_player_name(), "Your monster is ill-defined. Please let DuCake know")
return
end
2016-08-20 12:00:21 +01:00
local luaobj = minetest.add_entity(pos,eggname )
local luae = luaobj:get_luaentity()
if luae then
inventory:remove_item("main", eggname)
luae.type="npc"
luae.attacks_monsters=true
2016-08-25 23:20:35 +01:00
luae.state="stand"
2016-08-20 12:04:28 +01:00
luae.owner = user:get_player_name()
2016-08-20 12:14:28 +01:00
luae.tamed = true
2016-08-20 13:51:58 +01:00
luae.health = luae.hp_max
2016-09-19 22:41:14 +01:00
if luae.attack_type == nil then luae.attack_type = "dogfight" end
luae.runaway = false
2016-09-19 22:44:36 +01:00
luae.armor = math.ceil(luae.armor * 0.9)
2016-09-19 22:41:14 +01:00
local o_wv = luae.walk_velocity or 0
local o_rv = luae.run_velocity or 0
2016-09-19 22:44:36 +01:00
luae.walk_velocity = math.ceil(o_wv * 1.1)
luae.run_velocity = math.ceil(o_rv * 1.1)
2016-08-25 22:49:56 +01:00
vivarium:bomf(pos,2 )
2016-08-20 12:00:21 +01:00
else
luaobj:remove()
minetest.chat_send_player(user:get_player_name(),"Not a mob!")
end
2016-09-19 22:44:36 +01:00
if not minetest.check_player_privs(user:get_player_name(), {give=true}) then
itemstack:add_wear(math.ceil(65536/maxuses))
end
2016-08-20 12:00:21 +01:00
return itemstack
end,
})
minetest.register_craft({
2016-08-25 16:26:52 +01:00
output = "petting:mobtamer",
2016-08-20 12:00:21 +01:00
recipe = {
{"mobs:leather","mobs:magic_lasso","mobs:leather"},
{"mobs:nametag","mobs:nametag","mobs:nametag"}
}
})