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

Token Npc Script....Errors

RockeTBunnYz

Trainee in progress
Joined
Jan 21, 2015
Messages
137
Reaction score
7
Location
sweden
Hey, i was writing and adding this script to my server and got this error but i cant find it anyway and there was some EOF error too...

Code:
[18:34:45.368] [Error - LuaInterface::loadFile] data/npc/scripts/tokentrader.lua
:32: unexpected symbol near '=='
[18:34:45.370] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scr
ipts/tokentrader.lua
[18:34:45.371] data/npc/scripts/tokentrader.lua:32: unexpected symbol near '=='
[18:34:45.580] [Notice - Npc::Npc] NPC Name: Frenzy - autowalk has been deprecat
ed, use walkinterval.
[18:34:45.582] [Error - LuaInterface::loadFile] data/npc/scripts/tokentrader.lua
:32: unexpected symbol near '=='
[18:34:45.583] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scr
ipts/tokentrader.lua
[18:34:45.584] data/npc/scripts/tokentrader.lua:32: unexpected symbol near '=='

here is my scripts can someone please help me make it work .....
Code:
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 t = {
tokens = 5468, -- id of tokens
items = {
[1] = {"boots of haste", 10, 2195},
[2] = {"demon helmet", 10, 2493},
}
}

local function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
        end
if msgcontains(msg, 'boots of haste') then
if getPlayerItemCount(cid,t.tokens,10) == true then                 -- 10 Game Tokens
selfSay('Did you bring me 10 game tokens?', cid)
else
selfSay('Sorry, I need you to have atleast {10 game tokens} . Come back when you have them.', cid)
    end
        end

if msgcontains(msg,'yes') then
    if getPlayerItemCount(cid,t.tokens,10) == true then
    doPlayerRemoveItem(cid,t.tokens,10) == true then
    doPlayerAddItem(cid,t.items > [1]) then                            ---- boots of haste
        selfSay"Here you go!" 
            end
if msgcontains(msg, 'demon helmet') then
if getPlayerItemCount(cid,t.tokens,10) == true then                 -- 10 Game Tokens
selfSay('Did you bring me 10 game tokens?', cid)
else
selfSay('Sorry, I need you to have atleast {10 game tokens} . Come back when you have them.', cid)
end
    end

if msgcontains(msg,'yes') then
    if getPlayerItemCount(cid,t.tokens,10) == true then
    doPlayerRemoveItem(cid,t.tokens,10) == true then
    doPlayerAddItem(cid,t.items > [2]) then                            ----- demon helmet
        selfSay"Here you go!" 
        end
    end

please help !!
 
We are going to simplify this script to reduce the chances of clerical errors
Code:
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 tokens = 5468, -- id of tokens
local items = {
    ["boots of haste"] = {
        amount = 10,
        id = 2195
    },
    ["demon helmet"] = {
        amount = 10,
        id = 2493
    }
}

local itemToGive = {}

