pansuchar
Member
- Joined
- Dec 29, 2008
- Messages
- 68
- Reaction score
- 5
Welcome.
I make task npc and i have a problem:
npc.lua file:
donater.lua file:
- - - Updated - - -
~~refresh
someone can help me?
I make task npc and i have a problem:
PHP:
[17/07/2012 11:56:52] [Error - Npc interface]
[17/07/2012 11:56:52] data/npc/scripts/donater.lua
[17/07/2012 11:56:52] Description:
[17/07/2012 11:56:52] data/npc/lib/npc.lua:54: attempt to index local 'message' (a nil value)
[17/07/2012 11:56:52] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/donater.lua
npc.lua file:
PHP:
-- Include the Advanced NPC System
dofile(getDataDir() .. 'npc/lib/npcsystem/npcsystem.lua')
function selfIdle()
following = false
attacking = false
selfAttackCreature(0)
target = 0
end
function selfSayChannel(cid, message)
return selfSay(message, cid, false)
end
function selfMoveToCreature(id)
if(not id or id == 0) then
return
end
local t = getCreaturePosition(id)
if(not t.x or t.x == nil) then
return
end
selfMoveTo(t.x, t.y, t.z)
return
end
function getNpcDistanceToCreature(id)
if(not id or id == 0) then
selfIdle()
return nil
end
local c = getCreaturePosition(id)
if(not c.x or c.x == 0) then
return nil
end
local s = getCreaturePosition(getNpcId())
if(not s.x or s.x == 0 or s.z ~= c.z) then
return nil
end
return math.max(math.abs(s.x - c.x), math.abs(s.y - c.y))
end
function doMessageCheck(message, keyword)
if(type(keyword) == "table") then
return table.isStrIn(keyword, message)
end
local a, b = message:lower():find(keyword:lower())
if(a ~= nil and b ~= nil) then
return true
end
return false
end
function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
local amount = amount or 1
local subType = subType or 1
local ignoreCap = ignoreCap and true or false
local item = 0
if(isItemStackable(itemid)) then
item = doCreateItemEx(itemid, amount)
if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
return 0, 0
end
return amount, 0
end
local a = 0
if(inBackpacks) then
local container = doCreateItemEx(backpack, 1)
local b = 1
for i = 1, amount do
item = doAddContainerItem(container, itemid, subType)
if(itemid == ITEM_PARCEL) then
doAddContainerItem(item, ITEM_LABEL)
end
if(isInArray({(getContainerCapById(backpack) * b), amount}, i)) then
if(doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR) then
b = b - 1
break
end
a = i
if(amount > i) then
container = doCreateItemEx(backpack, 1)
b = b + 1
end
end
end
return a, b
end
for i = 1, amount do
item = doCreateItemEx(itemid, subType)
if(itemid == ITEM_PARCEL) then
doAddContainerItem(item, ITEM_LABEL)
end
if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
break
end
a = i
end
return a, 0
end
function doRemoveItemIdFromPos (id, n, position)
local thing = getThingFromPos({x = position.x, y = position.y, z = position.z, stackpos = 1})
if(thing.itemid == id) then
doRemoveItem(thing.uid, n)
return true
end
return false
end
donater.lua file:
PHP:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local item1 = 12469
local item2 = 8978
local niebo = {x=195, y=708, z=7, stackpos=255}
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, 'pomoc')) then
selfSay('xxxxxx.)', cid)
end
---------------------------------------------------------
if(msgcontains(msg, 'zadanie 1')) then
selfSay('xxxxx.', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'xxxxxxx') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,160) > 0) then
selfSay('Wykonales juz to zadanie.', cid)
else
if(doPlayerRemoveItem(cid, item1, 1) == TRUE) then
setPlayerStorageValue(cid,160,1)
doPlayerAddExperience(cid,50000)
doSendMagicEffect(fromPosition, CONST_ME_HOLYDAMAGE)
selfSay('xxxxxxx', cid)
else
selfSay('xxxxxxx', cid)
end
end
return true
end
----------------------------------------------------------
if(msgcontains(msg, 'zadanie 2')) then
selfSay('xxxxxxxxx. ', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'teleport') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,160) == 1) then
doTeleportThing(cid, niebo)
end
elseif(msgcontains(msg, 'zniszczylem je') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,160) < 1) then
selfSay('Wykonaj moje poprzednie polecenia...', cid)
elseif (getPlayerStorageValue(cid,161) > 0) then
selfSay('Wykonales juz ta misje.', cid)
elseif (getPlayerStorageValue(cid,35097) > 19) then
setPlayerStorageValue(cid,161,1)
doPlayerAddExperience(cid,150000)
doSendMagicEffect(fromPosition, CONST_ME_HOLYDAMAGE)
selfSay('xxxxxx', cid)
else
selfSay('Wciaz ich nie zniszczyles.', cid)
end
end
return true
end
----------------------------------------------------------
if(msgcontains(msg, 'zadanie 3')) then
selfSay('xxxxxxx ', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'klucz') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,161) < 1) then
selfSay('Wykonaj moje poprzednie polecenia...', cid)
else
if (getPlayerStorageValue(cid,162) > 0) then
selfSay('Wykonales juz wszystkie misje.', cid)
else
if(doPlayerRemoveItem(cid, item2, 1) == TRUE) then
setPlayerStorageValue(cid,162,1)
doPlayerAddExperience(cid,500000)
doPlayerAddItem(cid, 12399, 1)
doSendMagicEffect(fromPosition, CONST_ME_HOLYDAMAGE)
selfSay('xxxxxx', cid)
else
selfSay('Przynies mi ({klucz})', cid)
end
end
end
return true
end
---------------------------------------------------------
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
- - - Updated - - -
~~refresh
someone can help me?