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

converter for tfs 1.2 with level agreement and vocation

Mateus Robeerto

Excellent OT User
Joined
Jun 5, 2016
Messages
1,337
Solutions
71
Reaction score
697
Location
ლ(ಠ益ಠლ)
when I talk to npc but he doesn't answer anything!! it helps me plx ty


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



-- OTServ event handling functions start
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
-- OTServ event handling functions end

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

    if msgcontains(msg, 'bramun') then
    if getPlayerLevel(cid) < 100 then
        selfSay('Do you wish to travel to Bramun for 500 gold coins?')
        talk_state = 2
    else
        selfSay('I only can travel to there on level 8 to 99.')
    end

    elseif msgcontains(msg, 'canudis') then
    if getPlayerLevel(cid) > 99 and getPlayerLevel(cid) < 200 then
        selfSay('Do you wish to travel to Canudis for 1000 gold coins?')
        talk_state = 3
    else
        selfSay('I only can travel to there on level 100 to 199.')
    end

    elseif msgcontains(msg, 'morgun') then
    if getPlayerLevel(cid) > 199 and getPlayerLevel(cid) < 300 then
        selfSay('Do you wish to travel to Morgun for 2000 gold coins?')
        talk_state = 4
    else
        selfSay('I only can travel to there on level 200 to 299.')
    end

    elseif msgcontains(msg, 'mordor') then
    if getPlayerVocation(cid) > 8 then
        selfSay('Do you wish to travel to Mordor for 5000 gold coins?')
        talk_state = 5
    else
        selfSay('I only Valans can travel to there.')
    end
    
    elseif msgcontains(msg, 'tan53oris') then
    if getPlayerVocation(cid) > 12 then
        selfSay('Do you wish to travel to tanoris for 100 DSPs?')
        talk_state = 6
    else
        selfSay('I only gods can travel to there.')
    end
--

    elseif talk_state == 2 then
        if msgcontains(msg, 'yes') then
        if talk_state == 2 then
        if isPremium(cid) then
        if getPlayerLevel(cid) < 100 then
        if pay(cid,500) then
        travel(cid, 794, 2058, 6)
        talk_state = 0
        else
        selfSay('Sorry, you don\'t have this money.')
        talk_state = 0
         end
        else
        selfSay('I only can travel to there on level 8 to 99.')
        talk_state = 0
         end
        else
        selfSay('Sorry, only premmys can travel whit me.')
        talk_state = 0
         end
        else
        selfSay('Repeat all again.')
        talk_state = 0
         end
    end


    elseif talk_state == 3 then
        if msgcontains(msg, 'yes') then
        if talk_state == 3 then
        if isPremium(cid) then
        if getPlayerLevel(cid) > 99 and getPlayerLevel(cid) < 200 then
        if pay(cid,1000) then
        travel(cid, 753, 1932, 6)
        talk_state = 0
        else
        selfSay('Sorry, you don\'t have this money.')
        talk_state = 0
         end
        else
        selfSay('I only can travel to there on level 100 to 199.')
        talk_state = 0
         end
        else
        selfSay('Sorry, only premmys can travel whit me.')
        talk_state = 0
         end
        else
        selfSay('Repeat all again.')
        talk_state = 0
         end
    end

    elseif talk_state == 4 then
        if msgcontains(msg, 'yes') then
        if talk_state == 4 then
        if isPremium(cid) then
        if getPlayerLevel(cid) > 199 and getPlayerLevel(cid) < 299 then
        if pay(cid,2000) then
        travel(cid, 880, 1879, 6)
        talk_state = 0
        else
        selfSay('Sorry, you don\'t have this money.')
        talk_state = 0
         end
        else
        selfSay('I only can travel to there on level 200 to 299.')
        talk_state = 0
         end
        else
        selfSay('Sorry, only premmys can travel whit me.')
        talk_state = 0
         end
        else
        selfSay('Repeat all again.')
        talk_state = 0
         end
    end

    elseif talk_state == 5 then
        if msgcontains(msg, 'yes') then
        if talk_state == 5 then
        if isPremium(cid) then
        if getPlayerVocation(cid) > 8 then
        if pay(cid,5000) then
        travel(cid, 1024, 1894, 6)
        talk_state = 0
        else
        selfSay('Sorry, you don\'t have this money.')
        talk_state = 0
         end
        else
        selfSay('I only can travel only valans whit me.')
        talk_state = 0
         end
        else
        selfSay('Sorry, only premmys can travel whit me.')
        talk_state = 0
         end
        else
        selfSay('Repeat all again.')
        talk_state = 0
         end
    end

    elseif talk_state == 6 then
        if msgcontains(msg, 'yes') then
        if talk_state == 6 then
        if isPremium(cid) then
        if getPlayerVocation(cid) > 12 then
        if getPlayerItemCount(cid,6527) >= 100 then
        travel(cid, 1093, 1883, 6)
        doPlayerTakeItem(cid,6527,100)
        talk_state = 0
        else
        selfSay('Sorry, you don\'t have this.')
        talk_state = 0
         end
        else
        selfSay('I only can travel only gods whit me.')
        talk_state = 0
         end
        else
        selfSay('Sorry, only premmys can travel whit me.')
        talk_state = 0
         end
        else
        selfSay('Repeat all again.')
        talk_state = 0
         end
    end

        elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 34) then
            selfSay('Ok than.')
            talk_state = 0
        end


    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)


-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!

keywordHandler:addKeyword({'destination'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to Bramun on level 8 to 99, Canudis on level 100 to 199, Morgun on level 200 to 299 and to Mordor only for Valans and Tanoris for gods.'})


keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I am the Carpet Man!'})
keywordHandler:addKeyword({'mission'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I never get involved in quests.'})
keywordHandler:addKeyword({'quest'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I never get involved in quests.'})
keywordHandler:addKeyword({'offer'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to Bramun on level 8 to 99, Canudis on level 100 to 199, Morgun on level 200 to 299 and to Mordor only for Valans and Tanoris for gods.'})

-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())
 
IDK if you got some super downgraded NPC lib in your TFS 1.2, but this:
Lua:
function creatureSayCallback(cid, type, msg)
    if(npcHandler.focus ~= cid) then
        return false
    end
looks like code from Tibia times, when only one player could talk with NPC, rest had to wait in queue.
On TFS 1.2 you have to check, if current talking player is 'one of focused' players:
Lua:
local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
as in TFS 1.2 example NPC:

These first lines of creatureSayCallback for sure blocks this NPC. IDK how about others. Change it, try and report, if it prints some errors.

Whole code is TFS 0.3/0.4 Lua code with cid, not player variable and old functions ex. getPlayerLevel(cid) in place of TFS 1.2 player:getLevel(), but it should be fine. TFS 1.2 has compatibility code to make old functions work: forgottenserver/compat.lua at 1.2 · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/1.2/data/lib/compat/compat.lua)
 
Back
Top