local function asksForCorrectItem(msg)
    if isInArray(items, string.lower(msg)) then
        return true
    end
    return false
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 asksForCorrectItem(msg) then
        selfSay('Did you bring me "..items[string.lower(msg)][amount].." game tokens?', cid)
        itemToGive = items[string.lower(msg)]
        talkState[talkUser] = 1
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
        if doPlayerRemoveItem(cid, tokens, itemToGive.amount) then
            doPlayerAddItem(cid, itemToGive.id)                            
            selfSay("Here you go!", cid)]
            talkState[talkUser] = 0
        else
            selfSay('Sorry, you need to have atleast {'..itemToGive.amount..' game tokens} . Come back when you have them.', cid)
            talkState[talkUser] = 0
        end
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay('Come back when you have {'..itemToGive.amount..' game tokens}.', cid)
        talkState[talkUser] = 0
    else
        selfSay('Sorry, I don't sell '..msg, cid)
        talkState[talkUser] = 0
    end
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
We are going to simplify this script to reduce the chances of clerical errors
Code:
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 tokens = 5468, -- id of tokens
local items = {
    ["boots of haste"] = {
        amount = 10,
        id = 2195
    },
    ["demon helmet"] = {
        amount = 10,
        id = 2493
    }
}

local itemToGive = {}

local function asksForCorrectItem(msg)
    if isInArray(items, string.lower(msg)) then
        return true
    end
    return false
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 asksForCorrectItem(msg) then
        selfSay('Did you bring me "..items[string.lower(msg)][amount].." game tokens?', cid)
        itemToGive = items[string.lower(msg)]
        talkState[talkUser] = 1
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
        if doPlayerRemoveItem(cid, tokens, itemToGive.amount) then
            doPlayerAddItem(cid, itemToGive.id)                           
            selfSay("Here you go!", cid)]
            talkState[talkUser] = 0
        else
            selfSay('Sorry, you need to have atleast {'..itemToGive.amount..' game tokens} . Come back when you have them.', cid)
            talkState[talkUser] = 0
        end
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay('Come back when you have {'..itemToGive.amount..' game tokens}.', cid)
        talkState[talkUser] = 0
    else
        selfSay('Sorry, I don't sell '..msg, cid)
        talkState[talkUser] = 0
    end
end

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

unexpected symbol near "local" ....... cant find it ...
 
haha clerical error
Code:
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 tokens = 5468 -- id of tokens
local items = {
    ["boots of haste"] = {
        amount = 10,
        id = 2195
    },
    ["demon helmet"] = {
        amount = 10,
        id = 2493
    }
}

local itemToGive = {}

local function asksForCorrectItem(msg)
    if isInArray(items, string.lower(msg)) then
        return true
    end
    return false
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 asksForCorrectItem(msg) then
        selfSay('Did you bring me "..items[string.lower(msg)][amount].." game tokens?', cid)
        itemToGive = items[string.lower(msg)]
        talkState[talkUser] = 1
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
        if doPlayerRemoveItem(cid, tokens, itemToGive.amount) then
            doPlayerAddItem(cid, itemToGive.id)                             
            selfSay("Here you go!", cid)]
            talkState[talkUser] = 0
        else
            selfSay('Sorry, you need to have atleast {'..itemToGive.amount..' game tokens} . Come back when you have them.', cid)
            talkState[talkUser] = 0
        end
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay('Come back when you have {'..itemToGive.amount..' game tokens}.', cid)
        talkState[talkUser] = 0
    else
        selfSay('Sorry, I don't sell '..msg, cid)
        talkState[talkUser] = 0
    end
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
haha clerical error
what does this line mean sir
Code:
local itemToGive = {}
in this script.

haha clerical error
Code:
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 tokens = 5468 -- id of tokens
local items = {
    ["boots of haste"] = {
        amount = 10,
        id = 2195
    },
    ["demon helmet"] = {
        amount = 10,
        id = 2493
    }
}

local itemToGive = {}

local function asksForCorrectItem(msg)
    if isInArray(items, string.lower(msg)) then
        return true
    end
    return false
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 asksForCorrectItem(msg) then
        selfSay('Did you bring me "..items[string.lower(msg)][amount].." game tokens?', cid)
        itemToGive = items[string.lower(msg)]
        talkState[talkUser] = 1
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
        if doPlayerRemoveItem(cid, tokens, itemToGive.amount) then
            doPlayerAddItem(cid, itemToGive.id)                            
            selfSay("Here you go!", cid)]
            talkState[talkUser] = 0
        else
            selfSay('Sorry, you need to have atleast {'..itemToGive.amount..' game tokens} . Come back when you have them.', cid)
            talkState[talkUser] = 0
        end
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay('Come back when you have {'..itemToGive.amount..' game tokens}.', cid)
        talkState[talkUser] = 0
    else
        selfSay('Sorry, I don't sell '..msg, cid)
        talkState[talkUser] = 0
    end
end

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

haha another one unexpected symbol near ']'

found it !
 
Last edited by a moderator:
haha another one unexpected symbol near ']'
Sorry I was writing this without the lua extension or testing it
Should work now
local itemToGive = {} its a temporary container to hold the item table
Code:
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 tokens = 5468 -- id of tokens
local items = {
    ["boots of haste"] = {
        amount = 10,
        id = 2195
    },
    ["demon helmet"] = {
        amount = 10,
        id = 2493
    }
}

local itemToGive = {}

function asksForCorrectItem(msg)
    if isInArray(items, string.lower(msg)) then
        return true
    end
    return false
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 asksForCorrectItem(msg) then
        selfSay('Did you bring me '..items[string.lower(msg)][amount]..' game tokens?', cid)
        itemToGive = items[string.lower(msg)]
        talkState[talkUser] = 1
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
        if doPlayerRemoveItem(cid, tokens, itemToGive.amount) then
            doPlayerAddItem(cid, itemToGive.id)                          
            selfSay("Here you go!", cid)
            talkState[talkUser] = 0
        else
            selfSay('Sorry, you need to have atleast {'..itemToGive.amount..' game tokens} . Come back when you have them.', cid)
            talkState[talkUser] = 0
        end
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay('Come back when you have {'..itemToGive.amount..' game tokens}.', cid)
        talkState[talkUser] = 0
    else
        selfSay("Sorry, I don't sell "..msg, cid)
        talkState[talkUser] = 0
    end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Sorry I was writing this without the lua extension or testing it
Should work now
local itemToGive = {} its a temporary container to hold the item table
Code:
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 tokens = 5468 -- id of tokens
local items = {
    ["boots of haste"] = {
        amount = 10,
        id = 2195
    },
    ["demon helmet"] = {
        amount = 10,
        id = 2493
    }
}

local itemToGive = {}

function asksForCorrectItem(msg)
    if isInArray(items, string.lower(msg)) then
        return true
    end
    return false
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 asksForCorrectItem(msg) then
        selfSay('Did you bring me '..items[string.lower(msg)][amount]..' game tokens?', cid)
        itemToGive = items[string.lower(msg)]
        talkState[talkUser] = 1
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
        if doPlayerRemoveItem(cid, tokens, itemToGive.amount) then
            doPlayerAddItem(cid, itemToGive.id)                        
            selfSay("Here you go!", cid)
            talkState[talkUser] = 0
        else
            selfSay('Sorry, you need to have atleast {'..itemToGive.amount..' game tokens} . Come back when you have them.', cid)
            talkState[talkUser] = 0
        end
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay('Come back when you have {'..itemToGive.amount..' game tokens}.', cid)
        talkState[talkUser] = 0
    else
        selfSay("Sorry, I don't sell "..msg, cid)
        talkState[talkUser] = 0
    end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

yes the scripts is working now but when i try to exchange boots of haste its said he dont sell it and also tested with demon helmet aswell.
 
oke.. hehe.. means its working!! one second
Can you please also explain what line that tell npc to take tokens from player it is this like
Code:
if doPlayerRemoveItem(cid, tokens, itemToGive.amount) then
why itemtogive there in the local for itemtogive there is nothing... lol im confusing
 
Can you please also explain what line that tell npc to take tokens from player it is this like
Code:
if doPlayerRemoveItem(cid, tokens, itemToGive.amount) then
why itemtogive there in the local for itemtogive there is nothing... lol im confusing
itemToGive is a table which will hold the index of items depending on what is asked for
Code:
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 tokens = 5468 -- id of tokens
local items = {
    ["boots of haste"] = {
        amount = 10,
        id = 2195
    },
    ["demon helmet"] = {
        amount = 10,
        id = 2493
    }
}

local itemToGive = {}

-- this will check the table if the index exists
function isInTable(table_t, value)
    if type(table_t) == "table" and value ~= nil then
        for index, v in pairs(table_t) do
            if index == value then
                return true
            end
        end
    end
    return false
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 isInTable(items, string.lower(msg)) then
        selfSay('Did you bring me '..items[string.lower(msg)][amount]..' game tokens?', cid)
        itemToGive = items[string.lower(msg)]
        talkState[talkUser] = 1
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
        if doPlayerRemoveItem(cid, tokens, itemToGive.amount) then
            doPlayerAddItem(cid, itemToGive.id)                          
            selfSay("Here you go!", cid)
            talkState[talkUser] = 0
        else
            selfSay('Sorry, you need to have atleast {'..itemToGive.amount..' game tokens} . Come back when you have them.', cid)
            talkState[talkUser] = 0
        end
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay('Come back when you have {'..itemToGive.amount..' game tokens}.', cid)
        talkState[talkUser] = 0
    else
        selfSay("Sorry, I don't sell "..msg, cid)
        talkState[talkUser] = 0
    end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
itemToGive is a table which will hold the index of items depending on what is asked for
Code:
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 tokens = 5468 -- id of tokens
local items = {
    ["boots of haste"] = {
        amount = 10,
        id = 2195
    },
    ["demon helmet"] = {
        amount = 10,
        id = 2493
    }
}

local itemToGive = {}

-- this will check the table if the index exists
function isInTable(table_t, value)
    if type(table_t) == "table" and value ~= nil then
        for index, v in pairs(table_t) do
            if index == value then
                return true
            end
        end
    end
    return false
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 isInTable(items, string.lower(msg)) then
        selfSay('Did you bring me '..items[string.lower(msg)][amount]..' game tokens?', cid)
        itemToGive = items[string.lower(msg)]
        talkState[talkUser] = 1
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
        if doPlayerRemoveItem(cid, tokens, itemToGive.amount) then
            doPlayerAddItem(cid, itemToGive.id)                        
            selfSay("Here you go!", cid)
            talkState[talkUser] = 0
        else
            selfSay('Sorry, you need to have atleast {'..itemToGive.amount..' game tokens} . Come back when you have them.', cid)
            talkState[talkUser] = 0
        end
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay('Come back when you have {'..itemToGive.amount..' game tokens}.', cid)
        talkState[talkUser] = 0
    else
        selfSay("Sorry, I don't sell "..msg, cid)
        talkState[talkUser] = 0
    end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

he dont respone on boots of haste and getting this in serverlog.
Code:
[0:30:58.275] [Error - NpcScript Interface]
[0:30:58.277] data/npc/scripts/tokentrader.lua:onCreatureSay
[0:30:58.278] Description:
[0:30:58.279] data/npc/scripts/tokentrader.lua:45: attempt to concatenate field
'?' (a nil value)
[0:30:58.280] stack traceback:
[0:30:58.281]   data/npc/scripts/tokentrader.lua:45: in function 'callback'
[0:30:58.282]   data/npc/lib/npcsystem/npchandler.lua:385: in function 'onCreatu
reSay'
[0:30:58.283]   data/npc/scripts/tokentrader.lua:8: in function <data/npc/script
s/tokentrader.lua:8>
.......
 
Can you please also explain what line that tell npc to take tokens from player it is this like
Code:
if doPlayerRemoveItem(cid, tokens, itemToGive.amount) then
why itemtogive there in the local for itemtogive there is nothing... lol im confusing
Lets say we asked the npc for boots of haste, itemToGive would be assigned ["boots of haste"] which is a subtable of items its is a the same thing as saying
Code:
itemToGive = items["boots of haste"]
Now itemToGive has the same properties as the index of items["boots of haste"]

Code:
items["boots of haste"].amount 
itemToGive.amount

Would both have the value of 10 for amount.

Code:
items["boots of haste"].id
itemToGive.id
Would both have the value of 2195 for id.
 
Hmm i wonder.. could we cheat?
by changing this line
Code:
 if isInTable(items, string.lower(msg)) then
to this
Code:
if isInTable(items, string.lower(msg)) and msgcontains(msg, msg) then
 
Hmm i wonder.. could we cheat?
by changing this line
Code:
 if isInTable(items, string.lower(msg)) then
to this
Code:
if isInTable(items, string.lower(msg)) and msgcontains(msg, msg) then
that would add 2 way to getting items i think i will try it.

EDIT: its doesnt work getting this shit ... when i try to get items exemple boots of haste and the error show that its callback so i mean like its stop and restart... i think
Code:
[0:45:32.019] [Error - NpcScript Interface]
[0:45:32.020] data/npc/scripts/tokentrader.lua:onCreatureSay
[0:45:32.021] Description:
[0:45:32.022] data/npc/scripts/tokentrader.lua:45: attempt to concatenate field
'?' (a nil value)
[0:45:32.023] stack traceback:
[0:45:32.024]   data/npc/scripts/tokentrader.lua:45: in function 'callback'
[0:45:32.025]   data/npc/lib/npcsystem/npchandler.lua:385: in function 'onCreatu
reSay'
[0:45:32.026]   data/npc/scripts/tokentrader.lua:8: in function <data/npc/script
s/tokentrader.lua:8>
 
Sorry now i tested it, should work now ... crosses fingers :)
Code:
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 tokens = 5468 -- id of tokens
local items = {
    ["boots of haste"] = {
        amount = 10,
        id = 2195
    },
    ["demon helmet"] = {
        amount = 10,
        id = 2493
    }
}

