Camas/mods/wielditem/init.lua

71 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(
2015-10-20 19:59:21 +02:00
"wielditem:null",
{
2019-08-29 05:46:44 +02:00
wield_image = "blank.png"
2015-10-20 19:59:21 +02:00
})
minetest.register_entity(
2015-10-20 19:59:21 +02:00
"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
2015-10-20 19:59:21 +02:00
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:get_pos()
2015-10-20 19:59:21 +02:00
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
minetest.register_on_joinplayer(attach_wielditem)
minetest.register_on_leaveplayer(detach_wielditem)
2019-08-29 05:46:44 +02:00
default.log("mod:wielditem", "loaded")