Ir para conteúdo
  • Cadastre-se

(Resolvido)Npc que libera passagem


Ir para solução Resolvido por Dwarfer,

Posts Recomendados

Olá Tk, gostaria de ajuda com um npc, que libera-se a passagem em um piso x.

Seria basicamente assim, tu falaria com o npc, e ele ia pedir 30 itens, exemplo. "Gostaria de entrar na cidade das almas perdidas?, Yes."  "Traga- me 30 pieces of hellfire armor e lhe liberarei a passage

Depois disso voce poderia passar no piso indicado pelo player na foto

 

 

 

 

21369125_1997844970450208_6535982898707898956_n.png

Editado por FaaSouzax (veja o histórico de edições)
Link para o post
Compartilhar em outros sites

Em npcs/scripts, crie um arquivo.lua:

 

npcpermissao.lua

 

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

local storage = 56790
local item = {1111, 30} --id do item, quantidade

function creatureSayCallback(cid, type, msg)
    local msg = string.lower(msg)
    if not npcHandler:isFocused(cid) then
        if isInArray({"hi", "hello"}, msg) then
            npcHandler:addFocus(cid)
            if getPlayerStorageValue(cid, storage) == -1 then
                npcHandler:say("Hi, ".. getPlayerName(cid).."! I can give you the permission to {enter} at Lost Souls' City.", cid)
                npcTopic[cid] = 1
            else
                npcHandler:say("You already have my permission to enter.", cid)
                npcTopic[cid] = 0
                npcHandler:releaseFocus(cid)
            end
        else
            return false 
        end
    elseif msgcontains(msg, "enter") and npcTopic[cid] == 1 then
        npcHandler:say("I need ".. item[2] .. " " .. getItemNameById(item[1])..". Do you have it?", cid)
        npcTopic[cid] = 2
    elseif msgcontains(msg, "yes") and npcTopic[cid] == 2 then
        if doPlayerRemoveItem(cid, item[1], item[2]) then
            setPlayerStorageValue(cid, storage, 1)
            npcHandler:say("Ok, now you can enter.", cid)
            npcTopic[cid] = 0
        else
            npcHandler:say("Sorry but you don't have the items I need.", cid)
            npcTopic[cid] = 0
        end
    elseif msgcontains(msg, "no") and npcTopic[cid] == 2 then
        npcHandler:say("Ok, maybe on the next time.", cid)
        npcTopic[cid] = 0
    elseif msgcontains(msg, "bye") then
        npcHandler:say("Bye.", cid)
        npcHandler:releaseFocus(cid)
    else
        npcHandler:say("What?", cid)
        npcTopic[cid] = 0
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

 

 

O xml do npc:

 

Spoiler

<?xml version="1.0" encoding="UTF-8"?>
<npc name="Passagem" script="npcpermissao.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="139" head="20" body="39" legs="45" feet="7" addons="0"/>
</npc>

 

 

Edite as falas, o nome de npc e tudo mais. Apenas coloquei para te servir como base.

 

Tile pra verificar a permissão do npc:

Em movements/scripts:

 

tilepermission.lua

 

Spoiler

local storage = 56790

function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
if getPlayerStorageValue(cid, storage) == -1 then
doPlayerSendCancel(cid, "You should pay to enter.")
doTeleportThing(cid, fromPosition)
end
return true
end

 

 

 

Em movements.xml, adicione a tag: <movevent type="StepIn" actionid="ACTION_ID_DO_PISO" event="script" value="tilepermission.lua"/>

 

Contato:

 

Link para o post
Compartilhar em outros sites

Bem, não se se eu tinha que mudar mais algo, mas a unica coisa que mudei foi o item e uma fala.

E quando eu digo "enter" da esse erro no console.

5mL8HJHzRbeqTdf2ynQ7ug.png

 

 

e também o movements não esta bloqueando a passagem.

Link para o post
Compartilhar em outros sites

Tfs 3.7 se eu não estiver enganado, faz pouco tempo que voltei a mexer em servers ;x

gMDx9A8fSvKtH_cvGbLfoA.png

 

 

o npc esta assim

 

 

 

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

local storage = 56790
local item = {10581, 30} --id do item, quantidade

