Ola,
Criei um npc que o objetivo era retirar o itens 2195 em troca de algumas vantagens. Até ai tudo bem, só que na hora de executar acontece um erro.
Segue abaixo informações
The Forgotten Server, version 0.3.6 (Crying Damson)
Versão 8,54
treiner.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
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, 'vip')) then
selfSay('Quer comprar vip por 8 Treiner Coins?', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if(getPlayerItemCount(cid, 2159) >= 8) then
if(doPlayerRemoveItem(cid, 2159, 8)) then
local item = getPlayerItemById(cid, true, 6530)
selfSay('Here you are.', cid)
local price = 8
if doPlayerRemoveItem(cid, 2159, price) == TRUE then
local days = 30
local daysvalue = days * 24 * 60 * 60
local storageplayer = getPlayerStorageValue(cid, 13540)
local timenow = os.time()
if getPlayerStorageValue(cid, 13540) - os.time() <= 0 then
time = timenow + daysvalue
else
time = storageplayer + daysvalue
end
if string.find(tostring(getCreatureName(cid)),"[[Vip]]") then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Foram adicionados ".. days .." dias de VIP no seu character.")
setPlayerStorageValue(cid, 13540, time)
local quantity = math.floor((getPlayerStorageValue(cid, 13540) - timenow)/(24 * 60 * 60))
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Você tem ".. quantity .." dias de VIP restantes.")
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Foram adicionados ".. days .." dias de VIP no seu character.")
setPlayerStorageValue(cid, 13540, time)
local name = getCreatureName(cid)
db.executeQuery("UPDATE `players` SET `name` = '[Vip] "..name.."' WHERE `id` = "..getPlayerGUID(cid)..";")
doRemoveCreature(cid)
end
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Você precisa de "..price.." Treiner Coins para colocar vip.")
end
else
selfSay('Desculpe, você não tem Treiner Coins suficientes.', cid)
end
else
selfSay('Desculpe, você não tem Treiner Coins suficientes.', cid)
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'gender')) then
selfSay('Quer comprar trocar de sexo por 1 Treiner Coin?', cid)
talkState[talkUser] = 2
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2 and getPlayerItemCount(cid, 2159)) >= 1 then
if doPlayerRemoveItem(cid, 2159, 1) == TRUE then
doPlayerSetSex(cid, getPlayerSex(cid) == 0 and 1 or 0)
selfSay('Pronto, pode trocar seu outfit.', cid)
talkState[talkUser] = 0
end
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2 and getPlayerItemCount(cid, 2159)) < 1 then
selfSay('Voce não tem o Treiner Coin.', cid)
talkState[talkUser] = 0
elseif(msgcontains(msg, 'ofertas')) then
selfSay('Posso trocar seu { gender } e tambem vendo { vip }.', cid)
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
talkState[talkUser] = 0
selfSay('Ok então.', cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
treiner.xml
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Treiner Seller" script="treiner.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="128" head="17" body="54" legs="114" feet="0" addons="2"/>
<parameters>
<parameter key="message_greet" value="Oi |PLAYERNAME|, vendo artigos por Treiner Coins. Veja minhas { ofertas }."/>
</parameters>
</npc>
O erro apresentado é(aparece na gui):
[27/02/2011 13:18:11] [Error - Npc interface]
[27/02/2011 13:18:11] data/npc/scripts/treiner.lua:onCreatureSay
[27/02/2011 13:18:11] Description:
[27/02/2011 13:18:11] data/npc/scripts/treiner.lua:65: attempt to compare number with nil
[27/02/2011 13:18:11] stack traceback:
[27/02/2011 13:18:11] data/npc/scripts/treiner.lua:65: in function 'callback'
[27/02/2011 13:18:11] data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[27/02/2011 13:18:11] data/npc/scripts/treiner.lua:8: in function <data/npc/scripts/treiner.lua:8>
Então é isso, seria bom se vocês me ajudassem a resolver essa gambiarra esse npc que estou fazendo.
Aguardo Respostas,
Coyoty