• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

My Npc doesnt add items

Tbol

Well-Known Member
Joined
Apr 7, 2019
Messages
625
Reaction score
71
Hello trying to some changes in a code. But for some reason it doesnt give an item from the table even when there is no errors. It should give and item and remove 30 points from storage 25335 and it adds points when it should remove them. TFS 1.2
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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

local items = {
        item1 = {8266} -- [ITEMID]
}
local counts = {
        count1 = {30, 1}  -- [PRICE, ITEM AMOUNT]
}

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if  msgcontains(msg, 'event boost') then
        if player:getStorageValue(25335) >= counts.count1[1] then
            player:setStorageValue(25335, player:getStorageValue(25335) + counts.count1[1])
            player:addItem(cid, items.item1[2], counts.count1[2])
            selfSay('You just swap '.. counts.count1[1] ..' '.. getItemName(items.item1[1]) ..' for '.. counts.count1[2] ..' '.. getItemName(items.item1[2]) ..'.', cid)
        else
            selfSay('You need '.. counts.count1[1] ..' '.. getItemName(items.item1[1]) ..'.', cid)
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
X
Having 2 tables makes no sense to me, but whatever lol

Should work as intended, now.
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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

local items = {
    item1 = {8266} -- [ITEMID]
}
local counts = {
    count1 = {30, 1}  -- [PRICE, ITEM AMOUNT]
}

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if(not...
Change item1[2] to item1[1].

LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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

local items = {
        item1 = {8266} -- [ITEMID]
}
local counts = {
        count1 = {30, 1}  -- [PRICE, ITEM AMOUNT]
}

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if  msgcontains(msg, 'event boost') then
        if player:getStorageValue(25335) >= counts.count1[1] then
            player:setStorageValue(25335, player:getStorageValue(25335) + counts.count1[1])
            player:addItem(cid, items.item1[1], counts.count1[2])
            selfSay('You just swap '.. counts.count1[1] ..' '.. getItemName(items.item1[1]) ..' for '.. counts.count1[2] ..' '.. getItemName(items.item1[1]) ..'.', cid)
        else
            selfSay('You need '.. counts.count1[1] ..' '.. getItemName(items.item1[1]) ..'.', cid)
        end
    end
    return true
end

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

Post the console errors if you have, it is easier to solve.
 
Change item1[2] to item1[1].

LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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

local items = {
        item1 = {8266} -- [ITEMID]
}
local counts = {
        count1 = {30, 1}  -- [PRICE, ITEM AMOUNT]
}

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if  msgcontains(msg, 'event boost') then
        if player:getStorageValue(25335) >= counts.count1[1] then
            player:setStorageValue(25335, player:getStorageValue(25335) + counts.count1[1])
            player:addItem(cid, items.item1[1], counts.count1[2])
            selfSay('You just swap '.. counts.count1[1] ..' '.. getItemName(items.item1[1]) ..' for '.. counts.count1[2] ..' '.. getItemName(items.item1[1]) ..'.', cid)
        else
            selfSay('You need '.. counts.count1[1] ..' '.. getItemName(items.item1[1]) ..'.', cid)
        end
    end
    return true
end

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

Post the console errors if you have, it is easier to solve.
Same doesnt give, and it adds points. No errors in console
 
Having 2 tables makes no sense to me, but whatever lol

Should work as intended, now.
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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

local items = {
    item1 = {8266} -- [ITEMID]
}
local counts = {
    count1 = {30, 1}  -- [PRICE, ITEM AMOUNT]
}

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  
    if  msgcontains(msg, 'event boost') then
        if player:getStorageValue(25335) >= counts.count1[1] then
            player:setStorageValue(25335, player:getStorageValue(25335) - counts.count1[1])
            player:addItem(items.item1[1], counts.count1[2], true)
            --selfSay('You just swap '.. counts.count1[1] ..' '.. getItemName(items.item1[1]) ..' for '.. counts.count1[2] ..' '.. getItemName(items.item1[2]) ..'.', cid)
            selfSay('Is there something missing from the first table? because the line above this makes no sense..', cid)
        else
            selfSay('You need '.. counts.count1[1] ..' '.. getItemName(items.item1[1]) ..'.', cid)
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited by a moderator:
Solution
Having 2 tables makes no sense to me, but whatever lol

Should work as intended, now.
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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

local items = {
    item1 = {8266} -- [ITEMID]
}
local counts = {
    count1 = {30, 1}  -- [PRICE, ITEM AMOUNT]
}

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
    if  msgcontains(msg, 'event boost') then
        if player:getStorageValue(25335) >= counts.count1[1] then
            player:setStorageValue(25335, player:getStorageValue(25335) - counts.count1[1])
            player:addItem(cid, items.item1[1], counts.count1[2])
            --selfSay('You just swap '.. counts.count1[1] ..' '.. getItemName(items.item1[1]) ..' for '.. counts.count1[2] ..' '.. getItemName(items.item1[2]) ..'.', cid)
            selfSay('Is there something missing from the first table? because the line above this makes no sense..', cid)
        else
            selfSay('You need '.. counts.count1[1] ..' '.. getItemName(items.item1[1]) ..'.', cid)
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Yea it looks old school, but thats the script i got, cant do much about it :D i does remove points now but it doesnt give an item 8266
 
Yea it looks old school, but thats the script i got, cant do much about it :D i does remove points now but it doesnt give an item 8266
oh I see.
The script is using incorrect parameters for that function.

I've updated my post with the corrected parameters.
 
Back
Top