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

xodet not giving first wand

Jeyci

Banned User
Joined
May 6, 2023
Messages
289
Solutions
3
Reaction score
36
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 creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    local items = {[VOCATION_SORCERER] = 2190, [VOCATION_DRUID] = 2182}
    local itemId = items[player:getVocation():getBase():getId()]
    if msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand') then
        if player:isMage() then
            if player:getStorageValue(PlayerStorageKeys.firstMageWeapon) == -1 then
                npcHandler:say('So you ask me for a {' .. ItemType(itemId):getName() .. '} to begin your adventure?', cid)
                npcHandler.topic[cid] = 1
            else
                npcHandler:say('What? I have already gave you one {' .. ItemType(itemId):getName() .. '}!', cid)
            end
        else
            npcHandler:say('Sorry, you aren\'t a druid either a sorcerer.', cid)
        end
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 1 then
            player:addItem(itemId, 1)
            npcHandler:say('Here you are young adept, take care yourself.', cid)
            player:setStorageValue(PlayerStorageKeys.firstMageWeapon, 1)
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
        npcHandler:say('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

this is my data/lib/core/storages.lua

Code:
firstMageWeapon = 50079,
 
Solution
now it's working xD

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

-- Define a storage ID for tracking whether the player has already received the item
local STORAGE_ID = 1000

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 talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT...
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 creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
    local items = {[VOCATION_SORCERER] = 2190, [VOCATION_DRUID] = 2182}
    local vocationId = player:getVocation():getBase():getId()
    
    if msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand') then
        local itemId = items[vocationId]
        if itemId then
            if player:isMage() then
                if player:getStorageValue(PlayerStorageKeys.firstMageWeapon) == -1 then
                    npcHandler:say('So you ask me for a {' .. ItemType(itemId):getName() .. '} to begin your adventure?', cid)
                    npcHandler.topic[cid] = 1
                else
                    npcHandler:say('What? I have already given you one {' .. ItemType(itemId):getName() .. '}!', cid)
                end
            else
                npcHandler:say('Sorry, you aren\'t a druid or a sorcerer.', cid)
            end
        else
            npcHandler:say('I have no gifts for your vocation.', cid)
        end
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 1 then
            local itemId = items[vocationId]
            if itemId then
                player:addItem(itemId, 1)
                npcHandler:say('Here you are, young adept. Take care of yourself.', cid)
                player:setStorageValue(PlayerStorageKeys.firstMageWeapon, 1)
            else
                npcHandler:say('I have no gifts for your vocation.', cid)
            end
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
        npcHandler:say('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
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 creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
    local items = {[VOCATION_SORCERER] = 2190, [VOCATION_DRUID] = 2182}
    local vocationId = player:getVocation():getBase():getId()
  
    if msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand') then
        local itemId = items[vocationId]
        if itemId then
            if player:isMage() then
                if player:getStorageValue(PlayerStorageKeys.firstMageWeapon) == -1 then
                    npcHandler:say('So you ask me for a {' .. ItemType(itemId):getName() .. '} to begin your adventure?', cid)
                    npcHandler.topic[cid] = 1
                else
                    npcHandler:say('What? I have already given you one {' .. ItemType(itemId):getName() .. '}!', cid)
                end
            else
                npcHandler:say('Sorry, you aren\'t a druid or a sorcerer.', cid)
            end
        else
            npcHandler:say('I have no gifts for your vocation.', cid)
        end
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 1 then
            local itemId = items[vocationId]
            if itemId then
                player:addItem(itemId, 1)
                npcHandler:say('Here you are, young adept. Take care of yourself.', cid)
                player:setStorageValue(PlayerStorageKeys.firstMageWeapon, 1)
            else
                npcHandler:say('I have no gifts for your vocation.', cid)
            end
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
        npcHandler:say('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
does not work either :/ no errors in console
 
does not work either :/ no errors in console
That NPC just gives the wand, right? What's his ID then?
Post automatically merged:

What I did was use the Magic Sword's ID... then you can change the ID to the wand's and do the test.



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 creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
    
    if msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand') then
        if player:isMage() then
            if player:getStorageValue(PlayerStorageKeys.firstMageWeapon) == -1 then
                npcHandler:say('So you ask me for a first wand to begin your adventure?', cid)
                npcHandler.topic[cid] = 1
            else
                npcHandler:say('What? I have already given you a first wand!', cid)
            end
        else
            npcHandler:say('Sorry, you aren\'t a druid or a sorcerer.', cid)
        end
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 1 then
            player:addItem(2400, 1)  -- Adding item with ID 2400
            npcHandler:say('Here you are, young adept. Take care of yourself.', cid)
            player:setStorageValue(PlayerStorageKeys.firstMageWeapon, 1)
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
        npcHandler:say('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
That NPC just gives the wand, right? What's his ID then?
the wands id?
Lua:
06:47 You see a wand of vortex.
It can only be wielded properly by sorcerers of level 7 or higher.
It weighs 19.00 oz.
Surges of energy rush through the tip of this wand.
Item ID: 2190
Position: 32359, 32221, 6
06:47 You see a snakebite rod.
It can only be wielded properly by druids of level 7 or higher.
It weighs 19.00 oz.
It seems to twitch and quiver as if trying to escape your grip.

sotrages.lua
Code:
firstMageWeapon = 50079,
 
That NPC just gives the wand, right? What's his ID then?
Post automatically merged:

What I did was use the Magic Sword's ID... then you can change the ID to the wand's and do the test.



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 creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
   
    if msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand') then
        if player:isMage() then
            if player:getStorageValue(PlayerStorageKeys.firstMageWeapon) == -1 then
                npcHandler:say('So you ask me for a first wand to begin your adventure?', cid)
                npcHandler.topic[cid] = 1
            else
                npcHandler:say('What? I have already given you a first wand!', cid)
            end
        else
            npcHandler:say('Sorry, you aren\'t a druid or a sorcerer.', cid)
        end
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 1 then
            player:addItem(2400, 1)  -- Adding item with ID 2400
            npcHandler:say('Here you are, young adept. Take care of yourself.', cid)
            player:setStorageValue(PlayerStorageKeys.firstMageWeapon, 1)
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
        npcHandler:say('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
tried this didn't work either :( @Mateus Robeerto
Post automatically merged:

Is it possible to get the wand only once or is it allowed to get it multiple times?
only once and need that if player is druid it should be snakebite rod if its sorcerer wand of vortex please
 
Now I understand. You could have added a title to make it easier to understand. That way, we could help more quickly, you know? Anyway, I made some changes so that you can only receive the wand once. Hope it works.


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 creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
   
    if msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand') then
        if player:isMage() then
            local itemId = nil
            if player:getVocation():getId() == VOCATION_SORCERER then
                itemId = 2190  -- Wand ID for Sorcerers
            elseif player:getVocation():getId() == VOCATION_DRUID then
                itemId = 2182  -- Wand ID for Druids
            end
           
            if itemId then
                if player:getStorageValue(50079) ~= 1 then
                    npcHandler:say('So you ask me for a {' .. ItemType(itemId):getName() .. '} to begin your adventure?', cid)
                    npcHandler.topic[cid] = 1
                else
                    npcHandler:say('What? I have already given you a {' .. ItemType(itemId):getName() .. '}!', cid)
                end
            else
                npcHandler:say('Sorry, you aren\'t a druid or a sorcerer.', cid)
            end
        else
            npcHandler:say('Sorry, you aren\'t a druid or a sorcerer.', cid)
        end
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 1 then
            local itemId = nil
            if player:getVocation():getId() == VOCATION_SORCERER then
                itemId = 2190  -- Wand ID for Sorcerers
            elseif player:getVocation():getId() == VOCATION_DRUID then
                itemId = 2182  -- Wand ID for Druids
            end
           
            if itemId then
                player:addItem(itemId, 1)
                npcHandler:say('Here you are, young adept. Take care of yourself.', cid)
                player:setStorageValue(50079, 1)  -- Set the storage to indicate the player received the item
            else
                npcHandler:say('Sorry, you aren\'t a druid or a sorcerer.', cid)
            end
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
        npcHandler:say('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

or

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

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

    local player = Player(cid)
    local vocation = player:getVocation():getId()

    local sorcererItemId = 2190  -- Wand ID for Sorcerers
    local druidItemId = 2182  -- Wand ID for Druids
    local stor = 50079  -- Storage to track if the player has received an item

    if msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand') then
        if player:isMage() then
            local itemId = vocation == VOCATION_SORCERER and sorcererItemId or vocation == VOCATION_DRUID and druidItemId or nil

            if itemId then
                if player:getStorageValue(stor) ~= 1 then
                    npcHandler:say('So you ask me for a {' .. ItemType(itemId):getName() .. '} to begin your adventure?', cid)
                    npcHandler.topic[cid] = itemId
                else
                    npcHandler:say('What? I have already given you a {' .. ItemType(itemId):getName() .. '}!', cid)
                end
            else
                npcHandler:say('Sorry, you aren\'t a druid or a sorcerer.', cid)
            end
        else
            npcHandler:say('Sorry, you aren\'t a druid or a sorcerer.', cid)
        end
    elseif msgcontains(msg, 'yes') then
        local itemId = npcHandler.topic[cid]
        if itemId then
            player:addItem(itemId, 1)
            npcHandler:say('Here you are, young adept. Take care of yourself.', cid)
            player:setStorageValue(stor, 1)
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] then
        npcHandler:say('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Now I understand. You could have added a title to make it easier to understand. That way, we could help more quickly, you know? Anyway, I made some changes so that you can only receive the wand once. Hope it works.


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 creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
 
    if msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand') then
        if player:isMage() then
            local itemId = nil
            if player:getVocation():getId() == VOCATION_SORCERER then
                itemId = 2190  -- Wand ID for Sorcerers
            elseif player:getVocation():getId() == VOCATION_DRUID then
                itemId = 2182  -- Wand ID for Druids
            end
        
            if itemId then
                if player:getStorageValue(50079) ~= 1 then
                    npcHandler:say('So you ask me for a {' .. ItemType(itemId):getName() .. '} to begin your adventure?', cid)
                    npcHandler.topic[cid] = 1
                else
                    npcHandler:say('What? I have already given you a {' .. ItemType(itemId):getName() .. '}!', cid)
                end
            else
                npcHandler:say('Sorry, you aren\'t a druid or a sorcerer.', cid)
            end
        else
            npcHandler:say('Sorry, you aren\'t a druid or a sorcerer.', cid)
        end
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 1 then
            local itemId = nil
            if player:getVocation():getId() == VOCATION_SORCERER then
                itemId = 2190  -- Wand ID for Sorcerers
            elseif player:getVocation():getId() == VOCATION_DRUID then
                itemId = 2182  -- Wand ID for Druids
            end
        
            if itemId then
                player:addItem(itemId, 1)
                npcHandler:say('Here you are, young adept. Take care of yourself.', cid)
                player:setStorageValue(50079, 1)  -- Set the storage to indicate the player received the item
            else
                npcHandler:say('Sorry, you aren\'t a druid or a sorcerer.', cid)
            end
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
        npcHandler:say('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

or

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

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

    local player = Player(cid)
    local vocation = player:getVocation():getId()

    local sorcererItemId = 2190  -- Wand ID for Sorcerers
    local druidItemId = 2182  -- Wand ID for Druids
    local stor = 50079  -- Storage to track if the player has received an item

    if msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand') then
        if player:isMage() then
            local itemId = vocation == VOCATION_SORCERER and sorcererItemId or vocation == VOCATION_DRUID and druidItemId or nil

            if itemId then
                if player:getStorageValue(stor) ~= 1 then
                    npcHandler:say('So you ask me for a {' .. ItemType(itemId):getName() .. '} to begin your adventure?', cid)
                    npcHandler.topic[cid] = itemId
                else
                    npcHandler:say('What? I have already given you a {' .. ItemType(itemId):getName() .. '}!', cid)
                end
            else
                npcHandler:say('Sorry, you aren\'t a druid or a sorcerer.', cid)
            end
        else
            npcHandler:say('Sorry, you aren\'t a druid or a sorcerer.', cid)
        end
    elseif msgcontains(msg, 'yes') then
        local itemId = npcHandler.topic[cid]
        if itemId then
            player:addItem(itemId, 1)
            npcHandler:say('Here you are, young adept. Take care of yourself.', cid)
            player:setStorageValue(stor, 1)
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] then
        npcHandler:say('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
thanks bro but none of these are working, the npc works it replies to my greetings or hi trade channel opens when i say trade, but it wont give the rod or wand / tested both scripts. no errors in console
lib/core
have this in constant.lua
Lua:
VOCATION_NONE = 0
VOCATION_SORCERER = 1
VOCATION_DRUID = 2
VOCATION_PALADIN = 3
VOCATION_KNIGHT = 4
VOCATION_MASTER_SORCERER = 5
VOCATION_ELDER_DRUID = 6
VOCATION_ROYAL_PALADIN = 7
VOCATION_ELITE_KNIGHT = 8
this in player.lua
Code:
function Player.isDruid(self)
    return table.contains({VOCATION_DRUID, VOCATION_ELDER_DRUID}, self:getVocation():getId())
end

function Player.isKnight(self)
    return table.contains({VOCATION_KNIGHT, VOCATION_ELITE_KNIGHT}, self:getVocation():getId())
end

function Player.isPaladin(self)
    return table.contains({VOCATION_PALADIN, VOCATION_ROYAL_PALADIN}, self:getVocation():getId())
end

function Player.isMage(self)
    return table.contains({VOCATION_SORCERER, VOCATION_DRUID, VOCATION_MASTER_SORCERER, VOCATION_ELDER_DRUID}, self:getVocation():getId())
end

function Player.isSorcerer(self)
    return table.contains({VOCATION_SORCERER, VOCATION_MASTER_SORCERER}, self:getVocation():getId())
end
something might be missing?
 
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 creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	end
	local player = Player(cid)
	local items = {[1] = 2190, [2] = 2182}
	local itemId = items[player:getVocation():getBase():getId()]
	if msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand') then
		if isInArray({1, 2}, player:getVocation():getBase():getId()) then
			if player:getStorageValue(PlayerStorage.firstMageWeapon) == -1 then
				npcHandler:say('So you ask me for a {' .. ItemType(itemId):getName() .. '} to begin your adventure?', cid)
				npcHandler.topic[cid] = 1
			else
				npcHandler:say('What? I have already gave you one {' .. ItemType(itemId):getName() .. '}!', cid)
			end
		else
			npcHandler:say('Sorry, you aren\'t a druid either a sorcerer.', cid)
		end
	elseif msgcontains(msg, 'yes') then
		if npcHandler.topic[cid] == 1 then
			player:addItem(itemId, 1)
			npcHandler:say('Here you are young adept, take care yourself.', cid)
			player:setStorageValue(PlayerStorage.firstMageWeapon, 1)
		end
		npcHandler.topic[cid] = 0
	elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
		npcHandler:say('Ok then.', cid)
		npcHandler.topic[cid] = 0
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
don't know why is not working i tried with a clean sorcerer level 8 no promotion
Lua:
08:33 You see yourself. You are a sorcerer.
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 creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    local items = {[1] = 2190, [2] = 2182}
    local itemId = items[player:getVocation():getBase():getId()]
    if msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand') then
        if isInArray({1, 2}, player:getVocation():getBase():getId()) then
            if player:getStorageValue(PlayerStorage.firstMageWeapon) == -1 then
                npcHandler:say('So you ask me for a {' .. ItemType(itemId):getName() .. '} to begin your adventure?', cid)
                npcHandler.topic[cid] = 1
            else
                npcHandler:say('What? I have already gave you one {' .. ItemType(itemId):getName() .. '}!', cid)
            end
        else
            npcHandler:say('Sorry, you aren\'t a druid either a sorcerer.', cid)
        end
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 1 then
            player:addItem(itemId, 1)
            npcHandler:say('Here you are young adept, take care yourself.', cid)
            player:setStorageValue(PlayerStorage.firstMageWeapon, 1)
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
        npcHandler:say('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
the script not working :/ in spite i changed this
Code:
player:setStorageValue(PlayerStorage.firstMageWeapon, 1)
to this
Code:
player:setStorageValue(PlayerStorageKeys.firstMageWeapon, 1)
 
don't know why is not working i tried with a clean sorcerer level 8 no promotion
Lua:
08:33 You see yourself. You are a sorcerer.

the script not working :/ in spite i changed this
Code:
player:setStorageValue(PlayerStorage.firstMageWeapon, 1)
to this
Code:
player:setStorageValue(PlayerStorageKeys.firstMageWeapon, 1)
Change in getStorageValue too.

No errors in console? Whats your server?
 
yes i did
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 creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    local items = {[1] = 2190, [2] = 2182}
    local itemId = items[player:getVocation():getBase():getId()]
    if msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand') then
        if isInArray({1, 2}, player:getVocation():getBase():getId()) then
            if player:getStorageValue(PlayerStorageKeys.firstMageWeapon) == -1 then
                npcHandler:say('So you ask me for a {' .. ItemType(itemId):getName() .. '} to begin your adventure?', cid)
                npcHandler.topic[cid] = 1
            else
                npcHandler:say('What? I have already gave you one {' .. ItemType(itemId):getName() .. '}!', cid)
            end
        else
            npcHandler:say('Sorry, you aren\'t a druid either a sorcerer.', cid)
        end
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 1 then
            player:addItem(itemId, 1)
            npcHandler:say('Here you are young adept, take care yourself.', cid)
            player:setStorageValue(PlayerStorageKeys.firstMageWeapon, 1)
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
        npcHandler:say('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end
    return true
end
i use tfs 1.5 - protocol 8.6 with orts datapack
Post automatically merged:

have tried all the scripts given here, none of them work, none gives error in console
 
thanks bro but none of these are working, the npc works it replies to my greetings or hi trade channel opens when i say trade, but it wont give the rod or wand / tested both scripts. no errors in console
lib/core
have this in constant.lua
Lua:
VOCATION_NONE = 0
VOCATION_SORCERER = 1
VOCATION_DRUID = 2
VOCATION_PALADIN = 3
VOCATION_KNIGHT = 4
VOCATION_MASTER_SORCERER = 5
VOCATION_ELDER_DRUID = 6
VOCATION_ROYAL_PALADIN = 7
VOCATION_ELITE_KNIGHT = 8
this in player.lua
Code:
function Player.isDruid(self)
    return table.contains({VOCATION_DRUID, VOCATION_ELDER_DRUID}, self:getVocation():getId())
end

function Player.isKnight(self)
    return table.contains({VOCATION_KNIGHT, VOCATION_ELITE_KNIGHT}, self:getVocation():getId())
end

function Player.isPaladin(self)
    return table.contains({VOCATION_PALADIN, VOCATION_ROYAL_PALADIN}, self:getVocation():getId())
end

function Player.isMage(self)
    return table.contains({VOCATION_SORCERER, VOCATION_DRUID, VOCATION_MASTER_SORCERER, VOCATION_ELDER_DRUID}, self:getVocation():getId())
end

function Player.isSorcerer(self)
    return table.contains({VOCATION_SORCERER, VOCATION_MASTER_SORCERER}, self:getVocation():getId())
end
something might be missing?
what msg the npc says if u say 'first rod' or 'first wand' ?
Post automatically merged:

yes i did
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 creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    local items = {[1] = 2190, [2] = 2182}
    local itemId = items[player:getVocation():getBase():getId()]
    if msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand') then
        if isInArray({1, 2}, player:getVocation():getBase():getId()) then
            if player:getStorageValue(PlayerStorageKeys.firstMageWeapon) == -1 then
                npcHandler:say('So you ask me for a {' .. ItemType(itemId):getName() .. '} to begin your adventure?', cid)
                npcHandler.topic[cid] = 1
            else
                npcHandler:say('What? I have already gave you one {' .. ItemType(itemId):getName() .. '}!', cid)
            end
        else
            npcHandler:say('Sorry, you aren\'t a druid either a sorcerer.', cid)
        end
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 1 then
            player:addItem(itemId, 1)
            npcHandler:say('Here you are young adept, take care yourself.', cid)
            player:setStorageValue(PlayerStorageKeys.firstMageWeapon, 1)
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
        npcHandler:say('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end
    return true
end
i use tfs 1.5 - protocol 8.6 with orts datapack
Post automatically merged:

have tried all the scripts given here, none of them work, none gives error in console
this is the full script?
if so, add it at the end:

Lua:
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
now it's working xD

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

-- Define a storage ID for tracking whether the player has already received the item
local STORAGE_ID = 1000

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 talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if (msgcontains(msg, 'first wand') or msgcontains(msg, 'rod')) then
        if (getPlayerStorageValue(cid, STORAGE_ID) ~= 1) then
            if (getPlayerVocation(cid) == 1) then -- Sorcerer
                doPlayerAddItem(cid, 2190, 1) -- Add Wand ID 2190 for Sorcerers
                setPlayerStorageValue(cid, STORAGE_ID, 1) -- Set storage to indicate item received
                selfSay('Here is a wand for sorcerers. Enjoy!', cid)
            elseif (getPlayerVocation(cid) == 2) then -- Druid
                doPlayerAddItem(cid, 2182, 1) -- Add Wand ID 2182 for Druids
                setPlayerStorageValue(cid, STORAGE_ID, 1) -- Set storage to indicate item received
                selfSay('Here is a wand for druids. Enjoy!', cid)
            else
                selfSay('Sorry, this offer is only for sorcerers and druids.', cid)
            end
        else
            selfSay('You have already received this item.', cid)
        end
    elseif (msgcontains(msg, 'offer') or msgcontains(msg, 'trade') or msgcontains(msg, 'ofertas')) then
        selfSay('I offer various items for sale.', cid)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Post automatically merged:

 
Last edited:
Solution
Back
Top