function creatureSayCallback(cid, type, msg)
    local msg = string.lower(msg)
    if not npcHandler:isFocused(cid) then
        if isInArray({"hi", "hello"}, msg) then
            npcHandler:addFocus(cid)
            if getPlayerStorageValue(cid, storage) == -1 then
                npcHandler:say("Hi, ".. getPlayerName(cid).."! I can give you the permission to {enter} at Souls Eaters City.", cid)
                npcTopic[cid] = 1
            else
                npcHandler:say("You already have my permission to enter.", cid)
                npcTopic[cid] = 0
                npcHandler:releaseFocus(cid)
            end
        else
            return false 
        end
    elseif msgcontains(msg, "enter") and npcTopic[cid] == 1 then
        npcHandler:say("I need ".. item[2] .. " " .. getItemNameById(item[1])..". Do you have it?", cid)
        npcTopic[cid] = 2
    elseif msgcontains(msg, "yes") and npcTopic[cid] == 2 then
        if doPlayerRemoveItem(cid, item[1], item[2]) then
            setPlayerStorageValue(cid, storage, 1)
            npcHandler:say("Ok, now you can enter.", cid)
            npcTopic[cid] = 0
        else
            npcHandler:say("Sorry but you don't have the items I need.", cid)
            npcTopic[cid] = 0
        end
    elseif msgcontains(msg, "no") and npcTopic[cid] == 2 then
        npcHandler:say("Ok, maybe on the next time.", cid)
        npcTopic[cid] = 0
    elseif msgcontains(msg, "bye") then
        npcHandler:say("Bye.", cid)
        npcHandler:releaseFocus(cid)
    else
        npcHandler:say("What?", cid)
        npcTopic[cid] = 0
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

 

 

 

Editado por FaaSouzax (veja o histórico de edições)
Link para o post
Compartilhar em outros sites
  • Solução

Sim, a versão era diferente. Usa assim:

 

Spoiler

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


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

local storage = 56790
local item = {10581, 30} --id do item, quantidade

function creatureSayCallback(cid, type, msg)
    local msg, player = string.lower(msg), Player(cid)
    if not npcHandler:isFocused(cid) then
        if isInArray({"hi", "hello"}, msg) then
            npcHandler:addFocus(cid)
            if player:getStorageValue(storage) == -1 then
                npcHandler:say("Hi, ".. player:getName().."! I can give you the permission to {enter} at Lost Souls' City.", cid)
                npcHandler.topic[cid] = 1
            else
                npcHandler:say("You already have my permission to enter.", cid)
                npcHandler.topic[cid] = 0
                npcHandler:releaseFocus(cid)
            end
        else
            return false 
        end
    elseif msgcontains(msg, "enter") and npcHandler.topic[cid] == 1 then
        npcHandler:say("I need ".. item[2] .. " " .. getItemName(item[1])..". Do you have it?", cid)
         npcHandler.topic[cid] = 2
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
        if player:removeItem(item[1], item[2]) then
            player:setStorageValue(storage, 1)
            npcHandler:say("Ok, now you can enter.", cid)
             npcHandler.topic[cid] = 0
        else
            npcHandler:say("Sorry but you don't have the items I need.", cid)
             npcHandler.topic[cid] = 0
        end
    elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 2 then
        npcHandler:say("Ok, maybe on the next time.", cid)
         npcHandler.topic[cid] = 0
    elseif msgcontains(msg, "bye") then
        npcHandler:say("Bye.", cid)
        npcHandler:releaseFocus(cid)
    else
        npcHandler:say("What?", cid)
         npcHandler.topic[cid] = 0
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

 

 

Spoiler

local storage = 56790

function onStepIn(creature, item, position, fromPosition)
if not creature:isPlayer() then return true end
if creature:getStorageValue(storage) == -1 then
    creature:sendCancelMessage("You should pay to enter.")
    creature:teleportTo(fromPosition)
end
	return true
end

 

 

<movevent event="StepIn" actionid="ACTION_ID_DO_PISO" script="tilepermission.lua" />

Contato:

 

Link para o post
Compartilhar em outros sites
  • 2 years later...

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.

Visitante
Responder

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo