Capture player punch() event
I have asked this before but never did get an an answer, I guess that it is probably not possible.
However, I was recently wondering if there might be some kind of metatable trickery I could perform on the player userdata.
I tried the following code but it does not work as I expected
Any suggestions? I am pretty green when it comes to the more advanced Lua features
However, I was recently wondering if there might be some kind of metatable trickery I could perform on the player userdata.
I tried the following code but it does not work as I expected
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local my_player = nil
local player_wrapper = {}
local player_wrapper_mt = {}
function player_wrapper_mt:__index(key)
local proto = rawget(self, "__proto__")
local field = proto and proto[key]
if type(field) ~= "function" then
return field
else
return function (obj, ...)
if obj == self then
return field(proto, ...)
else
return field(obj, ...)
end
end
end
end
function player_wrapper:new(player)
return setmetatable({__proto__ = player}, player_wrapper_mt)
end
function player_wrapper:punch(puncher, time_from_last_punch, tool_capabilities, direction)
print("Player punched!")
end
minetest.register_on_joinplayer(function(player)
my_player = player_wrapper:new(player)
end)
Any suggestions? I am pretty green when it comes to the more advanced Lua features