]> git.lizzy.rs Git - elidragon.git/blob - birthday.lua
Merge branch 'master' of https://github.com/EliasFleckenstein03/elidragon
[elidragon.git] / birthday.lua
1 elidragon.savedata.birthday = elidragon.savedata.birthday or {}
2
3 function elidragon.set_birthday(player, birthday)
4         player:get_meta():set_string("elidragon:birthday", birthday)
5 end
6
7 function elidragon.get_birthday(player)
8         local name = player:get_player_name()
9         local birthday = player:get_meta():get_string("elidragon:birthday")
10         if birthday == "" then
11                 birthday = elidragon.savedata.birthday[name]
12                 if birthday then
13                         elidragon.savedata.birthday[name] = nil
14                         elidragon.set_birthday(player, birthday)
15                 end
16         end
17         return birthday
18 end
19
20 function elidragon.flower_rain(name)
21         local player = minetest.get_player_by_name(name)
22         if not player then return end
23         local pos = player:get_pos()
24         minetest.add_particlespawner({
25                 amount = 50,
26                 time = 2,
27                 minpos = vector.add(pos, {x = -1, y = 2, z = -1}),
28                 maxpos = vector.add(pos, {x = 1, y = 3, z = 1}),
29                 minvel = {x=0, y=0, z=0},
30                 maxvel = {x=0, y=0, z=0},
31                 minacc = {x=0, y=-8, z=0},
32                 maxacc = {x=0, y=-8, z=0},
33                 minexptime = 0.7,
34                 maxexptime = 1,
35                 minsize = 5,
36                 maxsize = 10,
37                 collisiondetection = true,
38                 vertical = true,
39                 texture = "flowers_rose.png",
40         })
41         minetest.after(0.5, function() elidragon.flower_rain(name) end)
42 end
43 minetest.register_on_joinplayer(function(player)
44         local name = player:get_player_name()
45         if elidragon.get_birthday(player) == os.date("%d/%m") then
46                 minetest.chat_send_all(minetest.colorize("#FF20FF", name .. " has joined the game. Today is their birthday!"))
47                 elidragon.flower_rain(name)
48                 player:hud_add({
49                         hud_elem_type = "text",
50                         position      = {x = 1, y = 0},
51                         offset        = {x = -5, y = 5},
52                         text          = "Happy Birthday!",
53                         alignment     = {x = -1, y = 1},
54                         scale         = {x = 100, y = 100},
55                         number    = 0xFFF40A,
56                 })
57         end
58 end)
59 minetest.register_chatcommand("birthday", {
60         description = "Set your birthday (e.g. 07/09 if your birthday is the seventh of september)",
61         param = "DD/MM",
62         func = function(name, param)
63                 local player = minetest.get_player_by_name(name)
64                 if not player then return false, "You need to be online to use this command." end
65                 elidragon.set_birthday(player, param)
66                 return true, "Birthday set to " .. param
67         end
68 })