• 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!

Lua HELP! "Blank" ModalWindow

gui56

New Member
Joined
Feb 4, 2009
Messages
19
Reaction score
0
Good night guys,

I'm trying to fix a script from TFS 1.0 to TFS 1.2 but I don't know what I'm doing wrong, cause there's no error on console. The task script returns a ModalWindow to player but it's blank, like the picture:

Ss0dQxP0.jpg




Code:
player:getStorageValue = player:getStorageValue
player:setStorageValue = player:setStorageValue

rankStorage = 32150

THESNAPPER = {80000, 1}
DEMODRAS = {80001, 1}
HIDE = {80002, 1}
THEBLOODTUSK = {80003, 1}
SHARDHEAD = {80004, 1}
THUL = {80005, 1}
ESMERALDA = {80006, 1}
THEOLDWIDOW = {80007, 1}
THEMANY = {80008, 1}
LEVIATHAN = {80009, 1}
STONECRACKER = {80010, 1}
THENOXIUSSPAWN = {80011, 1}
MERIKHTHESLAUGHTERER = {80012, 1}
FAHIMTHEWISE = {80013, 1}
RANDOMPIRATEBOSS = {80014, 1}
THEHORNEDFOX = {80015, 1}
NECROPHARUS = {80016, 1}

tasks =
{
[1] = {questStarted = 65000, questStorage = 65100, killsRequired = 100, raceName = "Trolls", repeatable = false, rewards = {{enable = true, type = "exp", values = 40000}, {enable = true, type = "money", values = 40000}}},
[2] = {questStarted = 65001, questStorage = 65101, killsRequired = 150, raceName = "Goblins", repeatable = false, rewards = {{enable = true, type = "exp", values = 70000}, {enable = true, type = "money", values = 50000}}},
[3] = {questStarted = 65002, questStorage = 65102, killsRequired = 300, raceName = "Rotworms", repeatable = false, rewards = {{enable = true, type = "exp", values = 100000}, {enable = true, type = "money", values = 60000}}},
[4] = {questStarted = 65003, questStorage = 65103, killsRequired = 500, raceName = "Cyclops", repeatable = false, rewards = {{enable = true, type = "exp", values = 150000}, {enable = true, type = "money", values = 80000}}},
[5] = {questStarted = 14007, questStorage = 14107, killsRequired = 300, raceName = "Crocodiles", repeatable = true, rewards = {{enable = true, type = "exp", values = 100000}, {enable = true, type = "storage", values = THESNAPPER}, {enable = true, type = "points", values = 2}}},
[6] = {questStarted = 14008, questStorage = 14108, killsRequired = 300, raceName = "Tarantulas", repeatable = true, rewards = {{enable = true, type = "exp", values = 150000}, {enable = true, type = "storage", values = HIDE}, {enable = true, type = "points", values = 2}}},
[7] = {questStarted = 14009, questStorage = 14109, killsRequired = 150, raceName = "Carniphilas", repeatable = false, rewards = {{enable = true, type = "exp", values = 250000}, {enable = true, type = "money", values = 150000}}},
[8] = {questStarted = 14010, questStorage = 14110, killsRequired = 200, raceName = "Stone Golems", repeatable = false, rewards = {{enable = true, type = "exp", values = 200000}, {enable = true, type = "money", values = 150000}}},
[9] = {questStarted = 14011, questStorage = 14111, killsRequired = 300, raceName = "Mammoths", repeatable = true, rewards = {{enable = true, type = "exp", values = 150000}, {enable = true, type = "storage", values = THEBLOODTUSK}, {enable = true, type = "points", values = 2}}},
[10] = {questStarted = 14012, questStorage = 14112, killsRequired = 300, raceName = "Ice Golems", repeatable = true, rewards = {{enable = true, type = "exp", values = 150000}, {enable = true, type = "storage", values = SHARDHEAD}, {enable = true, type = "points", values = 2}}},
[11] = {questStarted = 14013, questStorage = 14113, killsRequired = 300, raceName = "Quaras Scout", repeatable = true, rewards = {{enable = true, type = "exp", values = 250000}, {enable = true, type = "money", values = 250000}}},
[12] = {questStarted = 14014, questStorage = 14114, killsRequired = 300, raceName = "Quaras", repeatable = true, rewards = {{enable = true, type = "exp", values = 300000}, {enable = true, type = "storage", values = THUL}, {enable = true, type = "points", values = 2}}},
[13] = {questStarted = 14015, questStorage = 14115, killsRequired = 70, raceName = "Water Elementals", repeatable = false, rewards = {{enable = true, type = "exp", values = 200000}, {enable = true, type = "money", values = 200000}}},
[14] = {questStarted = 14016, questStorage = 14116, killsRequired = 70, raceName = "Earth Elementals", repeatable = false, rewards = {{enable = true, type = "exp", values = 200000}, {enable = true, type = "money", values = 200000}}},
[15] = {questStarted = 14017, questStorage = 14117, killsRequired = 70, raceName = "Energy Elementals", repeatable = false, rewards = {{enable = true, type = "exp", values = 200000}, {enable = true, type = "money", values = 200000}}},
[16] = {questStarted = 14018, questStorage = 14118, killsRequired = 70, raceName = "Fire Elementals", repeatable = false, rewards = {{enable = true, type = "exp", values = 200000}, {enable = true, type = "money", values = 200000}}},
[17] = {questStarted = 14019, questStorage = 14119, killsRequired = 200, raceName = "Mutated Rats", repeatable = true, rewards = {{enable = true, type = "exp", values = 150000}, {enable = true, type = "storage", values = ESMERALDA}, {enable = true, type = "points", values = 2}}},
[18] = {questStarted = 14020, questStorage = 14120, killsRequired = 500, raceName = "Giant Spiders", repeatable = true, rewards = {{enable = true, type = "exp", values = 250000}, {enable = true, type = "storage", values = THEOLDWIDOW}, {enable = true, type = "points", values = 2}}},
[19] = {questStarted = 14021, questStorage = 14121, killsRequired = 500, raceName = "Hydras", repeatable = true, rewards = {{enable = true, type = "storage", values = THEMANY}, {enable = true, type = "points", values = 4}}},
[20] = {questStarted = 14001, questStorage = 14101, killsRequired = 500, raceName = "Sea Serpents", repeatable = true, rewards = {{enable = true, type = "storage", values = LEVIATHAN}, {enable = true, type = "points", values = 4}}},
[21] = {questStarted = 14022, questStorage = 14122, killsRequired = 500, raceName = "Behemoths", repeatable = true, rewards = {{enable = true, type = "storage", values = STONECRACKER}, {enable = true, type = "points", values = 4}}},
[22] = {questStarted = 14002, questStorage = 14102, killsRequired = 375, raceName = "Serpents Spawn", repeatable = true, rewards = {{enable = true, type = "storage", values = THENOXIOUSSPAWN}, {enable = true, type = "points", values = 4}}},
[23] = {questStarted = 65022, questStorage = 65122, killsRequired = 125, raceName = "Green Djinns", repeatable = true, rewards = {{enable = true, type = "exp", values = 230000}, {enable = true, type = "money", values = 5000}, {enable = true, type = "storage", values = MERIKHTHESLAUGHTERER}}},
[24] = {questStarted = 65023, questStorage = 65123, killsRequired = 125, raceName = "Blue Djinns", repeatable = true, rewards = {{enable = true, type = "exp", values = 230000}, {enable = true, type = "money", values = 5000}, {enable = true, type = "storage", values = FAHIMTHEWISE}}},
[25] = {questStarted = 65024, questStorage = 65124, killsRequired = 300, raceName = "Pirates", repeatable = false, rewards = {{enable = true, type = "exp", values = 300000}, {enable = true, type = "money", values = 400000}, {enable = true, type = "storage", values = RANDOMPIRATEBOSS}}},
[26] = {questStarted = 14004, questStorage = 14104, killsRequired = 500, raceName = "Minotaurs", repeatable = false, rewards = {{enable = true, type = "storage", values = THEHORNEDFOX}}},
[27] = {questStarted = 14003, questStorage = 14103, killsRequired = 1000, raceName = "Magicians", repeatable = false, rewards = {{enable = true, type = "storage", values = NECROPHARUS}}},
[28] = {questStarted = 65030, questStorage = 65130, killsRequired = 500, raceName = "Dragons", repeatable = true, rewards = {{enable = true, type = "storage", values = DEMODRAS}, {enable = true, type = "exp", values = 400000}}},
[29] = {questStarted = 14023, questStorage = 14123, killsRequired = 6666, raceName = "Demons", repeatable = false, rewards = {{enable = true, type = "exp", values = 1000000}, {enable = true, type = "item", values = {10305,1}}}}}

