• 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

if msgcontains(msg:lower(), 'task') then
talkState[talkUser] = 0
if L >= tasks["deer"].minL and L <= tasks["deer"].maxL then
if getPlayerStorageValue(cid, 10100) < 1 then
selfSay ("Say {deer} for task ", cid)
talkState[talkUser] = 1
end
end
if L >= tasks["wolf"].minL and L <= tasks["wolf"].maxL then
if getPlayerStorageValue(cid, 10101) < 1 then
selfSay ("Say {wolf} for task", cid)
talkState[talkUser] = 1
end
end
if L >= tasks["boar"].minL and L <= tasks["boar"].maxL then
if getPlayerStorageValue(cid, 10102) < 1 then
selfSay ("Say {boar} for task", cid)
talkState[talkUser] = 1
end
end
if L >= tasks["bear"].minL and L <= tasks["bear"].maxL then
if getPlayerStorageValue(cid, 10103) < 1 then
selfSay ("Say {bear} for task", cid)
talkState[talkUser] = 1
end
if talkState[talkUser] == 0 then
selfSay ("NO MOAR TASKS!!", cid)
else talkState[talkUser] = 0
end
end

talkState doesn't work here for TFS 1.0

I want to to say "no moar tasks!!" if he doesn't bring out any previous answers
i don't say it if he says any other answers before
 
It's a table so it's not related to a TFS version, but for TFS 1.0 you can use this instead (it's added in the npcsystem, so you don't need to create a table at the top of the npc like with talkState).
Code:
npcHandler.topic[cid]

For the npc, use elseif and else, it will say the else part if all other statements above are not true.
 
It's a table so it's not related to a TFS version, but for TFS 1.0 you can use this instead (it's added in the npcsystem, so you don't need to create a table at the top of the npc like with talkState).
Code:
npcHandler.topic[cid]

For the npc, use elseif and else, it will say the else part if all other statements above are not true.

If i use elseif then it wont give more solutions when he finds first value and overall it seems buggy:
Code:
    if msgcontains(msg:lower(), 'task') then
        if L >= tasks["deer"].minL and L <= tasks["deer"].maxL then
            if getPlayerStorageValue(cid, 10100) < 1 then
                selfSay ("Say {deer} for task ", cid)
            end
       
        elseif L >= tasks["wolf"].minL and L <= tasks["wolf"].maxL then
            if getPlayerStorageValue(cid, 10101) < 1 then
                selfSay ("Say {wolf} for task", cid)
            end

        elseif L >= tasks["boar"].minL and L <= tasks["boar"].maxL then
            if getPlayerStorageValue(cid, 10102) < 1 then
                selfSay ("Say {boar} for task", cid)
            end
       
        elseif L >= tasks["bear"].minL and L <= tasks["bear"].maxL then
            if getPlayerStorageValue(cid, 10103) < 1 then
                selfSay ("Say {bear} for task", cid)
            end
        else selfSay ("no moar tasks", cid)
        end

already tried this: Had no effect
Code:
if msgcontains(msg:lower(), 'task') then
npcHandler.topic[cid] = 0
if L >= tasks["deer"].minL and L <= tasks["deer"].maxL then
if getPlayerStorageValue(cid, 10100) < 1 then
selfSay ("Say {deer} for task ", cid)
npcHandler.topic[cid] = 1
end
end
if L >= tasks["wolf"].minL and L <= tasks["wolf"].maxL then
if getPlayerStorageValue(cid, 10101) < 1 then
selfSay ("Say {wolf} for task", cid)
npcHandler.topic[cid] = 1
end
end
if L >= tasks["boar"].minL and L <= tasks["boar"].maxL then
if getPlayerStorageValue(cid, 10102) < 1 then
selfSay ("Say {boar} for task", cid)
npcHandler.topic[cid] = 1
end
end
if L >= tasks["bear"].minL and L <= tasks["bear"].maxL then
if getPlayerStorageValue(cid, 10103) < 1 then
selfSay ("Say {bear} for task", cid)
npcHandler.topic[cid] = 1
end
if npcHandler.topic[cid] == 0 then
selfSay ("NO MOAR TASKS!!", cid)
else npcHandler.topic[cid] = 0
end
end
 
@Limos If I want to make a task with "races" instead of monsters, example: kill orcs (normal, spearman, berserker,...), how I change the lua?
 
@Limos If I want to make a task with "races" instead of monsters, example: kill orcs (normal, spearman, berserker,...), how I change the lua?

Make table named
Orcs = {"orc", "orc spearman", "orc berserker"}
And loop trough
for tableValue=1, #Orcs do
if orcs.[tableValue] == target:getName() then
+1 to orc task :D
end
end
 
