-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
163 lines (149 loc) · 6.37 KB
/
init.lua
File metadata and controls
163 lines (149 loc) · 6.37 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
wyrda = {}
local modpath = core.get_modpath("wyrda")
local srcpath = modpath .. "/src/"
wyrda.spells = {}
wyrda.register_spell = function(name, def)
wyrda.spells[name] = def
end
wyrda.check_message = function(message)
local words = message:split("[ %-_]+", false, -1, true)
for i, v in pairs(words) do
if wyrda.spells[v] then
return {spell=wyrda.spells[v], words=words, i=i}
end
end
return nil
end
if not core.settings:has("allow_cbv") then
core.settings:set("allow_cbv", "true")
end
core.register_on_chat_message(function(name, message)
if core.settings:get("allow_cbv") == "true" then
local msgparams = wyrda.check_message(message)
local contains = nil
if msgparams ~= nil then contains = msgparams.spell else return false end
local send_msg
if contains ~= nil then
send_msg = wyrda.cast(contains, core.get_player_by_name(name), message, core.get_player_by_name(name):get_pos(), 1)
end
local msg = "<" .. name .. "> "
for i, v in pairs(msgparams.words) do
if i == msgparams.i then
msg = msg .. core.colorize("#88CCFF", msgparams.words[i]) .. " "
else
msg = msg .. msgparams.words[i] .. " "
end
end
if send_msg then minetest.chat_send_all(msg) end
return true
end
end)
wyrda.pointed_to_pos = function(pointed)
if pointed ~= nil then
if pointed.type == "node" then
if pointed.above ~= nil then return pointed.above end
if pointed.under ~= nil then return pointed.under end
elseif pointed.type == "object" then
if pointed.ref ~= nil and pointed.ref:get_pos() ~= nil then return pointed.ref:get_pos() end
end
return vector.new(0, 0, 0)
else
return vector.new(0, 0, 0)
end
end
if not core.settings:has("use_energy") then
core.settings:set("use_energy", "true")
end
if core.settings:get("use_energy") == "true" then
dofile(srcpath .. "/energy.lua")
end
local function take_energy(spell, player, type)
if type == 1 and spell.cost ~= nil then
if wyrda.energy.get_energy(player) > spell.cost then
wyrda.energy.change_energy(player, -spell.cost)
return true
end
elseif type == 2 and spell.cost2 ~= nil then
if wyrda.energy.get_energy(player) > spell.cost2 then
wyrda.energy.change_energy(player, -spell.cost2)
return true
end
end
return false
end
wyrda.cast = function(spell, player, message, pos, type)
if spell == nil then return end
if type == 1 then
if core.settings:get("use_energy") == "true" then
local has_energy = take_energy(spell, player, type)
if has_energy then
core.sound_play("wyrda_cast_spell", {pos = player:get_pos(), gain = 1, pitch = 2, max_hear_distance = 32}, true)
return spell.func(player, message, pos)
end
else
core.sound_play("wyrda_cast_spell", {pos = player:get_pos(), gain = 1, pitch = 2, max_hear_distance = 32}, true)
return spell.func(player, message, pos)
end
elseif type == 2 then
if core.settings:get("use_energy") == "true" then
local has_energy = take_energy(spell, player, type)
if has_energy then
core.sound_play("wyrda_cast_spell", {pos = player:get_pos(), gain = 1, pitch = 1, max_hear_distance = 32}, true)
return spell.func2(player, message, pos)
end
else
core.sound_play("wyrda_cast_spell", {pos = player:get_pos(), gain = 1, pitch = 1, max_hear_distance = 32}, true)
return spell.func2(player, message, pos)
end
end
end
dofile(srcpath .. "/helper.lua")
dofile(srcpath .. "/wands.lua")
dofile(srcpath .. "/inscription.lua")
dofile(srcpath .. "/spells.lua")
dofile(srcpath .. "/books.lua")
dofile(srcpath .. "/spell_gen.lua")
dofile(srcpath .. "/crafting.lua")
dofile(srcpath .. "/nodes.lua")
dofile(srcpath .. "/container.lua")
--dofile(srcpath .. "/mapgen.lua")
local c = core.colorize
core.register_chatcommand("wyrda", {
params = "settings <settings> <value>\n" ..
"settings list\n" ..
"help",
description = "Change Wyrda's settings from console",
privs = {},
func = function(name, param)
local params = param:split(" ")
local privs = core.check_player_privs(name, {server = true})
if params[1] == "settings" then
if privs == true then
local val = params[3]
if params[2] ~= nil then
if params[2] == "list" then
core.chat_send_player(name, c("#8F8", "Wyrda Settings:\n") ..
c("#88F", " allow_singularities") .. " = " .. c("#FF8", "false ") .. c("#AAA", "(whether black holes should be allowed)\n") ..
c("#88F", " singularity_size") .. " = " .. c("#FF8", "50 ") .. c("#AAA", "(size of black holes if allowed)\n") ..
c("#88F", " allow_crafting_wands") .. " = " .. c("#FF8", "true ") .. c("#AAA", "(allow wands to be crafted)\n") ..
c("#88F", " use_energy") .. " = " .. c("#FF8", "true ") .. c("#AAA", "(requires restart for full effect)\n") ..
c("#88F", " allow_cbv") .. " = " .. c("#FF8", "true ") .. c("#AAA", "(Whether to scan chat for Cast by Voice)"))
else
if val ~= nil then core.settings:set(params[2], tostring(val)) end
core.chat_send_player(name, c("#4F8", "[WYRDA] Setting changed: " .. tostring(params[2]) .. " : " .. tostring(val)))
if params[2] == "use_energy" then
core.chat_send_player(name, c("#F00", "[WYRDA] CHANGES REQUIRE RESTART TO TAKE FULL EFFECT!"))
end
end
else
core.chat_send_player(name, c("#F44", "Missing secondary parameter, try 'list' for a list of settings."))
end
else
core.chat_send_player(name, c("#F44", "Denied: Missing required privs (server)"))
end
elseif params[1] == "help" then
core.chat_send_player(name, c("#F44", "[WYRDA] Help menu is disabled"))
return
end
end,
})