Postado Abril 24, 2020 5 anos Criei um npc, mas quando eu digo missão ele não faz nada. Também não dá nenhum erro no console, sei apenas o básico do básico em lua, mesmo assim resolvi tentar criar. Este é o script: Spoiler local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local npcTopic = {} 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 npcHandler:onThink() local npcTopic = {} function creatureSayCallback(cid, type, msg) local talkUser, msg = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid, string.lower(msg) if(not npcHandler:isFocused(cid)) then if isInArray({"hi", "hello", "Oi"}, msg) then if getPlayerStorageValue(cid, 12101) >= 2 then selfSay("Você já completou todas as Missões!", cid) else if getPlayerStorageValue(cid, 13256) >= 2 then npcHandler:say("Você vai para a ultima missão!.", cid) -- configurar depois else npcHandler:say("Olá, "..getPlayerName(cid)..". você deseja fazer a {missao} para aprender a nova magia?.", cid) if msgcontains(msg, "missao") and npcTopic[talkUser] == 1 then npcHandler:say("vá e me traga os itens!.", cid) setPlayerStorageValue(cid, 1456,1) npcTopic[talkUser] = 0 end if getPlayerStorageValue(cid, 1456) and npcTopic[talkUser] == 1 then npcHandler:say("Olá, "..getPlayerName(cid)..". você deseja entregar os {itens} para aprender a nova magia?.", cid) if msgcontains(msg, "itens") and npcTopic[talkUser] == 1 then doPlayerRemoveItem(cid, 2160, 20) setPlayerStorageValue(cid, 13256, 1) npcHandler:say("Você completou a primeira missão.", cid) npcTopic[talkUser] = 0 else npcHandler:say("Você ainda não tem os itens necessários!", cid) npcTopic[talkUser] = 0 end end return true end end end end end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) o codigo parece meio "podre" ao meu ver, perdão.
Postado Abril 24, 2020 5 anos @MarkCharlotte Tenta assim: Spoiler 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 local talkUser, msg = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid, string.lower(msg) if(not npcHandler:isFocused(cid)) then if isInArray({"hi", "hello", "Oi"}, msg) then if getPlayerStorageValue(cid, 12101) >= 2 then selfSay("Você já completou todas as Missões!", cid) else if getPlayerStorageValue(cid, 13256) >= 2 then npcHandler:say("Você vai para a ultima missão!.", cid) -- configurar depois else npcHandler:say("Olá, "..getPlayerName(cid)..". você deseja fazer a {missao} para aprender a nova magia?.", cid) if msgcontains(msg, "missao") and talkState[talkUser] == 0 then npcHandler:say("vá e me traga os itens!.", cid) setPlayerStorageValue(cid, 1456,1) talkState[talkUser] = 1 end if getPlayerStorageValue(cid, 1456) and talkState[talkUser] == 1 then npcHandler:say("Olá, "..getPlayerName(cid)..". você deseja entregar os {itens} para aprender a nova magia?.", cid) if msgcontains(msg, "itens") and talkState[talkUser] == 1 then doPlayerRemoveItem(cid, 2160, 20) setPlayerStorageValue(cid, 13256, 1) npcHandler:say("Você completou a primeira missão.", cid) talkState[talkUser] = 0 else npcHandler:say("Você ainda não tem os itens necessários!", cid) talkState[talkUser] = 1 end end return true end end end end end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new())
Postado Abril 24, 2020 5 anos Autor @Storm quando eu digito "hi", ele diz "Welcome, Enemy! I have been expecting you." e quando digito "missao" não acontece nada
Postado Abril 25, 2020 5 anos @Vikachu @MarkCharlotte Só não da bola pras coisas que eu escrevi, acordei inspirado kkk Quote 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 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 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 end --3 seconds is default time between messages for aux=1,table.getn(msgs) do e[aux]={} doCreatureSayWithDelay(getNpcCid(),msgs[aux],TALKTYPE_PRIVATE_NP,(aux-1)*interval,e[aux]) table.insert(ret,e[aux]) end return(ret) 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, 'hi') or msgcontains(msg, 'oi')) and getPlayerStorageValue(cid,1001) == -1 then selfSay('Olá, "..getPlayerName(cid)..". você deseja fazer a {missao} para aprender a nova magia?', cid) talkState[talkUser] = 1 elseif((msgcontains(msg, 'quest') or msgcontains(msg, 'missao')) and talkState[talkUser] == 1) then selfSay('anda logo entao traste, vai e me tras uns 20 item do id 2160, se vira ai pra achar', cid) talkState[talkUser] = 0 setPlayerStorageValue(cid, 1001, 1) setPlayerStorageValue(cid, 1002, 1) elseif(msgcontains(msg, 'hi') or msgcontains(msg, 'oi')) and getPlayerStorageValue(cid,1002) == 1 then selfSay('Conseguiu pegar essas merda ae, ja ta quase noite', cid) talkState[talkUser] = 2 elseif(msgcontains(msg, 'Yes') or msgcontains(msg, 'sim')) and talkState[talkUser] == 2 and getPlayerItemCount(cid, 2160) < 1 then selfSay('tu nem tem nada, vai tmc mlk, rala.', cid) talkState[talkUser] = 0 elseif((msgcontains(msg, 'No') or msgcontains(msg, 'nao')) and talkState[talkUser] == 2) then selfSay('bah,imprestavel mesmo.', cid) talkState[talkUser] = 0 elseif(msgcontains(msg, 'Yes') or msgcontains(msg, 'sim')) and getPlayerStorageValue(cid,1002) == 1 and talkState[talkUser] == 2 and getPlayerItemCount(cid, 2160) == 1 then selfSay('Vlw ae, e nois truta!', cid) doPlayerAddItem(cid, 2160, 100) -- Se quiser add mais algum item junto, ou deleta essa linha doPlayerRemoveItem(cid, 2160, 20) setPlayerStorageValue(cid, 13256, 1) end return TRUE end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) Editado Abril 25, 2020 5 anos por Hologram (veja o histórico de edições)
Participe da conversa
Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.