Code:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..getCreatureName(target)..'s killed.')
If you want to make that Orcs for example, you can add name = "Orc" to the table and in the textmessage like this.
Code:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..(monster.name or getCreatureName(target))..'s killed.')
 
Code:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..getCreatureName(target)..'s killed.')
If you want to make that Orcs for example, you can add name = "Orc" to the table and in the textmessage like this.
Code:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..(monster.name or getCreatureName(target))..'s killed.')
I never stop learning with you. Thanks
 
@Limos bro can u create mission like kill 100 people get 200 premium points and with options of frags 50,100,500,600,1000 example?
 
Now stop bumping and double posting shit. post something once and wait for a reply :|

This belongs to @Limos post i just changed the reward item to points~
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink() npcHandler:eek:nThink() end

function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local config = {
npcstorage = 18687,
killstorage = 19001,
amountkills = 50,
rewardpoints = 50,
rewardexp = 12000
}

if(msgcontains(msg, 'mission')) then
if getPlayerStorageValue(cid, config.npcstorage) == -1 then
selfSay('So you want to do the mission? I want you to kill 50 players, do you accept?', cid)
talkState[talkUser] = 1
elseif getPlayerStorageValue(cid, config.npcstorage) == 1 then
selfSay('Did you kill 50 players?', cid)
talkState[talkUser] = 1
else
selfSay('You already did your mission.', cid)
end
elseif(msgcontains(msg, 'yes')) and talkState[talkUser] == 1 then
if getPlayerStorageValue(cid, config.npcstorage) == -1 then
selfSay('Lets see if you can make it!', cid)
doPlayerSetStorageValue(cid, config.npcstorage, 1)
talkState[talkUser] = 0
return true
end
if getPlayerStorageValue(cid, config.npcstorage) == 1 and getPlayerStorageValue(cid, config.killstorage) >= config.amountkills then
selfSay('Well, didn\'t expected it, but well done, here is your reward.', cid)
db.executeQuery('UPDATE accounts SET premium_points=premium_points+'..config.rewardpoints..' WHERE id=' .. getPlayerAccountId(cid))
doPlayerAddExp(cid, config.rewardexp)
doPlayerSetStorageValue(cid, config.npcstorage, 2)
talkState[talkUser] = 0
else
selfSay('You killed '..(getPlayerStorageValue(cid, config.killstorage) +1)..' players, you need to kill '..config.amountkills..'!', cid)
talkState[talkUser] = 0
end
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
talkState[talkUser] = 0
selfSay('I knew you were not strong enough!', cid)
end
return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
[07/06/2015 18:59:04] [Error - LuaScriptInterface::loadFile] data/npc/scripts/darkskull.lua:6: function arguments expected near ':'
[07/06/2015 18:59:04] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/darkskull.lua
[07/06/2015 18:59:04] data/npc/scripts/darkskull.lua:6: function arguments expected near ':'

whats this error? and how to solv?
 
You will have this with every NPC that is posted without code tags, it's because
Code:
:o
Will be changed to a :eek: smiley without code tags.
So you can just change it back or copy paste those 4 lines from an other NPC Lua script.
Code:
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
 
Part 5 - Different kinds of missions



Monster mission

Dragon.gif


When you want a mission that's not about items, for example with killing monsters, it's not so much different than an items mission.
Only now instead of checking if a player has an item, you check if a player killed monsters.

There are functions to find out if a player has items, but there is no function to find out if a player has killed monsters, that's why you have to add storagevalues when killing the monsters, so you can check for that storagevalue in the NPC.
This can't be done in an NPC, since an NPC has no influence on what you kill, so you have to make an extra script in creaturescripts with function onKill.
For example you want a mission where someone has to kill 5 dragons and 3 dragons lords (if you want more or less monsters, you can just add or remove lines in local config).

