Camas/mods/wielditem/init.lua

70 lines
1.6 KiB
Lua
Raw Normal View History

2015-10-20 19:59:21 +02:00
2015-09-01 17:15:24 +02:00
--
-- Wielditem mod
-- By Kaadmy, for Pixture
--
2015-10-20 19:59:21 +02:00
wielditem = {}
2015-09-01 17:15:24 +02:00
local update_time = 1
2015-10-20 19:59:21 +02:00
local timer = 10 -- needs to be more than update_time
minetest.register_craftitem(
"wielditem:null",
{
wield_image = "ui_null.png"
})
minetest.register_entity(
"wielditem:wielditem",
{
textures = {"default:broadsword"},
visual = "wielditem",
visual_size = {x = 0.17, y = 0.17},
collisionbox = {0, 0, 0, 0, 0, 0},
hp_max = 1,
physical = false,
collide_with_objects = false,
makes_footstep_sounds = false,
on_step = function(self, dtime)
local player = self.wielder
if player == nil or (minetest.get_player_by_name(player:get_player_name()) == nil) then
self.object:remove()
return
end
local itemname = player:get_wielded_item():get_name()
if itemname ~= "" then
self.object:set_properties({textures = {itemname}})
else
self.object:set_properties({textures = {"wielditem:null"}})
end
end
})
local function attach_wielditem(player)
local name = player:get_player_name()
local pos = player:getpos()
wielditem[name] = minetest.add_entity(pos, "wielditem:wielditem")
wielditem[name]:set_attach(player, "right_arm", {x = -1.5, y = 5.7, z = 2.5}, {x = 90, y = -45, z = 270})
2015-10-20 19:59:21 +02:00
wielditem[name]:get_luaentity().wielder = player
end
2015-09-01 17:15:24 +02:00
2015-10-20 19:59:21 +02:00
local function detach_wielditem(player)
local name = player:get_player_name()
2015-09-29 22:06:38 +02:00
2015-10-20 19:59:21 +02:00
wielditem[name]:remove()
wielditem[name] = nil
2015-09-01 17:15:24 +02:00
end
2015-10-20 19:59:21 +02:00
minetest.register_on_joinplayer(attach_wielditem)
minetest.register_on_leaveplayer(detach_wielditem)
default.log("mod:wielditem", "loaded")