mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-24 17:50:37 +01:00
Change broomstick craft
This commit is contained in:
parent
2e1803efe0
commit
50d7518038
@ -1 +1,4 @@
|
|||||||
mana
|
mana
|
||||||
|
default
|
||||||
|
mobs
|
||||||
|
farming
|
@ -1,9 +1,70 @@
|
|||||||
local broomstick_time = 120 -- Seconds (for default 2 minutes)
|
local broomstick_time = 180 -- Seconds
|
||||||
local broomstick_mana = 210
|
local broomstick_mana = 210
|
||||||
local broomstick_actual_users = {}
|
local broomstick_actual_users = {}
|
||||||
local had_fly_privilege = {}
|
local had_fly_privilege = {}
|
||||||
local privs = {}
|
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
|
-- Register broomstick
|
||||||
minetest.register_craftitem("broomstick:broomstick", {
|
minetest.register_craftitem("broomstick:broomstick", {
|
||||||
description = "Broomstick",
|
description = "Broomstick",
|
||||||
@ -13,8 +74,8 @@ minetest.register_craftitem("broomstick:broomstick", {
|
|||||||
local playername = user:get_player_name()
|
local playername = user:get_player_name()
|
||||||
if mana.get(playername) >= broomstick_mana then
|
if mana.get(playername) >= broomstick_mana then
|
||||||
local has_already_a_broomstick = false
|
local has_already_a_broomstick = false
|
||||||
for _, i in ipairs(broomstick_actual_users) do
|
for i = 1, #broomstick_actual_users do
|
||||||
if i.name == playername then
|
if broomstick_actual_users[i] == playername then
|
||||||
has_already_a_broomstick = true
|
has_already_a_broomstick = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -22,68 +83,42 @@ minetest.register_craftitem("broomstick:broomstick", {
|
|||||||
privs = minetest.get_player_privs(playername)
|
privs = minetest.get_player_privs(playername)
|
||||||
-- Set player privs...
|
-- Set player privs...
|
||||||
if not privs.fly == true then
|
if not privs.fly == true then
|
||||||
|
-- Rewrite the broomstick_users.txt file.
|
||||||
|
had_fly_privilege[playername] = true
|
||||||
|
save()
|
||||||
privs.fly = true
|
privs.fly = true
|
||||||
minetest.set_player_privs(playername, privs)
|
minetest.set_player_privs(playername, privs)
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(playername, "You known you " ..
|
minetest.chat_send_player(playername, "You known you can fly by yourself, don't you?")
|
||||||
"can fly by yourself, don't you?")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- Send a message...
|
-- Send a message...
|
||||||
minetest.chat_send_player(playername, "You can now fly during "
|
minetest.chat_send_player(playername, "You can now fly during " .. tostring(broomstick_time) .. " seconds.")
|
||||||
.. tostring(broomstick_time) .. " seconds.")
|
minetest.log("action", "Player " .. playername .. " has use a broomstick.")
|
||||||
minetest.log("action", "Player " .. playername
|
|
||||||
.." has use a broomstick.")
|
|
||||||
-- Subtract mana...
|
-- Subtract mana...
|
||||||
mana.subtract(playername, broomstick_mana)
|
mana.subtract(playername, broomstick_mana)
|
||||||
-- And insert player in the list.
|
-- Insert player in the list.
|
||||||
table.insert(broomstick_actual_users, {
|
table.insert(broomstick_actual_users, playername)
|
||||||
name = playername,
|
-- And add the function in queue
|
||||||
time = 0,
|
minetest.after(broomstick_time-10, broomstick_end, playername)
|
||||||
is_warning_said = false
|
-- Remove broomstick.
|
||||||
})
|
return ItemStack("")
|
||||||
-- Remove broomstick...
|
|
||||||
local item_count = user:get_wielded_item():get_count()
|
|
||||||
return ItemStack("broomstick:broomstick ".. tostring(item_count-1))
|
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(playername, "You already have a " ..
|
minetest.chat_send_player(playername, "You already have a broomstick ! Please wait until the end of your actual broomstick.")
|
||||||
"broomstick ! Please wait until the end of your actual " ..
|
|
||||||
"broomstick.")
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(playername, "You must have " ..
|
minetest.chat_send_player(playername, "You must have " .. tostring(broomstick_mana) .. " of mana to use a broomstick !")
|
||||||
tostring(broomstick_mana) .. " of mana to use a broomstick !")
|
|
||||||
end
|
end
|
||||||
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
|
-- Craft
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "broomstick:broomstick",
|
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")
|
||||||
|
@ -44,6 +44,8 @@ mobs:register_mob("mobs:minotaur", {
|
|||||||
chance = 2, min = 1, max = 2,},
|
chance = 2, min = 1, max = 2,},
|
||||||
{name = "mobs:minotaur_horn",
|
{name = "mobs:minotaur_horn",
|
||||||
chance = 4, min = 1, max = 2,},
|
chance = 4, min = 1, max = 2,},
|
||||||
|
{name = "mobs:minotaur_fur",
|
||||||
|
chance = 1, min = 1, max = 3,},
|
||||||
},
|
},
|
||||||
water_damage = 1,
|
water_damage = 1,
|
||||||
lava_damage = 5,
|
lava_damage = 5,
|
||||||
@ -73,3 +75,22 @@ minetest.register_craftitem("mobs:minotaur_horn", {
|
|||||||
inventory_image = "mobs_minotaur_horn.png",
|
inventory_image = "mobs_minotaur_horn.png",
|
||||||
groups = {magic = 1},
|
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"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user