mirror of
https://github.com/opentibiabr/canary
synced 2026-08-16 06:26:09 -04:00
35 lines
929 B
Lua
35 lines
929 B
Lua
local creatureEvent = CreatureEvent("ModalWindowHelper")
|
|
|
|
function creatureEvent.onModalWindow(player, modalWindowId, buttonId, choiceId)
|
|
local playerId = player:getId()
|
|
local modalWindows = ModalWindows[playerId]
|
|
if not modalWindows then
|
|
return true
|
|
end
|
|
|
|
local modalWindow = modalWindows[modalWindowId]
|
|
if not modalWindow then
|
|
return true
|
|
end
|
|
|
|
local button = modalWindow.buttons[buttonId] or {}
|
|
local choice = modalWindow.choices[choiceId] or {}
|
|
if button.callback then
|
|
button.callback(player, button, choice)
|
|
elseif choice.callback then
|
|
choice.callback(player, button, choice)
|
|
elseif modalWindow.defaultCallback then
|
|
modalWindow.defaultCallback(player, button, choice)
|
|
end
|
|
|
|
modalWindow.using = modalWindow.using - 1
|
|
if modalWindow.using == 0 then
|
|
modalWindows[modalWindowId] = nil
|
|
if not next(modalWindows) then
|
|
ModalWindows[playerId] = nil
|
|
end
|
|
end
|
|
return true
|
|
end
|
|
|
|
creatureEvent:register()
|