diff options
author | Perttu Ahola <celeron55@gmail.com> | 2011-11-27 19:39:36 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-11-29 19:13:56 +0200 |
commit | 05df2ee8a4fe6bd4fcb1879fd418ef6ad301fcf4 (patch) | |
tree | 65454cde46094339c5a88dfbdb766823d8a09137 /data | |
parent | ab3911ba9eb320b7845f95e294020de4758d3efa (diff) | |
download | minetest-05df2ee8a4fe6bd4fcb1879fd418ef6ad301fcf4.tar.gz minetest-05df2ee8a4fe6bd4fcb1879fd418ef6ad301fcf4.tar.bz2 minetest-05df2ee8a4fe6bd4fcb1879fd418ef6ad301fcf4.zip |
Add chat message callback and send functions
Diffstat (limited to 'data')
-rw-r--r-- | data/builtin.lua | 21 | ||||
-rw-r--r-- | data/mods/default/init.lua | 18 |
2 files changed, 39 insertions, 0 deletions
diff --git a/data/builtin.lua b/data/builtin.lua index 6fd19404e..b1abeb364 100644 --- a/data/builtin.lua +++ b/data/builtin.lua @@ -147,3 +147,24 @@ minetest.register_node("ignore", { air_equivalent = true, }) +-- +-- Chat message processing +-- + +minetest.registered_on_chat_messages = {} + +minetest.on_chat_message = function(name, message) + for i,func in ipairs(minetest.registered_on_chat_messages) do + ate = func(name, message) + if ate then + return true + end + end + return false +end + +minetest.register_on_chat_message = function(func) + table.insert(minetest.registered_on_chat_messages, func) +end + +-- END diff --git a/data/mods/default/init.lua b/data/mods/default/init.lua index ea6bf3da9..537f62e31 100644 --- a/data/mods/default/init.lua +++ b/data/mods/default/init.lua @@ -19,8 +19,11 @@ -- minetest.register_on_newplayer(func(ObjectRef)) -- minetest.register_on_respawnplayer(func(ObjectRef)) -- ^ return true in func to disable regular player placement +-- minetest.register_on_chat_message(func(name, message)) -- minetest.setting_get(name) -- minetest.setting_getbool(name) +-- minetest.chat_send_all(text) +-- minetest.chat_send_player(name, text) -- -- Global objects: -- minetest.env - environment reference @@ -1371,6 +1374,21 @@ end) print("setting max_users = " .. dump(minetest.setting_get("max_users"))) print("setting asdf = " .. dump(minetest.setting_get("asdf"))) +minetest.register_on_chat_message(function(name, message) + print("on_chat_message: name="..dump(name).." message="..dump(message)) + local cmd = "/testcommand" + if message:sub(0, #cmd) == cmd then + print(cmd.." invoked") + return true + end + local cmd = "/help" + if message:sub(0, #cmd) == cmd then + print("script-overridden help command") + minetest.chat_send_all("script-overridden help command") + return true + end +end) + -- -- Done, print some random stuff -- |