I think to make it easier for beginners should add in global.lua this function
By dalkon and me
function doPlayerAddDialog(cid, id, func)
modalWindow = ModalWindow(id, func.title, func.message)
if modalWindow:getId() == id then
for _, v in ipairs(func.buttons) do
modalWindow:doAddButton(v.id, v.text)
end
for _, v in ipairs(func.choices) do
modalWindow:doAddChoice(v.id, v.text)
end
modalWindow:setDefaultEnterButton(func.buttonEnter)
modalWindow:setPriority(func.popup)
modalWindow:setDefaultEscapeButton(func.buttonEscape)
end
modalWindow:sendToPlayer(cid)
return FALSE
end
Exemple script:
modaldialog = {
title = "Offline Training",
message = "Choose your room",
buttons = {
{ id = 1, text = "Go" },
},
buttonEnter = 1,
buttonEscape = 2,
choices = {
{ id = 1, text = "Sword" },
{ id = 2, text = "Axe" },
{ id = 3, text = "Club" },
{ id = 4, text = "Distance" },
{ id = 5, text = "Magic Level" }
},
popup = true
}
function onStepIn(cid, item, position, fromPosition)
doPlayerAddDialog(cid, 1001, modaldialog)
registerCreatureEvent(cid, "ModalOffline")
return true
end
As I said before the "get" function of modals should be removed, it has no utility
Only need "getId()"
Others gets have in onModalWindow
Exemple my script (button 0 and 29 is enter button):
function onModalWindow(cid, modalWindowId, buttonId, choiceId)
if modalWindowId == 1001 then
if buttonId == 1 or buttonId == 29 or buttonId == 0 then
local pos = 0
if (choiceId == 1) then
pos = {x=98, y=45, z=15}
elseif (choiceId == 2) then
pos = {x=108, y=45, z=15}
elseif (choiceId == 3) then
pos = {x=117, y=45, z=15}
elseif (choiceId == 4) then
pos = {x=98, y=55, z=15}
elseif (choiceId == 5) then
pos = {x=117, y=55, z=15}
end
doTeleportThing(cid, pos)
end
end
return true
end
I think to make it easier for beginners should add in global.lua this function
By dalkon and me
Exemple script:
As I said before the "get" function of modals should be removed, it has no utility Only need "getId()" Others gets have in onModalWindow Exemple my script (button 0 and 29 is enter button):