• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

2 Npc mission

kamilcioo

Veteran OT User
Joined
Jul 25, 2008
Messages
979
Solutions
1
Reaction score
291
First npc.

Player: Hi
Npc: Hi, i have mission for you
Player: quest
Npc: You must kill 5000 aniol. Come back when you will do this and say killed.
Player: killed
Npc: Great. Take this 250cc and 250 milions of experience


Second npc.

Player: Hi
Npc: Hi, i have mission for you
Player: quest
Npc: You must kill 10000 archaniol. Come back when you will do this and say killed.
Player: killed
Npc: Great. Take this 450cc and 500 milions of experience
 
First we go to data/creaturescripts/scripts and make file tasks_system.lua and paste this:
PHP:
local main_storage = 10005
local bosses_storage = 10006
local config = {    
    ["aniol"] = {storage = 9899, mob_storage = 19899, race_name = "trolls", begin_storage_value = 1, finished_storage_value = 2, count = 5000},
    ["archaniol"] = {storage = 9899, mob_storage = 19898, race_name = "trolls", begin_storage_value = 1, finished_storage_value = 2, count = 10000},
 }
function onKill(cid, target)
local mob = config[string.lower(getCreatureName(target))]
if not(mob and isPlayer(target) ~= true) then
    return true
end
local count_monsters = getPlayerStorageValue(cid, mob.storage)
local mob_storages = getPlayerStorageValue(cid, mob.mob_storage)
for k, v in pairs(config) do
    if count_monsters == 0 or mob_storages == -1 then
        if getPlayerStorageValue(cid, main_storage) == v.begin_storage_value then
            doPlayerSetStorageValue(cid, v.mob_storage, 0)
        end
    end
end
    if getPlayerStorageValue(cid, main_storage) == mob.begin_storage_value and count_monsters <= mob.count then
        doPlayerSetStorageValue(cid, mob.storage, getPlayerStorageValue(cid, mob.storage) + 1)
        doPlayerSetStorageValue(cid, mob.mob_storage, getPlayerStorageValue(cid, mob.mob_storage) + 1)
            x = 0
            s = "You killed "
            for k, v in pairs(config) do
                if getPlayerStorageValue(cid, main_storage) == v.begin_storage_value then
                    if s ~= "You killed " then
                        s = s .. " "
                    end
                    count = getPlayerStorageValue(cid, v.mob_storage)
                    
                    if count < 0 then
                        count = 0
                    end

                    s = s ..count.." " .. k .. ","
                    x = x + count
                end
            end

            s = string.sub(s, 1, string.len(s) - 1)..". You have killed " .. x .." of ".. mob.count .." "..mob.race_name.."."
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, s)
            if x == mob.count then 
                doPlayerSetStorageValue(cid, main_storage, mob.finished_storage_value)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Congratulations! You have killed enough "..mob.race_name..".")
                if getPlayerStorageValue(cid, main_storage) == mob.finished_storage_value then
                    for k, v in pairs(config) do
                        if getPlayerStorageValue(cid, v.mob_storage) > 0 then
                            doPlayerSetStorageValue(cid, v.mob_storage, 0)
                        end
                        if getPlayerStorageValue(cid, v.storage) > 0 then
                            doPlayerSetStorageValue(cid, v.storage, 0)
                        end
                    end
                end
            end
    elseif getPlayerStorageValue(cid, bosses_storage) == mob.begin_boss_storage_value and isInArray({-1,0}, count_monsters) then
        doPlayerSetStorageValue(cid, bosses_storage, mob.finished_storage_value)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Congratulations! You have killed "..getCreatureName(target)..".")
    end
    return true
end
Now open login.lua and before return true paste this:
PHP:
registerCreatureEvent(cid, "Task_System")
Now open creaturescripts.xml and after:
PHP:
<?xml version="1.0" encoding="UTF-8"?>
<creaturescripts>
Paste this:
PHP:
<event type="kill" name="Task_System" event="script" value="tasks_system.lua"/>
Now we go to data/NPC/scripts and create tasks_system.lua and paste this:
PHP:
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 say(param)
            npcHandler:say(param.text,param.cid)
         end
    function delayedSay(text, delay, cid)
    if(not npcHandler:isFocused(cid)) then
                return FALSE
     else
         local param = {cid = cid, text = text}
            local delay = delay or 0
            addEvent(say, delay, param)
        end
    end
