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

NPC Mission

Copy and then paste it in the lib Lua file.
If you are unable to find a Lua file in your data folder that is used as lib file, you can also add the function at the top of the onKill script (so above function onKill).
 
this is my creaturescripts.lub

Code:
function checkStageChange(cid)
    local playerLevel = getPlayerLevel(cid)
   
    if (playerLevel > stages[#stages].maxLevel) then
        setExperienceRate(cid, stages[#stages].multiplier)
        return true
    end
   
    for i = 1, #stages do
        if (playerLevel >= stages[i].minLevel and playerLevel <= stages[i].maxLevel) then
            setExperienceRate(cid, stages[i].multiplier)
            return true
        end
    end
   
    return false
end
 
Nah, I ment a global lib, can be in the folder data, like global.lua in TFS 0.2/1.0, or function.lua in the folder data/lb like in TFS 0.3/0.4.

But if you can't find such a Lua file, you can also just add the function in the onKill script (above function onKill).
 
13:09 Task: Good job, here is your reward.

i fix it ;)

how i can add new monster for this npc ?

my creaturescript
Code:
  ['dragon'] = {amount = 5, storage = 19000, startstorage = 5002, startvalue = 1},
     ['dragon lord'] = {amount = 3, storage = 19001, startstorage = 5002, startvalue = 1}
    ['heros'] = {amount = 3, storage = 19002, startstorage = 5003, startvalue = 1}

my npc :

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 = 5002

function creatureSayCallback(cid, type, msg)
if npcHandler.focus ~= cid then
     return false
end
     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

     if msgcontains(msg, "mission") then
         if getPlayerStorageValue(cid, storage) == -1 then
             npcHandler:say("I have a mission for you to kill 5 dragons and 3 dragon lords, do you accept?", cid)
             talkState[talkUser] = 1
         elseif getPlayerStorageValue(cid, storage) == 1 then
             npcHandler:say("Did you kill 5 dragons and 3 dragon lords?", cid)
             talkState[talkUser] = 1
         else
             npcHandler:say("You already did the mission.", cid)
         end
     elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
         if getPlayerStorageValue(cid, storage) == -1 then
             npcHandler:say("Good, come back when you killed them.", cid)
             setPlayerStorageValue(cid, storage, 1)
         else
             if getPlayerStorageValue(cid, 19000) == 5 and getPlayerStorageValue(cid, 19001) == 3 then
                 npcHandler:say("Good job, here is your reward.", cid)
                 doPlayerAddItem(cid, 2160, 5)
                 doPlayerAddExp(cid, 50000)
                 setPlayerStorageValue(cid, storage, 2)
             else
                 npcHandler:say("You didn't kill them all.", cid)
             end
         end
         
             if msgcontains(msg, "heros") then
         if getPlayerStorageValue(cid, storage) == -1 then
             npcHandler:say("I have a task for you to kill 200 Heros, do you accept?", cid)
             talkState[talkUser] = 1
         elseif getPlayerStorageValue(cid, storage) == 1 then
             npcHandler:say("Did you kill 200?", cid)
             talkState[talkUser] = 1
         else
             npcHandler:say("You already did the mission.", cid)
         end
     elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
         if getPlayerStorageValue(cid, storage) == -1 then
             npcHandler:say("Good, come back when you killed them.", cid)
             setPlayerStorageValue(cid, storage, 1)
         else
             if getPlayerStorageValue(cid, 19002) == 5 and getPlayerStorageValue(cid, 19002) == 3 then
                 npcHandler:say("Good job, here is your reward.", cid)
                 doPlayerAddItem(cid, 2160, 5)
                 doPlayerAddExp(cid, 300000)
                 setPlayerStorageValue(cid, storage, 2)
             else
                 npcHandler:say("You didn't kill them all.", cid)
             end
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
         npcHandler:say("Ok then.", cid)
         talkState[talkUser] = 0
     end
     return true
end

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

and not work :d
Warning: [NpcScript::NpcScript] Can not load script. data/npc/scripts/task.lua
data/npc/scripts/task.lua:77: 'end' expected (to close 'function' at line 13) near ''
 
Last edited:
You don't have to repeat msgcontains with the same words (yes).

You can give the second mission after the first mission, so the player knows there are more missions.
Code:
npcHandler:say("Good job, here is your reward, for your second mission kill 3 heros.")

Then under:
Code:
elseif getPlayerStorageValue(cid, storage) == 1 then
     npcHandler:say("Did you kill 5 dragons and 3 dragon lords?")
     talkState[talkUser] = 1

You can add an other part for storage value 2, because after finishing the first mission, the storage value was set to 2.
Code:
elseif getPlayerStorageValue(cid, storage) == 2 then
     npcHandler:say("Did you kill 5 dragons and heros?")
     talkState[talkUser] = 1

Then do the same thing after the msgcontains line for yes, so it will be: if, elseif, else instead of if and else.
Every time after a msgcontains line check for the storage value, then add what it should do.
You can use else because if the player doesn't have the other storage values, then it has to have the one that's left, but you could also just use elseif for every line.

Also set the storagevalue to 3 then after completing the second mission.

For the creaturescript part:
Code:
['dragon'] = {amount = 5, storage = 19000, startstorage = 5002, startvalue = 1},
['dragon lord'] = {amount = 3, storage = 19001, startstorage = 5002, startvalue = 1},
['hero'] = {amount = 3, storage = 19002, startstorage = 5002, startvalue = 2}

You have to write the monster name as you see it, so without s, the startstorage should be the storage of the npc (5002) and the startvalue the storagevalue that is set when the person is doing the mission.
 
Last edited:
i can make more missions but in order to not have to do one after the other?

Example :

Hello i have a several tasks for you to kill ( 10 dragons ) , ( 10 dragon lords ) (10 heros ) (10 dward guard ), do you accept?

Next i say :

Dragons

Npc give me this task and i must finish this mission for give me other mission

i kill this dragons and back for other task ;)

so i can take a one mission that I want and not the one that will give me

You know what i mean??
 
Last edited:
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 = 5002

local monsters = {
   ["dragons"] = {storage = 5010, mstorage = 19000, amount = 10, exp = 5000, item = {2160, 3}},
   ["dragon lords"] = {storage = 5011, mstorage = 19001, amount = 10, exp = 10000, item = {2160, 10}},
   ["heros"] = {storage = 5012, mstorage = 19002, amount = 10, exp = 8000, item = {2160, 8}},
   ["dwarf guards"] = {storage = 5013, mstorage = 19003, amount = 10, exp = 7000, item = {2160, 7}}
}

function creatureSayCallback(cid, type, msg)
     if npcHandler.focus ~= cid then
         return false
     end

     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

     if msgcontains(msg, "mission") then
         if getPlayerStorageValue(cid, storage) == -1 then
             local text, n = "",  0
             for k, x in pairs(monsters) do
                 if getPlayerStorageValue(cid, x.storage) == -1 then
                     n = n + 1
                     text = text .. ", "
                     text = text .. ""..x.amount.." {"..k.."}"
                 end
             end
             if n > 1 then
                 npcHandler:say("I have several tasks for you to kill"..text..", which one do you choose?")
                 talkState[talkUser] = 1
             elseif n == 1 then
                 npcHandler:say("I have one last task for you"..text..".")
                 talkState[talkUser] = 1
             else
                 npcHandler:say("You already did the missions.")
             end
         elseif getPlayerStorageValue(cid, storage) == 1 then
             for k, x in pairs(monsters) do
                 if getPlayerStorageValue(cid, x.storage) == 1 then
                     npcHandler:say("Did you kill "..x.amount.." "..k.."?")
                     talkState[talkUser] = 2
                     xmsg = k
                 end
             end
         end
     elseif monsters[msg:lower()] and talkState[talkUser] == 1 then
         if getPlayerStorageValue(cid, monsters[msg:lower()].storage) == -1 then
             npcHandler:say("Good luck, come back when you killed "..monsters[msg:lower()].amount.." "..msg..".")
             setPlayerStorageValue(cid, storage, 1)
             setPlayerStorageValue(cid, monsters[msg:lower()].storage, 1)
         else
            npcHandler:say("You already did the "..msg.." mission.", cid)
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then
         if getPlayerStorageValue(cid, monsters[xmsg].mstorage) == monsters[xmsg].amount then
             npcHandler:say("Good job, here is your reward.")
             doPlayerAddItem(cid, monsters[xmsg].item[1], monsters[xmsg].item[2])
             doPlayerAddExp(cid, monsters[xmsg].exp)
             setPlayerStorageValue(cid, monsters[xmsg].storage, 2)
             setPlayerStorageValue(cid, storage, -1)
         else
             npcHandler:say("You didn't kill them all.", cid)
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
         npcHandler:say("Ok then.")
         talkState[talkUser] = 0
     end
     return true
end

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

Creaturescript part:
Code:
local config = {
  ['dragon'] = {amount = 10, storage = 19000, startstorage = 5010, startvalue = 1},
  ['dragon lord'] = {amount = 10, storage = 19001, startstorage = 5011, startvalue = 1},
  ['hero'] = {amount = 10, storage = 19002, startstorage = 5012, startvalue = 1},
  ['dwarf guard'] = {amount = 10, storage = 19003, startstorage = 5013, startvalue = 1}
}
 
Last edited:
02:06 GOD: hi
02:06 Task: Welcome, GOD! I have been expecting you.
02:06 GOD: mission

and next npc not write message for me ;/

no have errors in console ;/
 
Maybe your server is using cid at the end of the textmessages, try to add that.
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 = 5003

local monsters = {
   ["dragons"] = {storage = 5010, mstorage = 19000, amount = 10, exp = 5000, item = {2160, 3}},
   ["dragon lords"] = {storage = 5011, mstorage = 19001, amount = 10, exp = 10000, item = {2160, 10}},
   ["heros"] = {storage = 5012, mstorage = 19002, amount = 10, exp = 8000, item = {2160, 8}},
   ["dwarf guards"] = {storage = 5013, mstorage = 19003, amount = 10, exp = 7000, item = {2160, 7}}
}

function creatureSayCallback(cid, type, msg)
     if npcHandler.focus ~= cid then
         return false
     end

     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

     if msgcontains(msg, "mission") then
         if getPlayerStorageValue(cid, storage) == -1 then
             local text, n = "",  0
             for k, x in pairs(monsters) do
                 if getPlayerStorageValue(cid, x.storage) == -1 then
                     n = n + 1
                     text = text .. ", "
                     text = text .. ""..x.amount.." {"..k.."}"
                 end
             end
             if n > 1 then
                 npcHandler:say("I have several tasks for you to kill"..text..", which one do you choose?", cid)
                 talkState[talkUser] = 1
             elseif n == 1 then
                 npcHandler:say("I have one last task for you"..text..".", cid)
                 talkState[talkUser] = 1
             else
                 npcHandler:say("You already did the missions.", cid)
             end
         elseif getPlayerStorageValue(cid, storage) == 1 then
             for k, x in pairs(monsters) do
                 if getPlayerStorageValue(cid, x.storage) == 1 then
                     npcHandler:say("Did you kill "..x.amount.." "..k.."?", cid)
                     talkState[talkUser] = 2
                     xmsg = k
                 end
             end
         end
     elseif monsters[msg:lower()] and talkState[talkUser] == 1 then
         if getPlayerStorageValue(cid, monsters[msg:lower()].storage) == -1 then
             npcHandler:say("Good luck, come back when you killed "..monsters[msg:lower()].amount.." "..msg..".", cid)
             setPlayerStorageValue(cid, storage, 1)
             setPlayerStorageValue(cid, monsters[msg:lower()].storage, 1)
         else
             npcHandler:say("You already did the "..msg.." mission.", cid)
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then
         if getPlayerStorageValue(cid, monsters[xmsg].mstorage) == monsters[xmsg].amount then
             npcHandler:say("Good job, here is your reward.", cid)
             doPlayerAddItem(cid, monsters[xmsg].item[1], monsters[xmsg].item[2])
             doPlayerAddExp(cid, monsters[xmsg].exp)
             setPlayerStorageValue(cid, monsters[xmsg].storage, 2)
             setPlayerStorageValue(cid, storage, -1)
         else
             npcHandler:say("You didn't kill them all.", cid)
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
         npcHandler:say("Ok then.", cid)
         talkState[talkUser] = 0
     end
     return true
end

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

Or it would be that you tested it with a character that already has storage 5002, I changed it to 5003 now.
 
Last edited:
now work also i say

hi / mission / dragons / yes
next i kill 10 dragons back to npc and say
hi/mission/yes
he give me reward i say hi/dragons/yes
and have second reward for each mission ;/ how change for make only each once mission ?
 
Change
Code:
  elseif monsters[msg:lower()] and talkState[talkUser] == 1 then
       npcHandler:say("Good luck, come back when you killed "..monsters[msg:lower()].amount.." "..msg..".", cid)
       setPlayerStorageValue(cid, storage, 1)
       setPlayerStorageValue(cid, monsters[msg:lower()].storage, 1)
       talkState[talkUser] = 0

To
Code:
  elseif monsters[msg:lower()] and talkState[talkUser] == 1 then
       if getPlayerStorageValue(cid, monsters[msg:lower()].storage) == -1 then
           npcHandler:say("Good luck, come back when you killed "..monsters[msg:lower()].amount.." "..msg..".", cid)
           setPlayerStorageValue(cid, storage, 1)
           setPlayerStorageValue(cid, monsters[msg:lower()].storage, 1)
       else
           npcHandler:say("You already did the "..msg.." mission.", cid)
       end
       talkState[talkUser] = 0
 
Last edited:
work :d

aslo now i can take 3 missions at one time :D

will do the trick so that could grab only one mission and first you have to finish it to make a second?
 
Change talkState.
Under:
Code:
npcHandler:say("Did you kill "..x.amount.." "..k.."?", cid)
Change talkState 1 to 2.

Then also change it here.
Code:
elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then
Now after starting the mission people can't start another one before completing it, because when they come back and get the "Did you kil.. " message, talkState will be set to 2 and people need talkState 1 to start a new task.
 
Solved in pm, he was missing the function isSummon.
Other TFS 0.4 users who need this function (add in function.lua in data/lib):
Code:
function isSummon(cid)
     return getCreatureMaster(cid) ~= nil or false
end
 
If i want to insert a delay between messages, how do i do it? looked everywhere but couldnt find. Ex:

selfSay('yadda yadda yadda.', cid)
(10 seconds delay)
selfSay('bla bla bla.', cid)
 
Question about ElseIf

If i have code like this: (not correct code forms, but just wana understand how does elseif work)
If number > 2 then
Say "hi"
elseif number >4 then
Say "bye"
elseif number > 6 then
say "wat"

Which is correct outcome? when the number is 7
1. hi
2. hi
bye
wat
3. wat

Question about talkState
can i have? (so i could have different talkStates at once
local talkState = {}
local talkState2 = {}


anyway, great thread, this will prolly fix my task master NPC problem.
 
Question about ElseIf

If i have code like this: (not correct code forms, but just wana understand how does elseif work)
If number > 2 then
Say "hi"
elseif number >4 then
Say "bye"
elseif number > 6 then
say "wat"

Which is correct outcome? when the number is 7
1. hi
2. hi
bye
wat
3. wat

Question about talkState
can i have? (so i could have different talkStates at once
local talkState = {}
local talkState2 = {}


anyway, great thread, this will prolly fix my task master NPC problem.
In your situation your asking if the number is great than 2,4,6.. It will stop on the first 'if' statement.
As soon as the first 'if' statement is correct it will not even look at the next elseif's.

However if you had it like..
Code:
if number < 2 then
  say this
elseif number < 4 then
  say this
elseif number < 6 then
  say this
else
  say this
end
It would look at each individual line if the number was 7.
You could also put your lines backwards..
Code:
if number > 6 then
  say this
elseif number > 4 then
  say this
elseif number > 2 then
  say this
else
  say this
end
 
Back
Top