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

Check vocation npc

Slafesko

New Member
Joined
Jan 6, 2016
Messages
101
Reaction score
2
I am using this script
Code:
https://pastebin.com/kwDvSa9V
that teleport players to area x but there is a problem with it, and i gonna explain it with spoilers
19:56 Freezer Clayous: Hello Sasdas I can teleport You to special area Cold Area for 20 gold nugget. Would You like to travel there?
19:56 Sasdas [3020]: cold area
19:56 Freezer Clayous: I am sorry you are either not a level 2000 Elder Druid or you don't have 20 gold nugget and it costs 20 gold nugget to travel.
20:37 You see yourself. You are Elder Druid.
And if i get for example vocation id 10 2nd promotion of druid won't work too.
using tfs 0.4
 
Try this one out.
Code:
local config = {
   ["cold area"] = {level = 2000, vocationid = {6, 10, 14, 18}, vocationname = "Elder Druid", "Natural Priest", "Priest", "Guardian Angel", amount = 20, itemid = 2157, location = {x = 1043, y = 621, z = 10}},
}

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState, xmsg = {}, {}
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 creatureSayCallback(cid, type, msg)
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
     local tm = config[msg:lower()]
     if msgcontains(msg, "bring me to") then
         for mes, t in pairs(config) do
             if msgcontains(msg, mes) then
                if isPlayerPzLocked(cid) == true then
                    doPlayerSendTextMessage(cid,MESSAGE_STATUS_SMALL,"Those hands look pretty bloody")
                    npcHandler:say("Hah, Seems like you got blood on your hands you shall not sail with me.", cid)
                    return false
                end
                    if doPlayerRemoveItem(cid, t.itemid, t.amount) and getPlayerVocation(cid) == t.vocationid and getPlayerLevel(cid) <= t.level then
                        npcHandler:say("You are a level ".. t.level .. " ".. t.vocationname .." and you paid ".. t.amount .." ".. getItemNameById(t.itemid) .." to travel and you have ".. getPlayerItemCount(cid, t.itemid) .." ".. getItemNameById(t.itemid) .." left in your backpack", cid)
                        doTeleportThing(cid, t.location)
                    else
                     npcHandler:say("I am sorry you are not a level ".. t.level .. " ".. t.vocationname .." or you don't have ".. getPlayerItemCount(cid, t.itemid) .." ".. getItemNameById(t.itemid) .." and it costs ".. t.amount .." ".. getItemNameById(t.itemid) .." to travel.", cid)
                end
             end
         end
     elseif tm then
         if getPlayerItemCount(cid, tm.itemid) >= tm.amount and getPlayerVocation(cid) == tm.vocationid and getPlayerLevel(cid) >= tm.level then
             npcHandler:say("Do you want to go to ".. msg .." for ".. tm.amount .." ".. getItemNameById(tm.itemid) .."? ... you do have ".. getPlayerItemCount(cid, tm.itemid) .." ".. getItemNameById(tm.itemid) .."! You also need to be a level ".. tm.level .. " ".. tm.vocationname ..".", cid)
             talkState[talkUser] = 1
             xmsg[cid] = msg
         else
             npcHandler:say("I am sorry you are either not a level ".. tm.level .. " ".. tm.vocationname .." or you don't have ".. tm.amount .." ".. getItemNameById(tm.itemid) .." and it costs ".. tm.amount .." ".. getItemNameById(tm.itemid) .." to travel.", cid)
         end
     elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
         local tm = config[xmsg[cid]:lower()]
                if isPlayerPzLocked(cid) == true then
                    doPlayerSendTextMessage(cid,MESSAGE_STATUS_SMALL,"Those hands look pretty bloody")
                    npcHandler:say("Hah, Seems like you got blood on your hands you shall not sail with me.", cid)
                    return false
                end
         if doPlayerRemoveItem(cid, tm.itemid, tm.amount) and getPlayerVocation(cid) == tm.vocationid and getPlayerLevel(cid) >= tm.level then
             npcHandler:say("You are a level ".. tm.level .. " ".. tm.vocationname .." and you paid ".. tm.amount .." ".. getItemNameById(tm.itemid) .." to travel and you have ".. getPlayerItemCount(cid, tm.itemid) .." ".. getItemNameById(tm.itemid) .." left in your backpack", cid)
             doTeleportThing(cid, tm.location)
         else
             npcHandler:say("I am sorry you are either not a level ".. tm.level .. " ".. tm.vocationname .." or you don't have ".. getPlayerItemCount(cid, tm.itemid) .." ".. getItemNameById(tm.itemid) .." and it costs ".. tm.amount .." ".. getItemNameById(tm.itemid) .." to travel.", cid)
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, 'no') and talkState[talkUser] == 1 then
         npcHandler:releaseFocus(cid)
         selfSay("Oh well, I guess not then.", cid)
     end
     return true
    end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
extra talkState on line 9 that needs to be removed.

Currently, the vocationname will always choose 'Elder Druid', because the names aren't in an array.
I'd change vocationname to "promoted druid" so the cancel message will make sense no matter what promotion status the player is at.

