mirror of
https://github.com/goraph/17rooms.git
synced 2024-05-04 15:08:13 +03:00
42 lines
790 B
Lua
42 lines
790 B
Lua
-- react_ and postreact_ event module for reactions near the object
|
|
|
|
--[[ include 'listen'
|
|
obj {
|
|
nam = 'npc';
|
|
react_Take = "Player in this room is taking something. Reject!";
|
|
}:listen();
|
|
]]--
|
|
|
|
--luacheck: globals mp
|
|
--luacheck: no self
|
|
game.react_list = std.list {}
|
|
|
|
function game:before_Any(ev, ...)
|
|
for _, v in ipairs(game.react_list) do
|
|
if v:inroom() == std.here() then
|
|
local r = mp:runmethods('react', ev, v, ...)
|
|
if r ~= false then
|
|
return
|
|
end
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
|
|
function game:post_Any(ev, ...)
|
|
for _, v in ipairs(game.react_list) do
|
|
if v:inroom() == std.here() then
|
|
local r = mp:runmethods('postreact', ev, v, ...)
|
|
if r ~= false then
|
|
return
|
|
end
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
|
|
function std.obj.listen(s)
|
|
game.react_list:add(s)
|
|
return s
|
|
end
|