Code:
local config = {
     ['dragon'] = {amount = 5, storage = 19000, startstorage = 5002, startvalue = 1},
     ['dragon lord'] = {amount = 3, storage = 19001, startstorage = 5002, 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

The startstorage is the storage from the NPC with value 1, so this means the script will start counting after accepting the mission.
The other storage, named storage, is to count the monsters.


Now in the NPC, instead of checking if a player has an item, you check for the value of the storage you use used to count the monsters.
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 not npcHandler:isFocused(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
             selfSay("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
             selfSay("Did you kill 5 dragons and 3 dragon lords?", cid)
             talkState[talkUser] = 1
         else
             selfSay("You already did the mission.", cid)
         end
     elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
         if getPlayerStorageValue(cid, storage) == -1 then
             selfSay("Good, come back when you killed them.", cid)
             setPlayerStorageValue(cid, storage, 1)
         else
             if getPlayerStorageValue(cid, 19000) == 5 and getPlayerStorageValue(cid, 19001) == 3 then
                 selfSay("Good job, here is your reward.", cid)
                 doPlayerAddItem(cid, 2160, 5)
                 doPlayerAddExp(cid, 50000)
                 setPlayerStorageValue(cid, storage, 2)
             else
                 selfSay("You didn't kill them all.", cid)
             end
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
         selfSay("Ok then.", cid)
         talkState[talkUser] = 0
     end
     return true
end

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

How do i put this in the quest log so you can see how many dragons or in my case Trolls i've killed?

edit:
I did apply it to the server and got this error
erc45v.png


in the creaturescripts xml
Code:
    <event type="onKill" name="troll_mission" event="script" value="trollmission.lua"/>

and the creaturescrips/scripts/trollmission.lua
Code:
local config = {
     ['troll'] = {amount = 25, storage = 19000, startstorage = 5002, startvalue = 1},
     ['troll champion'] = {amount = 10, storage = 19001, startstorage = 5002, 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
 
Last edited:
How do i put this in the quest log so you can see how many dragons or in my case Trolls i've killed?

edit:
I did apply it to the server and got this error
erc45v.png


in the creaturescripts xml
Code:
    <event type="onKill" name="troll_mission" event="script" value="trollmission.lua"/>

and the creaturescrips/scripts/trollmission.lua
Code:
local config = {
     ['troll'] = {amount = 25, storage = 19000, startstorage = 5002, startvalue = 1},
     ['troll champion'] = {amount = 10, storage = 19001, startstorage = 5002, 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
Looked into it thoroughly.. and unfortunately there's no quick way that I can see.
https://otland.net/threads/quest-log-killing-in-the-name-of-help-me.83155/
(for TFS 0.3.7 and similar it's located "data/xml/quests")

At your other problem..
Code:
<event type="onKill" name="troll_mission" event="script" value="trollmission.lua"/> -- incorrect
<event type="kill" name="troll_mission" event="script" value="trollmission.lua"/> -- correct

Code:
types of creaturescripts that I can think of off-hand..
   advance
   cast
   channeljoin
   combat
   death
   kill
   login
   look
   mailreceive
   preparedeath
   reportbug
   statschange
   thankyou
   think
   throw
 
It does not work for me :/ i think i added everything right.

in the creaturescripts xml
Code:
    <event type="kill" name="troll_mission" event="script" value="trollmission.lua"/>

and the creaturescrips/scripts/trollmission.lua
Code:
local config = {
     ['troll'] = {amount = 25, storage = 19000, startstorage = 5002, startvalue = 1},
     ['troll champion'] = {amount = 10, storage = 19001, startstorage = 5002, 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

then i also added this to the data/lib/050-function.lua
Code:
function isSummon(cid)
return (isCreature(cid) == TRUE and (getCreatureMaster(cid) ~= cid)) and TRUE or FALSE
end

i can speak with the npc and i can accept the quest, but it does not count my kills and i dont get any massage that i've killed 1/25 trolls
when i did kill enough to make the quest i go back to the npc and he says " You haven't killed them all.

here is npc script
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Tomas" script="Tomas.lua" speed="100" walkinterval="2000" floorchange="0">
   <health now="100" max="100"/>
   <look type="129" head="78" body="20" legs="116" feet="38" addons="1"/>
   <parameters>
     <parameter key="message_greet" value="Hello |PLAYERNAME|, can you do me a {favor}?"/>
   </parameters>
</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 not npcHandler:isFocused(cid) then
         return false
     end
     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

     if msgcontains(msg, "favor") then
         if getPlayerStorageValue(cid, storage) == -1 then
             selfSay("I have a mission for you, to kill 25 trolls and 10 troll champions, do you accept?", cid)
             talkState[talkUser] = 1
         elseif getPlayerStorageValue(cid, storage) == 1 then
             selfSay("Did you kill 25 trolls and 10 troll champions?", cid)
             talkState[talkUser] = 1
         else
             selfSay("You already did the mission.", cid)
         end
     elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
         if getPlayerStorageValue(cid, storage) == -1 then
             selfSay("Thank you, the trolls has been harassing this village for to long", cid)
             setPlayerStorageValue(cid, storage, 1)
         else
             if getPlayerStorageValue(cid, 19000) == 5 and getPlayerStorageValue(cid, 19001) == 3 then
                 selfSay("Good job, here is your reward. go to the anvil at Darnells shop and use this.", cid)
                 doPlayerAddItem(cid, 2225, 1)
                 setPlayerStorageValue(cid, storage, 2)
             else
                 selfSay("You didn't kill them all.", cid)
             end
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
         selfSay("Ok then.", cid)
         talkState[talkUser] = 0
     end
     return true
end

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