1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-19 16:50:31 +01:00

Added plate runes

- Added plate template for runes
 - Added on_punch API's handler's function
 - Added popper rune
This commit is contained in:
LeMagnesium 2015-04-26 15:45:04 +02:00
parent c15196fd0e
commit 22efc57bf1
3 changed files with 98 additions and 5 deletions

View File

@ -30,6 +30,10 @@ runes.functions.register_rune = function(parameters)
tiles = {runedef.img},
groups = {oddly_breakable_by_hand = 2, rune = 1},
after_place_node = function(pos, placer, itemstack, pointed_thing)
if placer and placer:is_player() then
local meta = minetest.get_meta(pos)
meta:set_string("owner",placer:get_player_name())
end
if runes.datas.handlers[runedef.name].on_place then
if mana.get(placer:get_player_name()) >= runedef.needed_mana then
runes.datas.handlers[runedef.name].on_place(pos, placer, itemstack, pointed_thing)
@ -40,13 +44,17 @@ runes.functions.register_rune = function(parameters)
end
end,
can_dig = function(pos, player)
print(runes.datas.handlers[runedef.name].can_dig)
if runes.datas.handlers[runedef.name].can_dig then
return runes.datas.handlers[runedef.name].can_dig(pos, player)
else
return true
end
end,
on_punch = function(pos, node, puncher, pointed_thing)
if runes.datas.handlers[runedef.name].on_punch then
runes.datas.handlers[runedef.name].on_punch(pos, node, puncher, pointed_thing)
end
end,
--[[after_dig_node = function(pos, oldnode, oldmetadata, digger)
--if runes.datas.handlers[runedef.name].can_dig and runes.datas.handlers[runedef.name].can_dig(pos, digger) then
if runes.datas.handlers[runedef.name].on_dig then
@ -62,7 +70,48 @@ runes.functions.register_rune = function(parameters)
})
elseif runedef.type == "plate" then
minetest.register_node("runes:rune_" .. runedef.name, {
description = runedef.desc,
paramtype = "light",
inventory_image = runedef.img,
sunlight_propagates = true,
walkable = false,
tiles = {runedef.img},
groups = {rune = 1, oddly_breakable_by_hand = 2},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, -0.499, 0.5},
}
},
after_place_node = function(pos, placer, itemstack, pointed_thing)
if placer and placer:is_player() then
local meta = minetest.get_meta(pos)
meta:set_string("owner",placer:get_player_name())
end
if runes.datas.handlers[runedef.name].on_place then
if mana.get(placer:get_player_name()) >= runedef.needed_mana then
runes.datas.handlers[runedef.name].on_place(pos, placer, itemstack, pointed_thing)
mana.subtract(placer:get_player_name(),runedef.needed_mana)
else
minetest.chat_send_player(placer:get_player_name(),"Not enough mana (needed : " .. runedef.needed_mana ..")")
end
end
end,
can_dig = function(pos, player)
if runes.datas.handlers[runedef.name].can_dig then
return runes.datas.handlers[runedef.name].can_dig(pos, player)
else
return true
end
end,
on_punch = function(pos, node, puncher, pointed_thing)
if runes.datas.handlers[runedef.name].on_punch then
runes.datas.handlers[runedef.name].on_punch(pos, node, puncher, pointed_thing)
end
end,
})
elseif runedef.type == "craftitem" then
minetest.register_craftitem("runes:rune_" .. runedef.name, {
description = runedef.desc,
@ -74,6 +123,7 @@ runes.functions.register_rune = function(parameters)
if mana.get(user:get_player_name()) >= runedef.needed_mana then
runes.datas.handlers[runedef.name].on_use(itemstack, user, pointed_thing)
mana.subtract(user:get_player_name(),runedef.needed_mana)
user:get_inventory():remove_item("main",{name = runedef.name})
else
minetest.chat_send_player(user:get_player_name(),"Not enough mana (needed : " .. runedef.needed_mana ..")")
end
@ -91,6 +141,7 @@ runes.functions.connect = function(itemname, callback, handler)
place
dig
can_dig
punch
]]
if not runes.datas.items[itemname] then
@ -106,8 +157,10 @@ runes.functions.connect = function(itemname, callback, handler)
runes.datas.handlers[itemname].on_dig = handler
elseif callback == "can_dig" then
runes.datas.handlers[itemname].can_dig = handler
elseif callback == "punch" then
runes.datas.handlers[itemname].on_punch = handler
else
minetest.log("error","[runes] Cannot connect handler at " .. handler .. " to item's " .. itemname .. " unknown " .. callback .. " callback")
minetest.log("error","[runes] Cannot connect handler to item's " .. itemname .. " unknown " .. callback .. " callback")
return
end
end

View File

@ -36,7 +36,6 @@ end
is_owner_online = function(pos)
local meta = minetest.get_meta(pos)
print(meta:get_string("owner"))
if meta:get_string("owner") ~= nil then
return minetest.get_player_by_name(meta:get_string("owner")) ~= nil
else
@ -53,6 +52,14 @@ end
set_manamax = function(itemstack, user, pointed_thing)
if user and user:is_player() then
mana.set(user:get_player_name(),mana.getmax(user:get_player_name()))
if not minetest.get_player_privs(user:get_player_name()).server then
-- Violent reaction if not admin
user:set_hp(1)
user:set_breath(1)
local userpos = user:getpos()
local useritem = user:get_wielded_item()
user:setpos({x=userpos.x+math.random(-50,50),y = userpos.y + math.random(1,20),z = userpos.z + math.random(-50,50)})
end
end
end
@ -65,3 +72,31 @@ runes.functions.connect("gotome","place",add_owner)
runes.functions.connect("gotome","dig",go_to_me)
runes.functions.connect("gotome","can_dig",is_owner_online)
runes.functions.connect("megamana","use",set_manamax)
-- And globalsteps
-- Is in
minetest.register_globalstep(function(dtime)
for _, player in pairs(minetest.get_connected_players()) do
local playerpos = player:getpos()
local underpos = {x=playerpos.x,y=playerpos.y,z=playerpos.z}
local undernode = minetest.get_node(underpos)
local meta = minetest.get_meta(underpos)
local inv = meta:get_inventory()
if undernode.name == "runes:rune_popper" then --and player:get_player_name() ~= meta:get_string("owner") then
if minetest.get_player_by_name(meta:get_string("owner")) and mana.get(meta:get_string("owner")) > 10 then
local thieff = math.random(1,32)
local stolen = player:get_inventory():get_stack("main", thieff)
player:get_inventory():set_stack("main", thieff, nil)
if stolen:get_count() > 0 then
local obj = minetest.add_item({x = underpos.x, y = underpos.y + 2.5, z = underpos.z}, stolen)
if obj then
obj:setvelocity({x = math.random(-5,5), y = math.random(3,5), z = math.random(-5,5)})
end
mana.set(meta:get_string("owner"), mana.get(meta:get_string("owner"))-10)
end
end
end
end
end)

View File

@ -43,7 +43,12 @@ runes.datas.items = {
description = "Mega Mana",
img = "default_diamond.png",
type = "craftitem"
}
},
["popper"] = {
description = "Popper",
img = "default_grass.png",
type = "plate"
},
}
for key, value in pairs(runes.datas.items) do