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

Change broomstick craft

This commit is contained in:
palige 2015-07-08 14:46:40 +02:00 committed by LeMagnesium
parent 2e1803efe0
commit 50d7518038
3 changed files with 108 additions and 49 deletions

View File

@ -1 +1,4 @@
mana
mana
default
mobs
farming

View File

@ -1,9 +1,70 @@
local broomstick_time = 120 -- Seconds (for default 2 minutes)
local broomstick_time = 180 -- Seconds
local broomstick_mana = 210
local broomstick_actual_users = {}
local had_fly_privilege = {}
local privs = {}
-- broomstick file
users_file = minetest.get_worldpath() .. "/broomstick_users.txt"
--load broomstick file
local file = io.open(users_file, "r")
if file then
had_fly_privilege = minetest.deserialize(file:read("*all"))
file:close()
file = nil
if not had_fly_privilege or type(had_fly_privilege) ~= "table" then
had_fly_privilege = {}
end
else
minetest.log("error", "[broomstick] Can not open broomstick_users.txt file !")
end
-- funtion save broomstick file
local function save()
local input = io.open(users_file, "w")
if input then
input:write(minetest.serialize(had_fly_privilege))
input:close()
else
minetest.log("error","[broomstick] Open failed (mode:w) of " .. users_file)
end
end
-- on join_player remove priv fly
minetest.register_on_joinplayer(function(player)
local playername = player:get_player_name()
if had_fly_privilege[playername] ~= nil then
privs = minetest.get_player_privs(playername)
privs.fly = nil
minetest.set_player_privs(playername, privs)
had_fly_privilege[playername] = nil
save()
end
end)
-- Broomstick timer
local function broomstick_end(playername)
minetest.chat_send_player(playername, "WARNING ! You'll fall in 10 seconds !")
minetest.after(10, function(playername)
-- Send a message...
minetest.chat_send_player(playername, "End of broomstick. I hope you're not falling down...")
-- Set player privs...
privs = minetest.get_player_privs(playername)
privs["fly"] = nil
minetest.set_player_privs(playername, privs)
-- Remove the player in the list.
for i = 1, #broomstick_actual_users do
if broomstick_actual_users[i] == playername then
table.remove(broomstick_actual_users, i)
end
end
-- Rewrite the broomstick_users.txt file.
had_fly_privilege[playername] = nil
save()
end, playername)
end
-- Register broomstick
minetest.register_craftitem("broomstick:broomstick", {
description = "Broomstick",
@ -13,8 +74,8 @@ minetest.register_craftitem("broomstick:broomstick", {
local playername = user:get_player_name()
if mana.get(playername) >= broomstick_mana then
local has_already_a_broomstick = false
for _, i in ipairs(broomstick_actual_users) do
if i.name == playername then
for i = 1, #broomstick_actual_users do
if broomstick_actual_users[i] == playername then
has_already_a_broomstick = true
end
end
@ -22,68 +83,42 @@ minetest.register_craftitem("broomstick:broomstick", {
privs = minetest.get_player_privs(playername)
-- Set player privs...
if not privs.fly == true then
-- Rewrite the broomstick_users.txt file.
had_fly_privilege[playername] = true
save()
privs.fly = true
minetest.set_player_privs(playername, privs)
else
minetest.chat_send_player(playername, "You known you " ..
"can fly by yourself, don't you?")
minetest.chat_send_player(playername, "You known you can fly by yourself, don't you?")
return
end
-- Send a message...
minetest.chat_send_player(playername, "You can now fly during "
.. tostring(broomstick_time) .. " seconds.")
minetest.log("action", "Player " .. playername
.." has use a broomstick.")
minetest.chat_send_player(playername, "You can now fly during " .. tostring(broomstick_time) .. " seconds.")
minetest.log("action", "Player " .. playername .. " has use a broomstick.")
-- Subtract mana...
mana.subtract(playername, broomstick_mana)
-- And insert player in the list.
table.insert(broomstick_actual_users, {
name = playername,
time = 0,
is_warning_said = false
})
-- Remove broomstick...
local item_count = user:get_wielded_item():get_count()
return ItemStack("broomstick:broomstick ".. tostring(item_count-1))
-- Insert player in the list.
table.insert(broomstick_actual_users, playername)
-- And add the function in queue
minetest.after(broomstick_time-10, broomstick_end, playername)
-- Remove broomstick.
return ItemStack("")
else
minetest.chat_send_player(playername, "You already have a " ..
"broomstick ! Please wait until the end of your actual " ..
"broomstick.")
minetest.chat_send_player(playername, "You already have a broomstick ! Please wait until the end of your actual broomstick.")
end
else
minetest.chat_send_player(playername, "You must have " ..
tostring(broomstick_mana) .. " of mana to use a broomstick !")
minetest.chat_send_player(playername, "You must have " .. tostring(broomstick_mana) .. " of mana to use a broomstick !")
end
end,
})
-- Broomstick timer
minetest.register_globalstep(function(dtime)
for index, i in ipairs(broomstick_actual_users) do
i.time = i.time + dtime
-- Just a little warning message
if i.time >= broomstick_time - 10 and not i.is_warning_said then
minetest.chat_send_player(i.name,
"WARNING ! You'll fall in 10 seconds !")
i.is_warning_said = true
elseif i.time >= broomstick_time then
-- Send a message...
minetest.chat_send_player(i.name, "End of broomstick. " ..
"I hope you're not falling down...")
-- Set player privs...
privs = minetest.get_player_privs(i.name)
privs["fly"] = nil
minetest.set_player_privs(i.name, privs)
-- And remove the player in the list.
table.remove(broomstick_actual_users, index)
end
end
end)
-- Craft
minetest.register_craft({
output = "broomstick:broomstick",
recipe = {{"default:stick","default:stick","farming:wheat",}},
recipe = {{"","","farming:string",},
{"default:stick","default:stick","mobs:minautor_lots_of_fur",},
{"","","farming:string",},},
})
minetest.log("action", "[OK] broomstick")
minetest.log("info", "[OK] broomstick")

View File

@ -44,6 +44,8 @@ mobs:register_mob("mobs:minotaur", {
chance = 2, min = 1, max = 2,},
{name = "mobs:minotaur_horn",
chance = 4, min = 1, max = 2,},
{name = "mobs:minotaur_fur",
chance = 1, min = 1, max = 3,},
},
water_damage = 1,
lava_damage = 5,
@ -73,3 +75,22 @@ minetest.register_craftitem("mobs:minotaur_horn", {
inventory_image = "mobs_minotaur_horn.png",
groups = {magic = 1},
})
minetest.register_craftitem("mobs:minotaur_fur", {
description = "Minotaur Fur",
inventory_image = "mobs_minotaur_fur.png",
groups = {magic = 1},
})
minetest.register_craftitem("mobs:minautor_lots_of_fur", {
description = "Lot of Minotaur Fur",
inventory_image = "mobs_minautor_lots_of_fur.png",
groups = {magic = 1},
})
minetest.register_craft({
output = "mobs:minautor_lots_of_fur",
recipe = {{"mobs:minautor_fur", "mobs:minautor_fur"},
{"mobs:minautor_fur", "mobs:minautor_fur"},
},
})