1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
ch_core.open_submod("pryc", {data = true, events = true, lib = true, privs = true})
ch_core.register_event_type("pryc", {
description = "pryč od počítače",
access = "discard",
chat_access = "public",
default_text = "{PLAYER} jde pryč od počítače",
})
ch_core.register_event_type("zpet", {
description = "zpět u počítače",
access = "discard",
chat_access = "public",
default_text = "{PLAYER} je zpět u počítače",
})
local empty_table = {}
local disrupt_pryc_silent = function(player, online_charinfo)
if not online_charinfo.pryc then
return false
end
online_charinfo.pryc = nil
local player_name = player:get_player_name()
-- remove HUD
local hud_id = online_charinfo.pryc_hud_id
if hud_id then
online_charinfo.pryc_hud_id = nil
player:hud_remove(hud_id)
end
-- remove titul
ch_core.set_temporary_titul(player_name, "pryč od počítače", false)
return true
end
local disrupt_pryc = function(player, online_charinfo)
if disrupt_pryc_silent(player, online_charinfo) then
-- announce
ch_core.add_event("zpet", nil, online_charinfo.player_name)
return true
else
return false
end
end
function ch_core.je_pryc(player_name)
return ch_core.ifthenelse((ch_data.online_charinfo[player_name] or empty_table).pryc ~= nil, true, false)
end
function ch_core.set_pryc(player_name, options)
local cod = ch_data.online_charinfo[player_name]
if not cod then
minetest.log("error", "Internal error: missing online_charinfo for character '"..player_name.."'!")
return false, "Interní chyba: chybí online_charinfo"
end
local player = minetest.get_player_by_name(player_name)
if not player then
minetest.log("error", "Internal error: missing player ref for character '"..player_name.."'!")
return false, "Interní chyba: chybí PlayerRef"
end
if cod.pryc then
minetest.log("warning", "Character '"..player_name.."' is already away from keyboard!")
return false, "Interní chyba: postava již je pryč od počítače!"
end
if not options then
options = empty_table
end
local no_hud, silently = options.no_hud, options.silently
if silently then
cod.pryc = disrupt_pryc_silent
else
cod.pryc = disrupt_pryc
end
-- HUD
if not no_hud then
local hud_def = {
type = "image",
-- text = "ch_core_white_pixel.png^[invert:rgb^[opacity:192",
text = "ch_core_pryc.png",
position = { x = 0, y = 0 },
scale = { x = -100, y = -100 },
alignment = { x = 1, y = 1 },
offset = { x = 0, y = 0},
}
cod.pryc_hud_id = player:hud_add(hud_def)
end
-- set titul
ch_core.set_temporary_titul(player_name, "pryč od počítače", true)
-- announce
if not silently then
ch_core.add_event("pryc", nil, player_name)
end
return true
end
local def = {
privs = {},
description = "",
func = function(player_name, param)
return ch_core.set_pryc(player_name, empty_table)
end
}
minetest.register_chatcommand("pop", def)
minetest.register_chatcommand("pryč", def)
minetest.register_chatcommand("pryc", def)
ch_core.close_submod("pryc")
|