From 88f0fa339d4e01489dfc00e8f3eae65cf1a23a08 Mon Sep 17 00:00:00 2001 From: LeMagnesium Date: Mon, 29 Dec 2014 20:19:23 +0100 Subject: [PATCH] =?UTF-8?q?Adding=20fail=20mod=20(I'm=20gonna=20speak=20fr?= =?UTF-8?q?ench=20a=20bit=20there..)=20Je=20propose=20dans=20cette=20pull-?= =?UTF-8?q?request=20un=20mod=20dont=20je=20vous=20ai=20d=C3=A9j=C3=A0=20s?= =?UTF-8?q?=C3=BBrement=20parl=C3=A9,=20le=20mod=20fail.=20Fail=20est=20un?= =?UTF-8?q?=20petit=20mod,=20qui=20n'a=20(pour=20le=20moment)=20pas=20de?= =?UTF-8?q?=20but=20pr=C3=A9cis=20=C3=A0=20part=20l'animation=20et=20le=20?= =?UTF-8?q?fun=20sur=20le=20serveur.=20Le=20mod=20permet=20=C3=A0=20une=20?= =?UTF-8?q?petite=20=C3=A9lite,=20au=20d=C3=A9part,=20de=20cr=C3=A9er=20de?= =?UTF-8?q?s=20failpoints=20et=20des=20cookies=20pour=20les=20donner=20?= =?UTF-8?q?=C3=A0=20des=20joueurs=20qui=20r=C3=A9ussissent=20une=20action?= =?UTF-8?q?=20particuli=C3=A8re,=20ou=20qui=20se=20rattent=20lamentablemen?= =?UTF-8?q?t=20de=20sorte=20que=20ce=20soit=20quelque=20chose=20de=20parti?= =?UTF-8?q?culi=C3=A8rement=20dr=C3=B4le.=20Par=20exemple,=20si=20un=20jou?= =?UTF-8?q?eur=20envoie=20:=20:msg=20Bidule=20J'ai=20trouv=C3=A9=20du=20me?= =?UTF-8?q?se=20vers=20x,y,z=20rien=20que=20pour=20moi=20niark!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Et que tout le monde (IRC compris ici) le voit, c'est un joli failpoint que le joueur recevra au lieu de ses mese diamonds/blocks! Le mod de manière générale sert juste (pour le moment) à mettre un peu plus de fun sur le serveur, mais les autres joueurs semblent l'attendre avec impatience, et si il est intégré, je me chargerai de l'intégrer dans d'autres mods, comme death_messages, pour des morts stupides dans la lave, l'acide, l'eau, etc... Si vous voulez suivre le développement seul du mod il est [ici](http://github.com/LeMagnesium/fail). --- mods/fail/README.md | 9 +++ mods/fail/cookie.lua | 119 ++++++++++++++++++++++++++++++++++++ mods/fail/init.lua | 139 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 267 insertions(+) create mode 100644 mods/fail/README.md create mode 100644 mods/fail/cookie.lua create mode 100644 mods/fail/init.lua diff --git a/mods/fail/README.md b/mods/fail/README.md new file mode 100644 index 00000000..9dfb2b7e --- /dev/null +++ b/mods/fail/README.md @@ -0,0 +1,9 @@ +Minetest Mod Fail +======================== + +Minetest's mod Fail. Based on an idea By Mg (@LeMagnesium). + +Future features : +- Cookies' support +- Create a use for the cookies and the FailPoints +- Create a way to materialize cookies and FailPoints diff --git a/mods/fail/cookie.lua b/mods/fail/cookie.lua new file mode 100644 index 00000000..e8f07295 --- /dev/null +++ b/mods/fail/cookie.lua @@ -0,0 +1,119 @@ +-- Cookies Recipe : + +if not rawget(_G,"data") then + data = {} +end + +data.oven = minetest.get_worldpath().."/cookies" +data.cookies = {} + +-- cookie_baker priv to create cookie +minetest.register_privilege("baker","Is able to bake CooKies and give them to anybody else") + +-- Loading cookies from oven +pntf = io.open(data.oven,"r") +if pntf == nil then + pntf = io.open(data.oven,"w") +else + repeat + local line = pntf:read() + if line == nil or line == "" then break end + --print(line) + data.cookies[line:split(" ")[1]] = line:split(" ")[2]+0 + until 1 == 0 -- Ok, not the best way to create a loop.. +end +minetest.log("action","[FailPoints] CooKies baked") + +-- Global callbacks +minetest.register_on_shutdown(function() + -- Stocking CooKies + pntf = io.open(data.oven,"w") + for i,v in pairs(data.cookies) do + if v ~= 0 then + pntf:write(i.." "..v.."\n") + end + end +end) + +minetest.register_chatcommand("cookie", { + params = " | ", + description = "CooKie baking command", + privs = {shout = true}, + func = function(name, parameters) + local paramlist = parameters:split(" ") + local param = paramlist[1] + local param2 = paramlist[2] + if param == "help" or param == nil then + core.chat_send_player(name,"CooKie recipe's help :") + core.chat_send_player(name,"/cookie | ") + core.chat_send_player(name,"Available subcommands :") + core.chat_send_player(name," - help : show this help") + core.chat_send_player(name," - view | view : View player's CooKies amount") + return + elseif param == "view" then + if param2 == "" or param2 == nil then + local owncookies = 0 + if data.cookies[name] then + owncookies = data.cookies[name] + end + core.chat_send_player(name,"-CK- You own "..owncookies.." CooKies.") + return true + end + + if data.cookies[param2] ~= nil and data.cookies[param2] > 0 then + core.chat_send_player(name,"-CK- Player "..param2.." owns "..data.cookies[param2].." CooKies.") + else + core.chat_send_player(name,"-CK- Player "..param2.." doesn't seem to own any CooKie.") + end + else + + -- If not any known command + if name == param then + if minetest.get_player_privs(name)["baker"] == true then + minetest.log("error",name.." tried to create a CooKie by giving to himself") + core.chat_send_player(name,"-CK- Congratulation, you failed. Don't try to cook for yourself, don't be selfish :p") + else + minetest.log("action",name.."cooked himself a CooKie") + core.chat_send_player(name,"-CK- You failed: It appears the name you entered is yours") + core.chat_send_player(name,"Don't try to cook yourself CooKies, share them :p") + end + return false + end + + if param == "" then + minetest.chat_send_player(name,"-CK- You failed: Not enough parameters given, type /cookie help for help") + return false + end + + if not minetest.get_player_by_name(param) then + core.chat_send_player(name,"-CK- You failed: Sorry, "..param.." isn't online.") + return false + end + + -- Take, or not, cookies from name's account to give them to param + if minetest.get_player_privs(name)["baker"] ~= true then + if data.cookies[name] == nil or data.failpoints[name] == 0 then + core.chat_send_player(name,"You failed: You don't have enough CooKies.. Cook some!") + return false + elseif data.cookies[name] > 0 then + data.cookies[name] = data.cookies[name] -1 + end + else + minetest.log("action","[FailPoints] "..name.." has baked a CooKie.") + end + + -- Give/Add the CooKie to param' account + if data.cookies[param] == nil then + data.cookies[param] = 1 + else + data.cookies[param] = data.cookies[param]+1 + end + + minetest.log("action","[FailPoints] "..name.." has given a CooKie to "..param) + minetest.log("action","[FailPoints] "..param.." now own "..data.cookies[param].."CKs") + minetest.log("action","[FailPoints] "..name.." now own "..(data.cookies[name] or 0).."CKs") + core.chat_send_player(param,"Congratulations "..param..", you get a CooKie.") + core.chat_send_player(name,"CooKie sent.") + end + end +}) diff --git a/mods/fail/init.lua b/mods/fail/init.lua new file mode 100644 index 00000000..bc1a66c1 --- /dev/null +++ b/mods/fail/init.lua @@ -0,0 +1,139 @@ +-- Fails mod By Mg +--[[ + + /-----\-\ + / /--] \-\ + | |-] |-| + \ | /-/ + \-----/-/ + + "Congratulation, you win a failpoint." + +]]-- + +-- The FailPoint mod by Mg. +-- The principal purpose of this mod is to allow FailPoints give, and the storage of them + +local data = {} + +data.fp_file = minetest.get_worldpath().."/failpoints" +data.failpoints = {} +data.fp_version = 0.0 -- It looks like a face, you see? + +-- fp_create priv to create failpoints +minetest.register_privilege("fp_create","Is able to create FailPoints and give them to anybody else") + +-- Loading failpoints +pntf = io.open(data.fp_file,"r") +if pntf == nil then + pntf = io.open(data.fp_file,"w") +else + repeat + local line = pntf:read() + if line == nil or line == "" then break end + --print(line) + data.failpoints[line:split(" ")[1]] = line:split(" ")[2]+0 + until 1 == 0 -- Ok, not the best way to create a loop.. +end +minetest.log("action","[FailPoints] Loaded") + +-- Global callbacks +minetest.register_on_shutdown(function() + -- Saving failpoints + pntf = io.open(data.fp_file,"w") + for i,v in pairs(data.failpoints) do + if v ~= 0 then + pntf:write(i.." "..v.."\n") + end + end +end) + +minetest.register_chatcommand("fail", { + params = " | ", + description = "Fail command", + privs = {shout = true}, + func = function(name, parameters) + local paramlist = parameters:split(" ") + local param = paramlist[1] + local param2 = paramlist[2] + if param == "version" then + core.chat_send_player(name,"-FP- Fail mod version: "..fp_version) + return true + elseif param == "help" or param == nil then + core.chat_send_player(name,"Failpoints available help :") + core.chat_send_player(name,"/fail | ") + core.chat_send_player(name,"Available subcommands :") + core.chat_send_player(name," - help : show this help") + core.chat_send_player(name," - version : show actual fail version") + core.chat_send_player(name," - view | view : View player's failpoints amount") + return + elseif param == "view" then + if param2 == "" or param2 == nil then + local ownfail = 0 + if data.failpoints[name] then + ownfail = data.failpoints[name] + end + core.chat_send_player(name,"-FP- You own "..ownfail.." FailPoints.") + return true + end + + if data.failpoints[param2] ~= nil and data.failpoints[param2] > 0 then + core.chat_send_player(name,"-FP- Player "..param2.." owns "..data.failpoints[param2].." FailPoints.") + else + core.chat_send_player(name,"-FP- Player "..param2.." doesn't seem to own any FailPoint.") + end + else + + -- If not any known command + if name == param then + if minetest.get_player_privs(name)["fp_create"] == true then + minetest.log("error",name.." tried to create a failpoint by giving to himself") + core.chat_send_player(name,"-FP- Congratulation, you failed. Don't try to give to yourself :p") + else + minetest.log("action",name.."gave himself a FailPoint") + core.chat_send_player(name,"-FP- You failed: It appears the name you entered is yours") + core.chat_send_player(name,"Don't try to give yourself failpoints, it's useless :p") + end + return false + end + + if param == "" then + minetest.chat_send_player(name,"-FP- You failed: Not enough parameters given, type /fail help for help") + return false + end + + if not minetest.get_player_by_name(param) then + core.chat_send_player(name,"-FP- You failed: Sorry, "..param.." isn't online.") + return false + end + + -- Take, or not, failpoints from name's account to give them to param + if minetest.get_player_privs(name)["fp_create"] ~= true then + if data.failpoints[name] == nil or data.failpoints[name] == 0 then + core.chat_send_player(name,"You failed: You don't have enough failpoints..") + return false + elseif data.failpoints[name] > 0 then + data.failpoints[name] = data.failpoints[name] -1 + end + else + minetest.log("action","[FailPoints] "..name.." has created a FailPoint.") + end + + -- Give/Add the failpoint to param' account + if data.failpoints[param] == nil then + data.failpoints[param] = 1 + else + data.failpoints[param] = data.failpoints[param]+1 + end + + minetest.log("action","[FailPoints] "..name.." has given a failpoint to "..param) + minetest.log("action","[FailPoints] "..param.." now own "..data.failpoints[param].."FPs") + minetest.log("action","[FailPoints] "..name.." now own "..(data.failpoints[name] or 0).."FPs") + core.chat_send_player(param,"Congratulations "..param..", you win a failpoint.") + core.chat_send_player(name,"FP sent.") + end + end +}) + +-- Create the same things for cookies +dofile(minetest.get_modpath("fail").."/cookie.lua")