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

TFS 1.X+ Reverse Oracle

Landera

Veteran OT User
Joined
Nov 24, 2011
Messages
905
Solutions
1
Reaction score
318
Hello guys,

I'd tried creating an reverse oracle npc basically, and came up with some kind of base. But no clue how to get this into a working script.

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

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

if msgcontains(msg, 'rookgaard') then
    npcHandler:say('Hmmm. Long time I visited that isle. Not very exciting place. Why do you ask? Do you wish to go there?')
    talk_state = 3
    
    elseif msgcontains(msg, 'yes') and talk_state == 3 then
    npcHandler:say('Careful, careful, it\'s a one-way ticket only! You can never come back here if you leave now, and you will lose all your equipment and products!?')
    talk_state = 4
    elseif msgcontains(msg, 'no') and talk_state == 3 then
    npcHandler:say('A wise decision. It\'s much better here, believe me. Been there, done that.')
    talk_state = 0
    
    elseif msgcontains(msg, 'yes') and talk_state == 4 then
    npcHandler:say('Then so be it. I\'m sorry to see you go, but if this is what you want, step this way... right. Now, cover your eyes... GO!')

    doPlayerSetVocation(cid, 0)
    doPlayerSetTown(cid, 1)

    doPlayerSetMagicLevel(cid, 0)
    doPlayerSetSkillLevel(cid, SKILL_SHIELD, 10)
    doPlayerSetSkillLevel(cid, SKILL_DISTANCE, 10)
    doPlayerSetSkillLevel(cid, SKILL_AXE, 10)
     doPlayerSetSkillLevel(cid, SKILL_SWORD, 10)
    doPlayerSetSkillLevel(cid, SKILL_CLUB, 10)
    player:removeExperience(player:getExperience() - getExpForLevel(1), false)   
    player:setMaxHealth(150)
    player:setMaxMana(55)
    player:addHealth(player:getMaxHealth())
    player:addMana(player:getMaxMana())
    player:setCapacity(400)

    doTeleportThing(cid, {x=32097,y=32219,z=7})
    doSendMagicEffect(destination, CONST_ME_MAGIC_BLUE)

    local slots = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    for _, slot in pairs(slots) do
    local item = player:getSlotItem(slot)
    if item then
        item:remove()
    end
end

    doPlayerAddItem(cid, 1987, 1)
    doAddContainerItem(bag,2650,1)
    doAddContainerItem(bag,2382,1)
    doAddContainerItem(bag,2674,1)
end

npcHandler:addModule(FocusModule:new())

I'm using TFS 1.5 772 downgrade by nekiro
 
Solution
Hello guys,

I'd tried creating an reverse oracle npc basically, and came up with some kind of base. But no clue how to get this into a working script.

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

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

