Ir para conteúdo

Featured Replies

Postado

Hiho, eu gostaria de um NPC que sirva para evento. Eu gostaria que ele funcionasse assim:

Ao falar Hi, ele fala "Você quer receber o {premio} do evento?"

Se falar sim, ele vai dar de o item com chances de 1 a 100 (exemplo eu recebo 55 do item 15014). de um x item (ID 15014)

 

DIALOGO:

PLAYER> Hi

NPC> Eu sou o NPC de evento, gostaria de receber seu premio?

PLAYER> Yes

NPC> Ok, aqui está seu item. (Ele pode dar de 1 a 100 o item, o famoso mathrandom)

PLAYER>  Bye

NPC> Adeus!

Resolvido por Dwarfer

Ir para solução
Postado
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 id, count, chance = 15014, 55, 10 -- 10% de chance

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"}, msg) then
            npcHandler:addFocus(cid)
            npcHandler:say("Hi, "..getPlayerName(cid)..". Do you want to receive your prize?", cid)
            npcTopic[talkUser] = 1
        else
            return false
        end
    elseif msgcontains(msg, "yes") and npcTopic[talkUser] == 1 then
        local rand = math.random(1, 100)
        if rand <= chance then
            doPlayerAddItem(cid, id, count)
            npcHandler:say("You are lucky today! Here you are.", cid)
            npcTopic[talkUser] = 0
        else
            npcHandler:say("It wasn't your time to win. Try again in the next!", cid)
            npcTopic[talkUser] = 0
        end
    elseif msgcontains(msg, "no") and npcTopic[talkUser] == 1 then
        npcHandler:say("Alright, then.", cid)
        npcTopic[talkUser] = 0
    elseif msgcontains(msg, "bye") then
        npcHandler:say("Bye.", cid)
        npcHandler:releaseFocus(cid)
    else
        npcHandler:say("WHAT??", cid)
        npcTopic[talkUser] = 0
    end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

 

 

Contato:

 

Postado
  • Autor
27 minutos atrás, Dwarfer disse:
  Ocultar conteúdo


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 id, count, chance = 15014, 55, 10 -- 10% de chance

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"}, msg) then
            npcHandler:addFocus(cid)
            npcHandler:say("Hi, "..getPlayerName(cid)..". Do you want to receive your prize?", cid)
            npcTopic[talkUser] = 1
        else
            return false
        end
    elseif msgcontains(msg, "yes") and npcTopic[talkUser] == 1 then
        local rand = math.random(1, 100)
        if rand <= chance then
            doPlayerAddItem(cid, id, count)
            npcHandler:say("You are lucky today! Here you are.", cid)
            npcTopic[talkUser] = 0
        else
            npcHandler:say("It wasn't your time to win. Try again in the next!", cid)
            npcTopic[talkUser] = 0
        end
    elseif msgcontains(msg, "no") and npcTopic[talkUser] == 1 then
        npcHandler:say("Alright, then.", cid)
        npcTopic[talkUser] = 0
    elseif msgcontains(msg, "bye") then
        npcHandler:say("Bye.", cid)
        npcHandler:releaseFocus(cid)
    else
        npcHandler:say("WHAT??", cid)
        npcTopic[talkUser] = 0
    end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

 

 

Poderia me fazer um edit disso? ao receber o item ser teleportado para as cordenadas:

{x = 1156, y = 1039, z = 7}

Postado
  • Solução
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 id, count, chance = 15014, 55, 10 -- 10% de chance

local newpos = {x = 1156, y = 1039, z = 7}

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"}, msg) then
            npcHandler:addFocus(cid)
            npcHandler:say("Hi, "..getPlayerName(cid)..". Do you want to receive your prize?", cid)
            npcTopic[talkUser] = 1
        else
            return false
        end
    elseif msgcontains(msg, "yes") and npcTopic[talkUser] == 1 then
        local rand = math.random(1, 100)
        if rand <= chance then
            doPlayerAddItem(cid, id, count)
            npcHandler:say("You are lucky today! Here you are.", cid)
            npcTopic[talkUser] = 0
        else
            npcHandler:say("It wasn't your time to win. Try again in the next!", cid)
            npcTopic[talkUser] = 0
        end
        doTeleportThing(cid, newpos)
        doSendMagicEffect(newpos, CONST_ME_TELEPORT)
    elseif msgcontains(msg, "no") and npcTopic[talkUser] == 1 then
        npcHandler:say("Alright, then.", cid)
        npcTopic[talkUser] = 0
    elseif msgcontains(msg, "bye") then
        npcHandler:say("Bye.", cid)
        npcHandler:releaseFocus(cid)
    else
        npcHandler:say("WHAT??", cid)
        npcTopic[talkUser] = 0
    end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

 

 

Contato:

 

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

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.7k

Informação Importante

Confirmação de Termo