function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
    return false
end
local main_storage = 10005
local bosses_storage = 10006
local getStorage = getPlayerStorageValue(cid, main_storage)
local getStorages = getPlayerStorageValue(cid, bosses_storage)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local good_hunting = {"Happy hunting, old chap! Come back to me when you are through with your {task}.", "Good show, old chap! Speak to me again when you are done hunting."}    
local good_job = {"That took some time, huh? Good hunting though. If you're up for another hunting mission just ask me for a {task}.", "If you're up for another hunting mission just ask me for a {task}."}
local tasks = {
            [1] = {name = "aniol", storage = 9899, min_level = 8, max_level = 200, 
                    first = "yes", first_rewards = {type = "money", reward = 0, count = 250000},
                    second = "yes", second_rewards = {type = "exp", reward = 0, count = 25000000},
                    third = "no", third_rewards = {type = 0, reward = , count = 0},
                    begin_storage_value = 1, finish_storage_value = 2, boss = "yes", before_kill_boss = 0, after_kill_boss = 0, talkstate = 1},
            [2] = {name = "archaniol", storage = 9898, min_level = 10, max_level = 2000, 
                    first = "yes", first_rewards = {type = "money", reward = 0, count = 450000},
                    second = "yes", second_rewards = {type = "exp", reward = 0, count = 5000000},
                    third = "no", third_rewards = {type = 0, reward = 0, count = 0},
                    begin_storage_value = 3, finish_storage_value = 4, boss = "no", before_kill_boss = 0, after_kill_boss = 0, talkstate = 2}
            }
s = "All right, what would you like to hunt - "
for k, v in pairs(tasks) do
    if (getPlayerLevel(cid) >= v.min_level and getPlayerLevel(cid) <= v.max_level) then
        s = s.."{"..v.name..",} "
    end
end
s = string.sub(s, 1, string.len(s) - 3).."."
if msgcontains(msg, "task") then
    if getStorage <= 0 then
        selfSay(s, cid)
        talkState[talkUser] = 100
    end
elseif msgcontains(msg, "cancel") then
    if getStorage > 0 then
        selfSay("Do you want cancel actual mission?", cid)
        talkState[talkUser] = 101
    else
        selfSay("You don't have started any task!", cid)
        return true
    end
