Skip to content

Instantly share code, notes, and snippets.

@Nosrick Nosrick/api.lua
Last active Aug 9, 2016

Embed
What would you like to do?
momtest.on_punch_callbacks = {}
function momtest.registerOnPunch(functionToRegister)
--momtest.on_punch_callbacks[#momtest.on_punch_callbacks + 1] = functionToRegister
table.insert(momtest.on_punch_callbacks, functionToRegister)
end
function momtest.on_punch(target, puncher, toolCapabilities, lastPunch)
local damage = 0
if not oldPunch then
local tmp = 0
local armor = target.object:get_armor_groups() or {}
for group,_ in pairs( (toolCapabilities.damage_groups or {}) ) do
tmp = lastPunch / (toolCapabilities.full_punch_interval or 1.4)
if tmp < 0 then
tmp = 0.0
elseif tmp > 1 then
tmp = 1.0
end
damage = damage + (toolCapabilities.damage_groups[group] or 0)
* tmp * ((armor[group] or 0) / 100.0)
end
else
oldPunch(target, puncher, lastPunch, toolCapabilities, direction)
end
local punchTimePercent = math.min(1.0, math.max(0.0, (lastPunch / toolCapabilities.full_punch_interval)))
for key, value in pairs(momtest.on_punch_callbacks) do
damage = damage + value(target, puncher, punchTimePercent, damage)
end
target.object:set_hp(math.max(0.0, target.object:get_hp() - damage))
end
function momtest.setEntityOwner(self, player)
if not player then
return
end
local itemStack = player:get_wielded_item()
if string.find(itemStack:get_name(), "wand") and self.owner == "" then
self.owner = player:get_player_name()
self.following = player
self.order = "follow"
end
end
function momtest.setNodeOwner(pos, player)
if not player then
return
end
local metadata = minetest.get_meta(pos)
local name = player:get_player_name()
metadata:set_string("owner", name)
print("Set node owner to " .. name)
return true
end
function momtest.setFontOwner(pos, player)
if not player then
return
end
local metadata = minetest.get_meta(pos)
local name = player:get_player_name()
if not metadata:get_string("owner") == "" then
print("Node is owned.")
return false
end
if playerHasFont[name] then
if playerHasFont[name] == true then
print("Player already has a node.")
return false
end
end
metadata:set_string("owner", name)
playerHasFont[name] = true
print("Set font owner to " .. name)
return true
end
function table.containsKey(table, element)
for key, value in pairs(table) do
if key == element then
return true
end
end
return false
end
function table.containsValue(table, element)
for key, value in pairs(table) do
if value == element then
return true
end
end
return false
end
function table.count(table)
local count = 0
for _ in pairs(table) do
count = count + 1
end
return count
end
function playereffects.hasEffect(effects, element)
for key, value in pairs(effects) do
if value.effect_type_id == element then
return true
end
end
return false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.