function getTasksStarted(cid)
local tmp = {}
for k, v in pairs(tasks) do
if player:getStorageValue(cid, v.questStarted) == 1 then
table.insert(tmp, k)
end
end
return tmp
end

function getTaskByName(name)
for k, v in pairs(tasks) do
if v.raceName:lower() == name:lower() then
return k
end
end
return false
end

function modalWindow:sendToPlayer(cid)
local task_status = {}

if taskWindow:getId() == 1900 then
    taskWindow:addButton(1, "Select")
    taskWindow:addButton(2, "Cancel")
    for i = 1, #tasks do
        if player:getStorageValue(cid, tasks[i].questStarted) == 2 then
            task_status[i] = "[completed]"
        else
            if player:getStorageValue(cid, tasks[i].questStarted) == 1 then
                task_status[i] = "[" .. player:getStorageValue(cid, tasks[i].questStorage) .. "/" .. tasks[i].killsRequired .. "]"
            else
                if player:getStorageValue(cid, tasks[i].questStarted) < 1 then
                    task_status[i] = tasks[i].killsRequired
                else
                    task_status[i] = tasks[i].killsRequired .. " [unknown]"
                end
            end
        end
      
        if player:getStorageValue(cid, tasks[i].questStarted) == 1 and player:getStorageValue(cid, tasks[i].questStorage) >= tasks[i].killsRequired then
            taskWindow:addChoice(i, tasks[i].raceName .. " [click for reward]")
        else
            taskWindow:addChoice(i, tasks[i].raceName .. ", " .. task_status[i])
        end
    end