end
for i = 1, #tasks do
    if msgcontains(msg, tasks[i].name) and talkState[talkUser] == 100 then
        if (getPlayerLevel(cid) >= tasks[i].min_level and getPlayerLevel(cid) <= tasks[i].max_level) then
            selfSay("Do you want hunt "..tasks[i].name.."?", cid)
            talkState[talkUser] = tasks[i].talkstate
        else
            selfSay("You do not have enough level.", cid)
            return true
        end
    elseif msgcontains(msg, "yes") and talkState[talkUser] == tasks[i].talkstate then
        doPlayerSetStorageValue(cid, main_storage, tasks[i].begin_storage_value)
        selfSay(good_hunting[math.random(1, #good_hunting)], cid)
        doPlayerSetStorageValue(cid, tasks[i].storage, 0)
    elseif msgcontains(msg, "task") then
        if getStorage == tasks[i].finish_storage_value and getStorages < tasks[i].before_kill_boss then
            if tasks[i].boss == "yes" then
                selfSay("Good job, go kill boss.", cid)
                doPlayerSetStorageValue(cid, bosses_storage, tasks[i].before_kill_boss)
            else 
                doPlayerSetStorageValue(cid, bosses_storage, -1)
                doPlayerSetStorageValue(cid, main_storage, -1)
                doPlayerSetStorageValue(cid, tasks[i].storage, -1)
                selfSay(good_job[math.random(1, #good_job)], cid)
                if tasks[i].first == "yes" then
                    if tasks[i].first_rewards.type == "item" then
                        doPlayerAddItem(cid, tasks[i].first_rewards.reward, tasks[i].first_rewards.count, true)
                    elseif tasks[i].first_rewards.type == "exp" then
                        doPlayerAddExperience(cid, tasks[i].first_rewards.count)
                        doSendAnimatedText(getPlayerPosition(cid), tasks[i].first_rewards.count, TEXTCOLOR_WHITE)
                    elseif tasks[i].first_rewards.type == "storage" then
                        doPlayerSetStorageValue(cid, tasks[i].first_rewards.reward, tasks[i].first_rewards.count)
                    elseif tasks[i].first_rewards.type == "money" then
                        doPlayerAddMoney(cid, tasks[i].first_rewards.count)
                    elseif tasks[i].first_rewards.type == "skill" then
                        doPlayerAddSkill(cid, tasks[i].first_rewards.reward, tasks[i].first_rewards.count)
                    elseif tasks[i].first_rewards.type == "addon" then
                        doPlayerAddOutfit(cid, tasks[i].first_rewards.reward[1], tasks[i].first_rewards.count)
                        doPlayerAddOutfit(cid, tasks[i].first_rewards.reward[2], tasks[i].first_rewards.count)
                    end
                end
                if tasks[i].second == "yes" then
                    if tasks[i].second_rewards.type == "item" then
                        doPlayerAddItem(cid, tasks[i].second_rewards.reward, tasks[i].second_rewards.count, true)
                    elseif tasks[i].second_rewards.type == "exp" then
                        doPlayerAddExperience(cid, tasks[i].second_rewards.count)
                        doSendAnimatedText(getPlayerPosition(cid), tasks[i].second_rewards.count, TEXTCOLOR_WHITE)
                    elseif tasks[i].second_rewards.type == "storage" then
                        doPlayerSetStorageValue(cid, tasks[i].second_rewards.reward, tasks[i].second_rewards.count)
                    elseif tasks[i].second_rewards.type == "money" then
                        doPlayerAddMoney(cid, tasks[i].second_rewards.count)
                    elseif tasks[i].second_rewards.type == "skill" then
                        doPlayerAddSkill(cid, tasks[i].second_rewards.reward, tasks[i].second_rewards.count)
                    elseif tasks[i].second_rewards.type == "addon" then
                        doPlayerAddOutfit(cid, tasks[i].second_rewards.reward[1], tasks[i].second_rewards.count)
                        doPlayerAddOutfit(cid, tasks[i].second_rewards.reward[2], tasks[i].second_rewards.count)
                    end
                end
                if tasks[i].third == "yes" then
                    if tasks[i].third_rewards.type == "item" then
                        doPlayerAddItem(cid, tasks[i].third_rewards.reward, tasks[i].third_rewards.count, true)
                    elseif tasks[i].third_rewards.type == "exp" then
                        doPlayerAddExperience(cid, tasks[i].third_rewards.count)
                        doSendAnimatedText(getPlayerPosition(cid), tasks[i].third_rewards.count, TEXTCOLOR_WHITE)
                    elseif tasks[i].third_rewards.type == "storage" then
                        doPlayerSetStorageValue(cid, tasks[i].third_rewards.reward, tasks[i].third_rewards.count)
                    elseif tasks[i].third_rewards.type == "money" then
                        doPlayerAddMoney(cid, tasks[i].third_rewards.count)
                    elseif tasks[i].third_rewards.type == "skill" then
                        doPlayerAddSkill(cid, tasks[i].third_rewards.reward, tasks[i].third_rewards.count)
                    elseif tasks[i].third_rewards.type == "addon" then
                        doPlayerAddOutfit(cid, tasks[i].third_rewards.reward[1], tasks[i].third_rewards.count)
                        doPlayerAddOutfit(cid, tasks[i].third_rewards.reward[2], tasks[i].third_rewards.count)
                    end
                end
            end
        elseif getStorages == tasks[i].after_kill_boss then
            doPlayerSetStorageValue(cid, bosses_storage, -1)
            doPlayerSetStorageValue(cid, main_storage, -1)
            doPlayerSetStorageValue(cid, tasks[i].storage, -1)
            selfSay(good_job[math.random(1, #good_job)], cid)
                if tasks[i].first == "yes" then
                    if tasks[i].first_rewards.type == "item" then
                        doPlayerAddItem(cid, tasks[i].first_rewards.reward, tasks[i].first_rewards.count, true)
                    elseif tasks[i].first_rewards.type == "exp" then
                        doPlayerAddExperience(cid, tasks[i].first_rewards.count)
                        doSendAnimatedText(getPlayerPosition(cid), tasks[i].first_rewards.count, TEXTCOLOR_WHITE)
                    elseif tasks[i].first_rewards.type == "storage" then
                        doPlayerSetStorageValue(cid, tasks[i].first_rewards.reward, tasks[i].first_rewards.count)
                    elseif tasks[i].first_rewards.type == "money" then
                        doPlayerAddMoney(cid, tasks[i].first_rewards.count)
                    elseif tasks[i].first_rewards.type == "skill" then
                        doPlayerAddSkill(cid, tasks[i].first_rewards.reward, tasks[i].first_rewards.count)
                    elseif tasks[i].first_rewards.type == "addon" then
                        doPlayerAddOutfit(cid, tasks[i].first_rewards.reward[1], tasks[i].first_rewards.count)
                        doPlayerAddOutfit(cid, tasks[i].first_rewards.reward[2], tasks[i].first_rewards.count)
                    end
                end
                if tasks[i].second == "yes" then
                    if tasks[i].second_rewards.type == "item" then
                        doPlayerAddItem(cid, tasks[i].second_rewards.reward, tasks[i].second_rewards.count, true)
                    elseif tasks[i].second_rewards.type == "exp" then
                        doPlayerAddExperience(cid, tasks[i].second_rewards.count)
                        doSendAnimatedText(getPlayerPosition(cid), tasks[i].second_rewards.count, TEXTCOLOR_WHITE)
                    elseif tasks[i].second_rewards.type == "storage" then
                        doPlayerSetStorageValue(cid, tasks[i].second_rewards.reward, tasks[i].second_rewards.count)
                    elseif tasks[i].second_rewards.type == "money" then
                        doPlayerAddMoney(cid, tasks[i].second_rewards.count)
                    elseif tasks[i].second_rewards.type == "skill" then
                        doPlayerAddSkill(cid, tasks[i].second_rewards.reward, tasks[i].second_rewards.count)
                    elseif tasks[i].second_rewards.type == "addon" then
                        doPlayerAddOutfit(cid, tasks[i].second_rewards.reward[1], tasks[i].second_rewards.count)
                        doPlayerAddOutfit(cid, tasks[i].second_rewards.reward[2], tasks[i].second_rewards.count)
                    end
                end
                if tasks[i].third == "yes" then
                    if tasks[i].third_rewards.type == "item" then
                        doPlayerAddItem(cid, tasks[i].third_rewards.reward, tasks[i].third_rewards.count, true)
                    elseif tasks[i].third_rewards.type == "exp" then
                        doPlayerAddExperience(cid, tasks[i].third_rewards.count)
                        doSendAnimatedText(getPlayerPosition(cid), tasks[i].third_rewards.count, TEXTCOLOR_WHITE)
                    elseif tasks[i].third_rewards.type == "storage" then
                        doPlayerSetStorageValue(cid, tasks[i].third_rewards.reward, tasks[i].third_rewards.count)
                    elseif tasks[i].third_rewards.type == "money" then
                        doPlayerAddMoney(cid, tasks[i].third_rewards.count)
                    elseif tasks[i].third_rewards.type == "skill" then
                        doPlayerAddSkill(cid, tasks[i].third_rewards.reward, tasks[i].third_rewards.count)
                    elseif tasks[i].third_rewards.type == "addon" then
                        doPlayerAddOutfit(cid, tasks[i].third_rewards.reward[1], tasks[i].third_rewards.count)
                        doPlayerAddOutfit(cid, tasks[i].third_rewards.reward[2], tasks[i].third_rewards.count)
                    end
                end
        elseif getStorage == tasks[i].begin_storage_value then
            selfSay("You have kill "..getPlayerStorageValue(cid, tasks[i].storage).." "..tasks[i].name..".", cid)
        elseif getStorages == tasks[i].before_kill_boss then
            selfSay("You do not kill boss yet.", cid)
            return true
        end
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 101 then
        if getStorage > 0 then
            selfSay("Speak to me again when you are done hunting.", cid)
            doPlayerSetStorageValue(cid, main_storage, -1)
            doPlayerSetStorageValue(cid, tasks[i].storage, -1)
            return true
        end
    elseif msgcontains(msg, "no") and isInArray({i, 100, 101}, talkState[talkUser]) then
        selfSay("Ok then.", cid)
        return true
    end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

i hope its work if i helped rep++
 
I have this bug

[01/03/2011 19:37:36] [Error - LuaScriptInterface::loadFile] data/npc/scripts/archaniol quest.lua:36: unexpected symbol near ','
[01/03/2011 19:37:36] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/archaniol quest.lua
[01/03/2011 19:37:36] data/npc/scripts/archaniol quest.lua:36: unexpected symbol near ','
 
Back
Top