]> git.lizzy.rs Git - elidragon.git/blob - birthday.lua
Tweaked birthday.lua and other things
[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         if elidragon.get_birthday(player) == os.date("%d/%m") then
45                 minetest.chat_send_all(minetest.colorize("#FF20FF", name .. " has joined the game. Today is their birthday!"))
46                 elidragon.flower_rain(name)
47                 player:hud_add({
48                         hud_elem_type = "text",
49                         position      = {x = 1, y = 0},
50                         offset        = {x = -5, y = 5},
51                         text          = "Happy Birthday!",
52                         alignment     = {x = -1, y = 1},
53                         scale         = {x = 100, y = 100},
54                         number    = 0xFFF40A,
55                 })
56         end
57 end)
58 minetest.register_chatcommand("birthday", {
59         description = "Set your birthday (e.g. 07/09 if your birthday is the seventh of september)",
60         param = "DD/MM",
61         func = function(name, param)
62                 local player = minetest.get_player_by_name(name)
63                 if not player then return false, "You need to be online to use this command." end
64                 elidragon.set_birthday(player, param)
65                 return true, "Birthday set to " .. param
66         end
67 })