0.4
Hello guys, I'm trying to do a NPC something like this:
Player says something to him, there is a chance of the npc desappears and, if he desappears, he will appears again later.
Until now, I made this:
But he does not get removed if math random is right and nether get created again, and this is how I know:
[22/4/2022 14:11:25] [Warning - Npc::createNpc] Cannot find npc with name: Test NPC.
[22/4/2022 14:11:26] [Error - NpcScript Interface]
[22/4/2022 14:11:26] In a timer event called from:
[22/4/2022 14:11:26] data/npc/scripts/EF westfall sem teto.luanCreatureSay
[22/4/2022 14:11:26] Description:
[22/4/2022 14:11:26] (luaDoCreateNpc) Npc with name 'Test NPC' not found
What can I do?
Hello guys, I'm trying to do a NPC something like this:
Player says something to him, there is a chance of the npc desappears and, if he desappears, he will appears again later.
Until now, I made this:
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, 'help')) then
if getPlayerStorageValue(cid,877541) == -1 then
selfSay('Leave me alone.', cid)
else
selfSay('{yes}?', cid)
end
end
if(msgcontains(msg, 'yes')) then
rand = math.random(0, 100)
if rand >= 85 then
selfSay('1', cid)
else
selfSay('2', cid)
doRemoveCreature(getCreatureByName('Test NPC'))
addEvent(function()
local pos1 = {x = 848, y = 1106, z = 7}
doCreateNpc('Test NPC', pos1)
end, 4000)
return true
end
end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
But he does not get removed if math random is right and nether get created again, and this is how I know:
[22/4/2022 14:11:25] [Warning - Npc::createNpc] Cannot find npc with name: Test NPC.
[22/4/2022 14:11:26] [Error - NpcScript Interface]
[22/4/2022 14:11:26] In a timer event called from:
[22/4/2022 14:11:26] data/npc/scripts/EF westfall sem teto.luanCreatureSay
[22/4/2022 14:11:26] Description:
[22/4/2022 14:11:26] (luaDoCreateNpc) Npc with name 'Test NPC' not found
What can I do?