Depending on how the vocations are setup, you will either want to check their current vocation, or the promotion status of the player.

If you are checking for the promotion status, just check to see if it's above 0.

If you are checking for the vocation you should use the isInArray function.., OR
If you put the vocationname into an array, (which I don't recommend for this script) you could loop through the array checking the player vocation, and using the same array value to send the correct vocationname.
 
Try this one out.
Code:
local config = {
   ["cold area"] = {level = 2000, vocationid = {6, 10, 14, 18}, vocationname = "Elder Druid", "Natural Priest", "Priest", "Guardian Angel", amount = 20, itemid = 2157, location = {x = 1043, y = 621, z = 10}},
}

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState, xmsg = {}, {}
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 creatureSayCallback(cid, type, msg)
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
     local tm = config[msg:lower()]
     if msgcontains(msg, "bring me to") then
         for mes, t in pairs(config) do
             if msgcontains(msg, mes) then
                if isPlayerPzLocked(cid) == true then
                    doPlayerSendTextMessage(cid,MESSAGE_STATUS_SMALL,"Those hands look pretty bloody")
                    npcHandler:say("Hah, Seems like you got blood on your hands you shall not sail with me.", cid)
                    return false
                end
                    if doPlayerRemoveItem(cid, t.itemid, t.amount) and getPlayerVocation(cid) == t.vocationid and getPlayerLevel(cid) <= t.level then
                        npcHandler:say("You are a level ".. t.level .. " ".. t.vocationname .." and you paid ".. t.amount .." ".. getItemNameById(t.itemid) .." to travel and you have ".. getPlayerItemCount(cid, t.itemid) .." ".. getItemNameById(t.itemid) .." left in your backpack", cid)
                        doTeleportThing(cid, t.location)
                    else
                     npcHandler:say("I am sorry you are not a level ".. t.level .. " ".. t.vocationname .." or you don't have ".. getPlayerItemCount(cid, t.itemid) .." ".. getItemNameById(t.itemid) .." and it costs ".. t.amount .." ".. getItemNameById(t.itemid) .." to travel.", cid)
                end
             end
         end
     elseif tm then
         if getPlayerItemCount(cid, tm.itemid) >= tm.amount and getPlayerVocation(cid) == tm.vocationid and getPlayerLevel(cid) >= tm.level then
             npcHandler:say("Do you want to go to ".. msg .." for ".. tm.amount .." ".. getItemNameById(tm.itemid) .."? ... you do have ".. getPlayerItemCount(cid, tm.itemid) .." ".. getItemNameById(tm.itemid) .."! You also need to be a level ".. tm.level .. " ".. tm.vocationname ..".", cid)
             talkState[talkUser] = 1
             xmsg[cid] = msg
         else
             npcHandler:say("I am sorry you are either not a level ".. tm.level .. " ".. tm.vocationname .." or you don't have ".. tm.amount .." ".. getItemNameById(tm.itemid) .." and it costs ".. tm.amount .." ".. getItemNameById(tm.itemid) .." to travel.", cid)
         end
     elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
         local tm = config[xmsg[cid]:lower()]
                if isPlayerPzLocked(cid) == true then
                    doPlayerSendTextMessage(cid,MESSAGE_STATUS_SMALL,"Those hands look pretty bloody")
                    npcHandler:say("Hah, Seems like you got blood on your hands you shall not sail with me.", cid)
                    return false
                end
         if doPlayerRemoveItem(cid, tm.itemid, tm.amount) and getPlayerVocation(cid) == tm.vocationid and getPlayerLevel(cid) >= tm.level then
             npcHandler:say("You are a level ".. tm.level .. " ".. tm.vocationname .." and you paid ".. tm.amount .." ".. getItemNameById(tm.itemid) .." to travel and you have ".. getPlayerItemCount(cid, tm.itemid) .." ".. getItemNameById(tm.itemid) .." left in your backpack", cid)
             doTeleportThing(cid, tm.location)
         else
             npcHandler:say("I am sorry you are either not a level ".. tm.level .. " ".. tm.vocationname .." or you don't have ".. getPlayerItemCount(cid, tm.itemid) .." ".. getItemNameById(tm.itemid) .." and it costs ".. tm.amount .." ".. getItemNameById(tm.itemid) .." to travel.", cid)
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, 'no') and talkState[talkUser] == 1 then
         npcHandler:releaseFocus(cid)
         selfSay("Oh well, I guess not then.", cid)
     end
     return true
    end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Didn't work ,s
extra talkState on line 9 that needs to be removed.

Currently, the vocationname will always choose 'Elder Druid', because the names aren't in an array.
I'd change vocationname to "promoted druid" so the cancel message will make sense no matter what promotion status the player is at.

Depending on how the vocations are setup, you will either want to check their current vocation, or the promotion status of the player.

If you are checking for the promotion status, just check to see if it's above 0.

If you are checking for the vocation you should use the isInArray function.., OR
If you put the vocationname into an array, (which I don't recommend for this script) you could loop through the array checking the player vocation, and using the same array value to send the correct vocationname.
gonna try again and i'll see ;S
 
Back
Top