local itemToGive = {}

-- this will check the table if the index exists
function isInTable(table_t, value)
    if type(table_t) == "table" and value ~= nil then
        for index, v in pairs(table_t) do
            if index == value then
                return true
            end
        end
    end
    return false
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 isInTable(items, string.lower(msg)) then
        selfSay('Did you bring me {'..items[string.lower(msg)].amount..' game tokens}?', cid)
        itemToGive = items[string.lower(msg)]
        talkState[talkUser] = 1
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
        if doPlayerRemoveItem(cid, tokens, itemToGive.amount) then
            doPlayerAddItem(cid, itemToGive.id)                           
            selfSay("Here you go!", cid)
            talkState[talkUser] = 0
        else
            selfSay('Sorry, you need to have atleast {'..itemToGive.amount..' game tokens} . Come back when you have them.', cid)
            talkState[talkUser] = 0
        end
    elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
        selfSay('Come back when you have {'..itemToGive.amount..' game tokens}.', cid)
        talkState[talkUser] = 0
    else
        selfSay("Sorry, I don't sell "..msg, cid)
        talkState[talkUser] = 0
    end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Thanks for this, I learned a lot about the npc and how to add items :)

haha thanks you !! you are the best ! now its all working fine haha this was to advance for me with string and stuff :D you did took my script and change it? or did you write all by youself hehehe

Well, good night eought coding for today to much for me haha cyyaa
 
Last edited by a moderator:
You can also do it like this.
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState, xmsg = {}, {}

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 tokens = 5468 -- id of tokens
local items = {
  ["boots of haste"] = {
      amount = 10,
      id = 2195
  },
  ["demon helmet"] = {
      amount = 20,
      id = 2493
  }
}

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

     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

     local x = items[msg:lower()]
     if x then
         selfSay('Did you bring me '..x.amount..' game tokens?', cid)
         xmsg = msg
         talkState[talkUser] = 1
     elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
         x = items[xmsg:lower()]
         if doPlayerRemoveItem(cid, tokens, x.amount) then
             doPlayerAddItem(cid, x.id, 1)
             selfSay("Here you go!", cid)
         else
             selfSay('Sorry, you need to have atleast {'..x.amount..' game tokens} . Come back when you have them.', cid)
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
         selfSay('Come back when you have enough game tokens.', cid)
         talkState[talkUser] = 0
     else
         selfSay("Sorry, I don't sell "..msg, cid)
         talkState[talkUser] = 0
     end
     return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top