• 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 Reward for each vocation

Joined
Apr 11, 2015
Messages
102
Reaction score
6
0.4
Hello my dudes, i am here to ask for a help. I got a NPC script that reward a player when the task is finished. What I'd like is: When a Druid talk to the following NPC and finish the task, he would get a SnakeBite Rod, and if were a Sorcerer, he would get a "Wand of Vortex". Here is my NPC:

C++:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local talkState = {}
local quest = 22542
local reward = 70000

local markTable = {
--    {markPos =
    {markPos = {x = , y = , z = }, markType = MAPMARK_SWORD, markDescription = ""}
}


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)
if(not npcHandler:isFocused(cid)) then
        return false
    end
    
    local func_addMark = doPlayerAddMapMark
    if(not func_addMark) then
      func_addMark = doAddMapMark
    end
 
    if(msgcontains(msg, "")) then
        for mark, x in pairs(markTable) do
            func_addMark(cid, x.markPos, x.markType, x.markDescription ~= nil and x.markDescription or "")
        end
        selfSay("", cid)
    end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if(not npcHandler:isFocused(cid)) then
    return false
elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
    npcHandler:say("", cid)
    talkState[talkUser] = 2
elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then
    npcHandler:say("", cid)
    setPlayerStorageValue(cid, quest, 2)
    talkState[talkUser] = 0
elseif msgcontains(msg, "") then
    local str = getPlayerStorageValue(cid, quest)
    if(str < 2) then
        npcHandler:say("", cid)
        talkState[talkUser] = 1
        return true
    elseif(str == 2) then
        npcHandler:say("", cid)
    elseif(str == 3) then
        npcHandler:say("", cid)
        doPlayerAddExp(cid, 10000)
        doPlayerAddItem(cid,2182,1)
        doPlayerAddItem(cid,8820,1)
        setPlayerStorageValue(cid, quest, 4)
    elseif(str == 4) then
        npcHandler:say("", cid)
    end
    talkState[talkUser] = 0
end
return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
elseif(str == 3) and isKnight(cid) then
npcHandler:say("", cid) doPlayerAddExp(cid, 10000) doPlayerAddItem(cid,2182,1) doPlayerAddItem(cid,8820,1) setPlayerStorageValue(cid, quest, 4)
etc, etc.
elseif(str == 3) and isKnight(cid) then
npcHandler:say("", cid) doPlayerAddExp(cid, 10000) doPlayerAddItem(cid,2182,1) doPlayerAddItem(cid,8820,1) setPlayerStorageValue(cid, quest, 4)
etc, etc.
 
Solution
Actually, @KazushiMetaxa I have created a new vocation, and when I use "isCrusader" I get the following error in console:
data/npc/scripts/task.lua:54: attempt to call global 'isCrusader' (a nil value)

Is there any way to use the vocation ID instead of their name? Or there is another way to use it?
 
Actually, @KazushiMetaxa I have created a new vocation, and when I use "isCrusader" I get the following error in console:
data/npc/scripts/task.lua:54: attempt to call global 'isCrusader' (a nil value)

Is there any way to use the vocation ID instead of their name? Or there is another way to use it?
you could add isCrusader() to your server
add this, just remember to change 4 and 8 to the vocation ids you use for you crusader vocation
data\lib\031-vocations.lua
Lua:
function isCrusader(cid)
    return isInArray({4, 8}, getPlayerVocation(cid))
end
 
Back
Top