ziggy46802
Active Member
- Joined
- Aug 19, 2012
- Messages
- 418
- Reaction score
- 27
Okay, here is my script
bpquest2.lua
And I'm getting the error in my console this:
Lua Script Error: [Npc interface]
data/npc/scripts/bpquest2.lua
data/npc/scripts/lib/npc.lua:32: bag argument #1 to 'find' <string expected, got nil>
Warning: [NpcScript::NpcScript] Can not load script. data/npc/scripts/bpquest2.lua
npc.lua
I wrote "THIS IS LINE 32" where line 32 is so you can easily find it.
bpquest2.lua
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
---------------------------------------------------------------------------
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, 'backpack')) and
(getPlayerStorageValue(cid, 1009) == 1) then
setPlayerStorageValue(cid, 1009, 2)
selfSay("Yes, I do sell backpacks, brown ones if thats {good} enough for you.", cid)
else
selfsay("What backpack are you talking about, you've lost your mind man.", cid)
end
end
if(msgcontains(msg, 'good')) then
if(getPlayerStorageValue(cid, 1009) > 1) then
selfSay("Oh wow he did a terrible job on this piece of shit. Let me see if I can fix it up. Wait, all you have to do is this and that and this and this and bam! Here you go my friend, I hope you enjoy this piece of fuckin awesomeness.", cid)
setPlayerStorageValue(cid, 1009, 3)
setPlayerStorageValue(cid, 1011, 2)
doPlayerAddItem(cid, 2365, 1)
doPlayerRemoveItem(cid, 7342, 1)
else
selfSay("Good what? Lots of things are good, especially my shit I sell!", cid)
end
end
if(msgcontains(msg, 'more')) and
(getPlayerStorageValue(cid, 1011) == 2) then
selfSay("What you want more? God damn man if you can't accept that gift you can't get nothin.", cid)
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
-------------------------------------------------------------------------------
local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)
shopModule:addBuyableItem({'brown backpack'}, 1988, 20, 1,'brown backpack')
shopModule:addBuyableItem({'brown bag'}, 1987, 5, 1,'brown bag')
shopModule:addBuyableItem({'fishing rod'}, 2580, 150, 1,'fishing rod')
shopModule:addBuyableItem({'machete'}, 2420, 35, 1,'machete')
shopModule:addBuyableItem({'pick'}, 2553, 50, 1,'pick')
shopModule:addBuyableItem({'rope'}, 2120, 50, 1,'rope')
shopModule:addBuyableItem({'scythe'}, 2550, 50, 1,'scythe')
shopModule:addBuyableItem({'shovel'}, 2554, 50, 1,'shovel')
shopModule:addBuyableItem({'worm'}, 3976, 1, 1,'worm')
npcHandler:addModule(FocusModule:new())
And I'm getting the error in my console this:
Lua Script Error: [Npc interface]
data/npc/scripts/bpquest2.lua
data/npc/scripts/lib/npc.lua:32: bag argument #1 to 'find' <string expected, got nil>
Warning: [NpcScript::NpcScript] Can not load script. data/npc/scripts/bpquest2.lua
npc.lua
I wrote "THIS IS LINE 32" where line 32 is so you can easily find it.
Code:
-- Include external classes.
dofile(getDataDir() .. 'npc/scripts/lib/npcsystem/npcsystem.lua')
-- Callback for isPremium(cid) so Jiddo's npcsystem works
isPlayerPremiumCallback = isPremium
-- get the distance to a creature
-- deprecated function
function getDistanceToCreature(id)
debugPrint('getDistanceToCreature(): deprecated function. Use getDistanceTo()')
return getDistanceTo(id)
end
-- move to a creature
function moveToCreature(id)
if(isCreature(id) == false) then
debugPrint('moveToCreature(): creature not found.')
return false
end
local pos = getCreaturePosition(id)
selfMoveTo(pos.x, pos.y, pos.z)
return true
end
function selfGotoIdle()
debugPrint('selfGotoIdle(): deprecated function. Do not use it anymore!')
return nil
end
--LINE 31
--THIS IS LINE 32 function msgcontains(message, keyword)
local a, b = string.find(message, keyword)
if a == nil or b == nil then
return false
end
return true
end
function doCreatureSayWithDelay(cid,text,type,delay,e)
if delay<=0 then
doCreatureSay(cid,text,type)
else
local func=function(pars)
doCreatureSay(pars.cid,pars.text,pars.type)
pars.e.done=TRUE
end
e.done=FALSE
e.event=addEvent(func,delay,{cid=cid, text=text, type=type, e=e})
end
end
--returns how many msgs he have said already
function cancelNPCTalk(events)
local ret=1
for aux=1,table.getn(events) do
if events[aux].done==FALSE then
stopEvent(events[aux].event)
else
ret=ret+1
end
end
events=nil
return(ret)
end
function doNPCTalkALot(msgs,interval)
local e={}
local ret={}
if interval==nil then
interval=3000 --3 seconds is default time between messages
end
for aux=1,table.getn(msgs) do
e[aux]={}
doCreatureSayWithDelay(getNpcCid(),msgs[aux],TALKTYPE_SAY,(aux-1)*interval,e[aux])
table.insert(ret,e[aux])
end
return(ret)
end