if msgcontains(msg, 'rookgaard') then
    npcHandler:say('Hmmm. Long time I visited that isle...
Hello guys,

I'd tried creating an reverse oracle npc basically, and came up with some kind of base. But no clue how to get this into a working script.

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

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

if msgcontains(msg, 'rookgaard') then
    npcHandler:say('Hmmm. Long time I visited that isle. Not very exciting place. Why do you ask? Do you wish to go there?')
    talk_state = 3
  
    elseif msgcontains(msg, 'yes') and talk_state == 3 then
    npcHandler:say('Careful, careful, it\'s a one-way ticket only! You can never come back here if you leave now, and you will lose all your equipment and products!?')
    talk_state = 4
    elseif msgcontains(msg, 'no') and talk_state == 3 then
    npcHandler:say('A wise decision. It\'s much better here, believe me. Been there, done that.')
    talk_state = 0
  
    elseif msgcontains(msg, 'yes') and talk_state == 4 then
    npcHandler:say('Then so be it. I\'m sorry to see you go, but if this is what you want, step this way... right. Now, cover your eyes... GO!')

    doPlayerSetVocation(cid, 0)
    doPlayerSetTown(cid, 1)

    doPlayerSetMagicLevel(cid, 0)
    doPlayerSetSkillLevel(cid, SKILL_SHIELD, 10)
    doPlayerSetSkillLevel(cid, SKILL_DISTANCE, 10)
    doPlayerSetSkillLevel(cid, SKILL_AXE, 10)
     doPlayerSetSkillLevel(cid, SKILL_SWORD, 10)
    doPlayerSetSkillLevel(cid, SKILL_CLUB, 10)
    player:removeExperience(player:getExperience() - getExpForLevel(1), false) 
    player:setMaxHealth(150)
    player:setMaxMana(55)
    player:addHealth(player:getMaxHealth())
    player:addMana(player:getMaxMana())
    player:setCapacity(400)

    doTeleportThing(cid, {x=32097,y=32219,z=7})
    doSendMagicEffect(destination, CONST_ME_MAGIC_BLUE)

    local slots = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    for _, slot in pairs(slots) do
    local item = player:getSlotItem(slot)
    if item then
        item:remove()
    end
end

    doPlayerAddItem(cid, 1987, 1)
    doAddContainerItem(bag,2650,1)
    doAddContainerItem(bag,2382,1)
    doAddContainerItem(bag,2674,1)
end

npcHandler:addModule(FocusModule:new())

I'm using TFS 1.5 772 downgrade by nekiro

I mean, you're like 99% of the way there.

XML:
<npc name="The Reverse Oracle" script="The Reverse Oracle.lua" walkinterval="0" speechbubble="3">
    <look typeex="1448" />
    <parameters>
        <parameter key="message_greet" value="|PLAYERNAME|, ARE YOU PREPARED TO FACE YOUR DESTINY?" />
        <parameter key="message_walkaway" value="COME BACK WHEN YOU ARE PREPARED TO FACE YOUR DESTINY!" />
        <parameter key="message_farewell" value="COME BACK WHEN YOU ARE PREPARED TO FACE YOUR DESTINY!" />
    </parameters>
</npc>
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 function greetCallback(cid)
    return true
end

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

    if msgcontains(msg, "rookgaard") then
        npcHandler:say("Hmmm. Long time I visited that isle. Not very exciting place. Why do you ask? Do you wish to go there?")
        npcHandler.topic[cid] = 1
   
    elseif npcHandler.topic[cid] == 1 then
        if not msgcontains(msg, "yes") then
            npcHandler:say("A wise decision. It's much better here, believe me. Been there, done that.")
            npcHandler.topic[cid] = 0
            return true
        end
        npcHandler:say("Careful, careful, it's a one-way ticket only! You can never come back here if you leave now, and you will lose all your equipment and products!? Do you still wish to go?")
        npcHandler.topic[cid] = 2
   
    elseif npcHandler.topic[cid] == 2 then
        if not msgcontains(msg, "yes") then
            npcHandler:say("A wise decision. It's much better here, believe me. Been there, done that.")
            npcHandler.topic[cid] = 0
            return true
        end
        npcHandler:say("Then so be it. I'm sorry to see you go, but if this is what you want, step this way... right. Now, cover your eyes... GO!")
   
        doPlayerSetVocation(cid, 0)
        doPlayerSetTown(cid, 1)
   
        doPlayerSetMagicLevel(cid, 0)
        doPlayerSetSkillLevel(cid, SKILL_SHIELD, 10)
        doPlayerSetSkillLevel(cid, SKILL_DISTANCE, 10)
        doPlayerSetSkillLevel(cid, SKILL_AXE, 10)
        doPlayerSetSkillLevel(cid, SKILL_SWORD, 10)
        doPlayerSetSkillLevel(cid, SKILL_CLUB, 10)
        player:removeExperience(player:getExperience() - getExpForLevel(1), false)  
        player:setMaxHealth(150)
        player:setMaxMana(55)
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        player:setCapacity(400)
   
        doTeleportThing(cid, {x=32097,y=32219,z=7})
        doSendMagicEffect(destination, CONST_ME_MAGIC_BLUE)
   
        local slots = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
        for _, slot in pairs(slots) do
            local item = player:getSlotItem(slot)
            if item then
                item:remove()
            end
        end

        doPlayerAddItem(cid, 1987, 1)
        doAddContainerItem(bag,2650,1)
        doAddContainerItem(bag,2382,1)
        doAddContainerItem(bag,2674,1)
        npcHandler.topic[cid] = 0
       
    end
   
    return true
end

local function onAddFocus(cid)
    npcHandler.topic[cid] = 0
end

local function onReleaseFocus(cid)
    npcHandler.topic[cid] = 0
end

npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
I mean, you're like 99% of the way there.

XML:
<npc name="The Reverse Oracle" script="The Reverse Oracle.lua" walkinterval="0" speechbubble="3">
    <look typeex="1448" />
    <parameters>
        <parameter key="message_greet" value="|PLAYERNAME|, ARE YOU PREPARED TO FACE YOUR DESTINY?" />
        <parameter key="message_walkaway" value="COME BACK WHEN YOU ARE PREPARED TO FACE YOUR DESTINY!" />
        <parameter key="message_farewell" value="COME BACK WHEN YOU ARE PREPARED TO FACE YOUR DESTINY!" />
    </parameters>
</npc>
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 function greetCallback(cid)
    return true
end

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

    if msgcontains(msg, "rookgaard") then
        npcHandler:say("Hmmm. Long time I visited that isle. Not very exciting place. Why do you ask? Do you wish to go there?")
        npcHandler.topic[cid] = 1
  
    elseif npcHandler.topic[cid] == 1 then
        if not msgcontains(msg, "yes") then
            npcHandler:say("A wise decision. It's much better here, believe me. Been there, done that.")
            npcHandler.topic[cid] = 0
            return true
        end
        npcHandler:say("Careful, careful, it's a one-way ticket only! You can never come back here if you leave now, and you will lose all your equipment and products!? Do you still wish to go?")
        npcHandler.topic[cid] = 2
  
    elseif npcHandler.topic[cid] == 2 then
        if not msgcontains(msg, "yes") then
            npcHandler:say("A wise decision. It's much better here, believe me. Been there, done that.")
            npcHandler.topic[cid] = 0
            return true
        end
        npcHandler:say("Then so be it. I'm sorry to see you go, but if this is what you want, step this way... right. Now, cover your eyes... GO!")
  
        doPlayerSetVocation(cid, 0)
        doPlayerSetTown(cid, 1)
  
        doPlayerSetMagicLevel(cid, 0)
        doPlayerSetSkillLevel(cid, SKILL_SHIELD, 10)
        doPlayerSetSkillLevel(cid, SKILL_DISTANCE, 10)
        doPlayerSetSkillLevel(cid, SKILL_AXE, 10)
        doPlayerSetSkillLevel(cid, SKILL_SWORD, 10)
        doPlayerSetSkillLevel(cid, SKILL_CLUB, 10)
        player:removeExperience(player:getExperience() - getExpForLevel(1), false) 
        player:setMaxHealth(150)
        player:setMaxMana(55)
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        player:setCapacity(400)
  
        doTeleportThing(cid, {x=32097,y=32219,z=7})
        doSendMagicEffect(destination, CONST_ME_MAGIC_BLUE)
  
        local slots = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
        for _, slot in pairs(slots) do
            local item = player:getSlotItem(slot)
            if item then
                item:remove()
            end
        end

        doPlayerAddItem(cid, 1987, 1)
        doAddContainerItem(bag,2650,1)
        doAddContainerItem(bag,2382,1)
        doAddContainerItem(bag,2674,1)
        npcHandler.topic[cid] = 0
      
    end
  
    return true
end

local function onAddFocus(cid)
    npcHandler.topic[cid] = 0
end

local function onReleaseFocus(cid)
    npcHandler.topic[cid] = 0
end

npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Thank you for your reply, i've tried thescript and I'm getting this error.

Lua:
Lua Script Error: [Npc interface]
data/npc/scripts/The Oracle.lua:onCreatureSay
data/npc/lib/npcsystem/npchandler.lua:633: table index is nil
stack traceback:
        [C]: in function '__newindex'
        data/npc/lib/npcsystem/npchandler.lua:633: in function 'say'
        data/npc/scripts/The Oracle.lua:23: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:411: in function 'onCreatureSay'
        data/npc/scripts/The Oracle.lua:8: in function <data/npc/scripts/The Oracle.lua:8>


I've tried to change the npcHandler.topic[cid] to talk_state this didnt show me any errors when i said "rookgaard" but it didnt do anything either
 
Alright I've found the issue I did need to put ", cid)" behind the npcHandler.
However now im bumping into another issue.

This add +10 skill instead of reseting it to 10
doPlayerSetSkillLevel(cid, SKILL_SHIELD, 10)
 
Last edited:
Yea this lowers the skills, but the (10) is the skill i want players to get :p

Lua:
local currentSkillLevel = player:getSkillLevel(SKILL_SHIELD)
local desiredSkillLevel = (currentSkillLevel + 10) - currentSkillLevel

player:addSkillLevel(SKILL_SHIELD, -desiredSkillLevel)

should work or something, just need some math calculation
 
Alright I found away around it if I do -1000 on all skills they end up at skill 10, wont go below it. Only magic level do not work that way so i repeated the magic level line 100 times xD, its ugly but it works.
 
Back
Top