Joriku
Working in the mines, need something?
Hi, could not find a thread of it. And I am out of ideas.
So I want the modal window to activate upon an action id pressed. So for this one right here, an action id of 3005 on a lever.
How would I get it to activate upon aid instead of id?
Just changing it to aid does not activate it..
So I want the modal window to activate upon an action id pressed. So for this one right here, an action id of 3005 on a lever.
How would I get it to activate upon aid instead of id?
Just changing it to aid does not activate it..
Lua:
local modal = Action()
local difficultyStorage = {
EASY = 30004,
MEDIUM = 30005,
HARD = 30006,
EXPERT = 30007
}
local itemID = 3005 -- ID of the item that triggers the action, here I'd like it to be aid instead
function modal.onUse(player, item, fromPosition, target, toPosition, isHotkey)
player:registerEvent("selectDifficulty")
local w = ModalWindow(0, "Select Difficulty", "Choose your challenge level:")
w:addChoice(1, "Easy")
w:addChoice(2, "Medium")
w:addChoice(3, "Hard")
w:addChoice(4, "Expert")
w:addButton(1, "Select")
w:addButton(2, "Cancel")
w:setDefaultEnterButton(1)
w:setDefaultEscapeButton(2)
w:sendToPlayer(player)
return true
end
modal:id(itemID)
modal:register()
local difficultyEvent = CreatureEvent("selectDifficulty")
function difficultyEvent.onModalWindow(player, modalWindowId, buttonId, choiceId)
player:unregisterEvent("selectDifficulty")
if buttonId == 1 then -- Player clicked "Select"
local difficulty
local message
local storageKey
if choiceId == 1 then
difficulty = "Easy"
storageKey = difficultyStorage.EASY
message = "You have selected Easy difficulty."
elseif choiceId == 2 then
difficulty = "Medium"
storageKey = difficultyStorage.MEDIUM
message = "You have selected Medium difficulty."
elseif choiceId == 3 then
difficulty = "Hard"
storageKey = difficultyStorage.HARD
message = "You have selected Hard difficulty."
elseif choiceId == 4 then
difficulty = "Expert"
storageKey = difficultyStorage.EXPERT
message = "You have selected Expert difficulty."
else
player:sendTextMessage(MESSAGE_STATUS_WARNING, "Invalid choice.")
return true
end
if player:getStorageValue(storageKey) ~= 1 then
player:setStorageValue(storageKey, 1)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, message)
else
player:sendTextMessage(MESSAGE_STATUS_WARNING, "You have already selected this difficulty.")
end
else -- Player clicked "Cancel" or closed the window
player:sendTextMessage(MESSAGE_STATUS_WARNING, "You have cancelled the selection.")
end
return true
end
difficultyEvent:type("modalwindow")
difficultyEvent:register()