end
taskWindow:sendToPlayer(cid)
return true
end
 
Code:
function onModalWindow(cid, modalWindowId, buttonId, choiceId)
    local player = Player(cid)
    local rank = player:getStorageValue(cid, rankStorage)
    local taskWindow = ModalWindow(1900, "Mission Management", "Select a task:")
    if rank < 0 then
        player:setStorageValue(cid, rankStorage, 0)
    end
                  
    local r_string = function() if tasks[choiceId].repeatable then return "repeatable" end return "not repeatable" end
    local r_article_string = function (id, amount)
        task_item_word = ""
        if amount > 1 then
            task_item_word = task_item_word .. amount .. "x " .. item:getName(id)
        else
            if ItemType(itemId):getArticle() == "" then
                task_item_word = task_item_word .. item:getName(id)
            else
                task_item_word = task_item_word .. ItemType(itemId):getArticle() .. " " .. item:getName(id)
            end
        end
    return task_item_word
    end
    local storage_string = {[80000] = "The Snapper",
[80001] = "Demodras",
[80002] = "The Hide",
[80003] = "The Bloodtusk",
[80004] = "The Shardhead",
[80005] = "Thul",
[80006] = "Esmeralda",
[80007] = "The Old Widow",
[80008] = "The Many",
[80009] = "The Leviathan",
[80010] = "The Stonecracker",
[80011] = "The Noxious Spawn",
[80012] = "Merikh The Slaughterer",
[80013] = "Fahim The Wise",
[80014] = "pirate leader",
[80015] = "The Horned Fox",
[80016] = "Necropharus"
    }
    if (not modalWindowId == 1900) then return false end

    if buttonId == 1 then -- confirm task
        if player:getStorageValue(cid, tasks[choiceId].questStarted) < 1 then
            player:setStorageValue(cid, tasks[choiceId].questStarted, 1)
            player:setStorageValue(cid, tasks[choiceId].questStorage, 0)
            creature:say(taskNPCuid, "In this mission you have to hunt " .. tasks[choiceId].killsRequired .. " " .. tasks[choiceId].raceName .. " down. Good luck!", TALKTYPE_PRIVATE_NP, false, cid, getThingPos(taskNPCuid))
        else
            if player:getStorageValue(cid, tasks[choiceId].questStarted) == 1 then
                if tasks[choiceId].killsRequired > player:getStorageValue(cid, tasks[choiceId].questStorage) then
                    doPlayerPopupFYI(cid,"Status: Active\nKills: " .. player:getStorageValue(cid, tasks[choiceId].questStorage) .. "/" .. tasks[choiceId].killsRequired .. " (" .. tasks[choiceId].killsRequired - player:getStorageValue(cid, tasks[choiceId].questStorage) .. " left)\n\nThis mission is " .. r_string() .. ".")
                    taskWindow:sendToPlayer(cid)
                else
                    player:setStorageValue(cid, tasks[choiceId].questStarted, 2)
                    task_reward_str = "Reward(s):\n"
                    for i = 1, table.maxn(tasks[choiceId].rewards) do
                        if(tasks[choiceId].rewards[i].enable) then
                            if isInArray({"boss", "teleport", 1}, tasks[choiceId].rewards[i].type) then
                                doTeleportThing(cid, tasks[choiceId].rewards[i].values)
                                task_reward_str = task_reward_str .. "You have been teleported.\n"
                            elseif isInArray({"exp", "experience", 2}, tasks[choiceId].rewards[i].type) then
                                doPlayerAddExperience(cid, tasks[choiceId].rewards[i].values)
                                task_reward_str = task_reward_str .. "+ " .. tasks[choiceId].rewards[i].values .. " exp\n"
                            elseif isInArray({"item", 3}, tasks[choiceId].rewards[i].type) then
                                doPlayerAddItem(cid, tasks[choiceId].rewards[i].values[1], tasks[choiceId].rewards[i].values[2])
                                task_reward_str = task_reward_str .. r_article_string(tasks[choiceId].rewards[i].values[1], tasks[choiceId].rewards[i].values[2]) .. "\n"
                            elseif isInArray({"money", 4}, tasks[choiceId].rewards[i].type) then
                                doPlayerAddMoney(cid, tasks[choiceId].rewards[i].values)
                                task_reward_str = task_reward_str .. "+ " .. tasks[choiceId].rewards[i].values .. " gp\n"
                            elseif isInArray({"storage", "stor", 5}, tasks[choiceId].rewards[i].type) then
                                player:setStorageValue(cid, tasks[choiceId].rewards[i].values[1], tasks[choiceId].rewards[i].values[2])
                                task_reward_str = task_reward_str .. "Chance to duel " .. storage_string[tasks[choiceId].rewards[i].values[1]] .. ".\n"
                            elseif isInArray({"points", "rank", 2}, tasks[choiceId].rewards[i].type) then
                                player:setStorageValue(cid, rankStorage, player:getStorageValue(cid, rankStorage) + tasks[choiceId].rewards[i].values)
                                task_reward_str = task_reward_str .. "+ " .. tasks[choiceId].rewards[i].values .. " rank points.\n"
                            else
                                print("[Warning - Npc::KillingInTheNameOf] Wrong reward type: " .. (tasks[choiceId].rewards[i].type or "nil") .. ", reward could not be loaded.")
                            end
                        end
                    end
                    if task_reward_str == "Reward(s):\n" then
                        doPlayerPopupFYI(cid,task_reward_str .. "none")
                    else
                        doPlayerPopupFYI(cid,task_reward_str)
                    end
                    creature:say(taskNPCuid, "Great job" .. (((rank > 4 and rank < 10) and (", Huntsman") or (rank > 9 and rank < 20) and (", Ranger") or (rank > 19 and rank < 30) and (", Big Game Hunter") or (rank > 29 and rank < 50) and (", Trophy Hunter") or (rank > 49) and (", Elite Hunter")) or ", my Beginner") .. "! Here is your reward. Keep hunting and good luck!", TALKTYPE_PRIVATE_NP, false, cid, getThingPos(taskNPCuid))
                end
            else
                if tasks[choiceId].repeatable then
                    for i = 1, table.maxn(tasks[choiceId].rewards) do
                        if isInArray({"storage", "stor", 5}, tasks[choiceId].rewards[i].type) then
                            doPlayerPopupFYI(cid,"To repeat this mission again, fight with " .. storage_string[tasks[choiceId].rewards[i].values[1]] .. " first.")
                            break
                        end
                        if i == table.maxn(tasks[choiceId].rewards) then
                            doPlayerPopupFYI(cid,"You can't repeat this mission.")
                        end
                    end
                else
                    doPlayerPopupFYI(cid,"You can't repeat this mission.")
                end
                taskWindow:sendToPlayer(cid)
            end
        end
    elseif buttonId == 255 then
        doPlayerPopupFYI(cid,"Please use a button.")
        taskWindow:sendToPlayer(cid)
    end
  
return true
end

Code:
local choose = {}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid)  npcHandler:onCreatureAppear(cid)  end
function onCreatureDisappear(cid)  npcHandler:onCreatureDisappear(cid)  end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg)  end
function onThink()  npcHandler:onThink()  end
function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
    local taskWindow = ModalWindow(1900, "Mission Management", "Select a task:")
    if isInArray({"task", "tasks"}, msg:lower()) then
        selfSay("Here.", cid)
        taskNPCuid = getNpcCid()
        if player:getStorageValue(32150) < 0 then player:setStorageValue(32150, 0) end
        return taskWindow:sendToPlayer(cid)
    end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top