• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

RevScripts Modal window using aid?

Joriku

Working in the mines, need something?
Joined
Jul 16, 2016
Messages
1,097
Solutions
15
Reaction score
384
Location
Sweden
YouTube
Joriku
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..

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()
 
Replace id with aid.
Replace this line:
Lua:
modal:id(itemID)
with:
Lua:
modal:aid(1234)
So from this, as mentioned. Chaning 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
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:aid(3006)
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()

So aid 3006

1715694285594.png1715694298217.png
 
adding on, there is a slightly outdated wiki page for revscripts, which shows 99% of the stuff you can register


So from this, as mentioned. Chaning 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
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:aid(3006)
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()

So aid 3006

View attachment 84659View attachment 84660

Can you add a print into the first line of onUse, to verify it's being triggered?
 
adding on, there is a slightly outdated wiki page for revscripts, which shows 99% of the stuff you can register




Can you add a print into the first line of onUse, to verify it's being triggered?
So, not sure. Changing it to an aid returns this
2024-05-14 13:58:39 - [2024-14-05 13:58:39.574] [error] /home/fignittytest/canary-main/data-otservbr-global/scripts/actions/3k_dungeons.lua
2024-05-14 13:58:39 - [2024-14-05 13:58:39.574] [error] ...ain/data-otservbr-global/scripts/actions/3k_dungeons.lua:25: '=' expected near 'end'

Though, using an id works alright on an item.

So this is the original part where I went from, works with id, aid returns the same error

Lua:
local modal = Action()
function modal.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    player:registerEvent("modal")
    local w = ModalWindow(0, "title")
    w:addChoice(1, "choice name")
    w:addButton(0, "Select")
    w:addButton(1, "Cancel")
    w:setDefaultEnterButton(0)
    w:setDefaultEscapeButton(1)
    w:sendToPlayer(player)
    return true
end
modal:id(xxxx)
modal:register()
local modal = CreatureEvent("modal")
function modal.onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("modal")
    if buttonId == 0 then
        something
    end
    return true
end
modal:type("modalwindow")
modal:register()

It does not activate upon prints due to the error
 
Last edited:
So, not sure. Changing it to an aid returns this
2024-05-14 13:58:39 - [2024-14-05 13:58:39.574] [error] /home/fignittytest/canary-main/data-otservbr-global/scripts/actions/3k_dungeons.lua
2024-05-14 13:58:39 - [2024-14-05 13:58:39.574] [error] ...ain/data-otservbr-global/scripts/actions/3k_dungeons.lua:25: '=' expected near 'end'

Though, using an id works alright on an item.
uhh, can you try a super simple test script, like.. below, to see that it works?
Cuz I'm not seeing anything obvious in the code that would account for that error

Lua:
local test = Action()

function test.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    print("actionId trigger is working.")
    return true
end

test:aid(3006)
test:register()
 
this line just change.
Lua:
local itemID = 3005 -- ID of the item that triggers the action, here I'd like it to be aid instead
for
Lua:
local aid = 3005 -- ID of the item that triggers the action, here I'd like it to be aid instead

this line just change.
Lua:
modal:aid(3006)
for
Lua:
modal:aid(aid)

The script is up to date, tested, and functional!
Lua:
local modal = Action()
local difficultyStorage = {
    EASY = 30004,
    MEDIUM = 30005,
    HARD = 30006,
    EXPERT = 30007
}

local aid = 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:aid(aid)
modal:register()

local difficultyEvent = CreatureEvent("selectDifficulty")

function difficultyEvent.onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("selectDifficulty")
    if modalWindowId ~= 0 or buttonId == 2 then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You have cancelled the selection.")
        return true
    end

    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

    return true
end

difficultyEvent:type("modalwindow")
difficultyEvent:register()

1715696338734.png
 
uhh, can you try a super simple test script, like.. below, to see that it works?
Cuz I'm not seeing anything obvious in the code that would account for that error

Lua:
local test = Action()

function test.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    print("actionId trigger is working.")
    return true
end

test:aid(3006)
test:register()
Alright, so.. once I tried to just trigger a print the same error poped up. So I restarted it all, turned out that the old 3005 aid script was triggered where the issue was at the first stage of the script.

So after restarting, printing works, and the script above works fine using an aid..
Using visual studio without being connected onto the machine itself might not be a good idea. Will setup a connection to edit live instead, thank you both!

1715696597729.png
 
Since this is connected to the same script, I'll just avoid creating a new thread.
What would be an ideal way to spawn monsters, not just once but kind of place down a spawner depending on the mode?

Let me try to phrase it:
Players enters
Monsters spawns (60s on repeat)
Players clears first floor, now the monsters are changed out to harder monsters
and on repeat 3 times to make it harder.

How would this kind of be done, load in seprate maps of it at the positions (or just the monsters) on the positions and load it up when script calls it or?..
 
Code:
Monsters spawns (60s on repeat)
Players clears first floor, now the monsters are changed out to harder monsters
Respawn killed monsters every 60 second = players have to kill them all within 60 second. That's what you want?
Or spawn monsters, wait until players kill all and spawn next stronger wave = classic dungeon/arena with stronger waves?

There are 2 problems with scripts like that:
  • massive spawn of monsters/'map part' load will lag OTS - you should use addEvent and spawn few monsters at once with XX executions over 1-5 seconds
  • tracking of killed monsters may lag OTS - if you try to getSpectators() in area and count monsters; you should keep monster IDs in some table in Lua or add to them onDeath event that decrement some Lua variable (when it goes to 0, you start next wave)
 
Code:
Monsters spawns (60s on repeat)
Players clears first floor, now the monsters are changed out to harder monsters
Respawn killed monsters every 60 second = players have to kill them all within 60 second. That's what you want?
Or spawn monsters, wait until players kill all and spawn next stronger wave = classic dungeon/arena with stronger waves?

There are 2 problems with scripts like that:
  • massive spawn of monsters/'map part' load will lag OTS - you should use addEvent and spawn few monsters at once with XX executions over 1-5 seconds
  • tracking of killed monsters may lag OTS - if you try to getSpectators() in area and count monsters; you should keep monster IDs in some table in Lua or add to them onDeath event that decrement some Lua variable (when it goes to 0, you start next wave)
So what I am after is, placing mob with spawner. So if it's killed is the answer then have it respawn within set time.
Then, I got a complex one but it works. You walk through a pattern of teleports which spawns a boss. Here, we swap the spawned monsters.
So the idea is to have those 4 objects drop inside bosses which you have to fight your way through to collect and use.

Right now, I changed out the idea since I have no idea what to do yet so currently I use 4 different areas for each difficulty which also allows different arenas to be used at once.

So once triggered, I spawn a set of non-re-spawnable harder monsters in the dungeon.
This works as I'd like it too so far, but would be nice with a way to spawn the monsters and keep track of if they're alive or dead and re-spawn them without causing like you said. lag
1715886439056.png
 
Back
Top