• 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 Task/mission NPC (storyline)

Jalorius

Intermediate OT User
Joined
Sep 2, 2015
Messages
62
Reaction score
103
Hi all, if this is not allowed here, please feel free to remove my post.

Just trying to figure out a script I have going right now. TFS 1.x and 10.77. It's not the normal Tasker NPC that you choose your monster to kill, it's more of a storyline Task npc. I'm trying to be able to have one NPC be able to start off with killing one monster than going onto another after the first one has been killed.

I've gotten to the point where all of the monsters register and I am able to carry the task all the way till the end of the tasks, but am having the problem of either the NPC will not read storage values and skip the killing to be able to complete the monsters killed or I am able to kill the monsters but will not register that I have killed or will not move onto the next storage for the next part of the mission.

This is what I currently have:

NPC script:
Code:
 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

local storage = 1004


function creatureSayCallback(cid, type, msg)
     if not npcHandler:isFocused(cid) then
         return false
     end
  
     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if msgcontains(msg, "stronger") then
        selfSay("Pfft.. you think you can {train} under me?", cid)
    end

        if msgcontains(msg, "train") or msgcontains(msg, "task") then
            if getPlayerStorageValue(cid, storage) == -1 then
                selfSay("Hmph. Well then, prove to me you are capable. Go and slay 10 rat. can you do this?", cid)
                talkState[talkUser] = 1
            elseif getPlayerStorageValue(cid, storage) == 2 then
                selfSay("You still haven't completely convinced me. Your next task is to go out into the wild and slay 8 wolves. I hope you're ready?", cid)
                talkState[talkUser] = 1
            elseif getPlayerStorageValue(cid, storage) == 4 then
                selfSay("I must admit, you have it in you. Well then, we must continue our training. I heard there were some bears near by, and I need you to take them out. Can you go and kill 15 and report back?", cid)
                talkState[talkUser] = 1
            elseif getPlayerStorageValue(cid, storage) == 6 then
                selfSay("For your next task, I need you to find the Troll lair and extinguish them. Can I trust you with this task?", cid)
                talkState[talkUser] = 1             
            elseif getPlayerStorageValue(cid, storage) == 1 then
                selfSay("Did you finish your task?", cid)
                talkState[talkUser] = 1
            elseif getPlayerStorageValue(cid, storage) == 3 then
                selfSay("Did you bring me good news?", cid)
                talkState[talkUser] = 1
            elseif getPlayerStorageValue(cid, storage) == 5 then
                selfSay("Have you taken care of those bears I asked about?", cid)
                talkState[talkUser] = 1
            elseif getPlayerStorageValue(cid, storage) == 7 then
                selfSay("Are the nasty trolls gone?", cid)
                talkState[talkUser] = 1
            else
                selfSay("Your time here is done. Thank you for all your help.", cid)
        end
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
        if getPlayerStorageValue(cid, storage) == -1 then
            selfSay("I don't think you have it in you...", cid)
            setPlayerStorageValue(cid, storage, 1)
    elseif getPlayerStorageValue(cid, storage) == 2 then
            selfSay("Don't back out now, we're getting somewhere.", cid)
            setPlayerStorageValue(cid, storage, 3)
    elseif getPlayerStorageValue(cid, storage) == 4 then
            selfSay("Don't forget to supply up before leaving. I wouldn't want you getting hurt now.", cid)
            setPlayerStorageValue(cid, storage, 5)
    elseif getPlayerStorageValue(cid, storage) == 6 then
            selfSay("You will find these pest's hiding deep in a cave. Don't forget a torch to light your way.", cid)
            setPlayerStorageValue(cid, storage, 7)     
        else
            if getPlayerStorageValue(cid, storage) == 10 then
                selfSay("Well well, you made it out in one piece. Ready for your next {task}?", cid)
                doPlayerAddExp(cid, 150)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have recieved 150 experience points.")
                setPlayerStorageValue(cid, storage, 2)         
            elseif getPlayerStorageValue(cid, storage) == 8 then
                selfSay("Very impresive. I suppose you are worthy of training. If you are looking for another {task}, just ask and I will be happy to give you one.", cid)
                doPlayerAddExp(cid, 350)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have recieve 350 experience points.")
                setPlayerStorageValue(cid, storage, 4)
            elseif getPlayerStorageValue(cid, storage) == 15 then
                selfSay("Well done young one. But we have further more to be sure our town is safe. Come back when you are ready for another {task}.", cid)
                doPlayerAddExp(cid, 700)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have recieve 700 experience points.")
                setPlayerStorageValue(cid, storage, 6)
            elseif getPlayerStorageValue(cid, storage) == 20 then
                selfSay("And another one bites the dust. That's what I like to see. come back when you're ready for your next {task}.", cid)
                doPlayerAddExp(cid, 1000)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have recieve 1000 experience points.")
                setPlayerStorageValue(cid, storage, 8)         
            else
                selfSay("Pathetic, get back out there and don't come back till you are done.", cid)
            end
        end
        talkState[talkUser] = 0
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay("Well what are you waiting for kid?! Move along!.", cid)
        talkState[talkUser] = 0
    end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Creature script:
Code:
 local config = {
     ['rat'] = {amount = 10, storage = 15000, startstorage = 1004, startvalue = 1},
     ['wolf'] = {amount = 8, storage = 15001, startstorage = 1005, startvalue = 1},
     ['bear'] = {amount = 15, storage = 15002, startstorage = 1006, startvalue = 1},
     ['troll'] = {amount = 20, storage = 15003, startstorage = 1007, startvalue = 1}
}
function onKill(cid, target)
     local monster = config[getCreatureName(target):lower()]
     if isPlayer(target) or not monster or isSummon(target) then
         return true
     end

     if (getPlayerStorageValue(cid, monster.storage)+1) < monster.amount and getPlayerStorageValue(cid, monster.startstorage) >= monster.startvalue then
         setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
         doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..getCreatureName(target)..'s killed.')
     end
     if (getPlayerStorageValue(cid, monster.storage)+1) == monster.amount then
         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Congratulations, you have killed '..(getPlayerStorageValue(cid, monster.storage)+1)..' '..getCreatureName(target)..'s and completed the '..getCreatureName(target)..'s mission.')
         setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
     end
     return true
end


Edit: Added client version and also, Server
 
Last edited:
Please read this thread and update your post.
Server version etc

 
Back
Top