Ir para conteúdo
Banner com Efeitos

Featured Replies

Postado

Pronto, aqui está:

local tab = {
    voc = 5, -- newVocationID
    dctime = 5, -- segundos para desconectar o player
    stats = {1, 150, 5}, -- {newLevel, newHealth, newMana} novo level/hp/mana ao trocar a voc
    oldstor = {5432, 1}, -- {storage, value) <- necessários
    newstor = {6543, 2} -- {storage, value) <- que o player receberá
}

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
    
    function changeVoc(cid)
        local playerid, mh, mm = getPlayerGUID(cid), getCreatureMaxHealth(cid), getCreatureMaxMana(cid)
        if(npcHandler:isFocused(cid)) then
            npcHandler:releaseFocus(cid)
        end
        
        setCreatureMaxHealth(cid, tab.stats[2])
        doCreatureAddHealth(cid, -(tab.stats[2] - mh))
        setCreatureMaxMana(cid, tab.stats[3])
        doCreatureAddMana(cid, -(tab.stats[3] - mm))
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        doRemoveCreature(cid)
        db.executeQuery("UPDATE `players` SET `level`="..tab.stats[1]..",`experience`= 0 WHERE `players`.`id`= "..playerid.."")
        return true
    end

    if (msgcontains(msg, 'change')) then
        if (getPlayerStorageValue(cid, tab.oldstor[1]) == tab.oldstor[2]) then
            talkState[talkUser] = 1
            selfSay('If you choose to change your vocation, your level, health and mana will return as a level '..tab.stats[1]..'..', cid)
            selfSay('Are you sure you want this?', cid)
        else
            talkState[talkUser] = 0
            npcHandler:releaseFocus(cid)
            selfSay('I can not change your vocation.', cid)
        end
    elseif (msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        doPlayerSetVocation(cid, tab.voc)
        setPlayerStorageValue(cid, tab.oldstor[1], -1)
        setPlayerStorageValue(cid, tab.newstor[1], tab.newstor[2])
        doSendMagicEffect(getThingPos(cid), CONST_ME_STUN)
        addEvent(function()
            if isPlayer(cid) then
                changeVoc(cid)
            end
        end, tab.dctime * 1000)
        talkState[talkUser] = 0
        npcHandler:releaseFocus(cid)
        selfSay('Okay, now you will pass out and I will send you to the temple of your town in '..tab.dctime..' seconds.', cid)
    elseif (msgcontains(msg, 'no') and talkState[talkUser] == 1) then
        talkState[talkUser] = 0
        npcHandler:releaseFocus(cid)
        selfSay('Sure, goodbye!', cid)
    end
    
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Editado por Suicide (veja o histórico de edições)

The corrupt fear us.

The honest support us.

The heroic join us.

  • Respostas 12
  • Visualizações 760
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

  • Bom, nesse caso nem precisaria usar storages.. local tab = { voc = {5}, -- newVocationID dctime = 5, -- segundos para desconectar o player stats = {1, 150, 5} -- {newLevel, newHealth, newMana} nov

Postado
  • Autor

agora ele fala 'i can not change your vocation' por mais que eu tenha a storage ele não muda e aparece a mensagem.

 

Será que não é melhor tirar a storage e eu colocar em alguma porta ou piso? porque o objetivo dela seria que o player precise ter completado uma missão para conseguir trocar a vocação.

Postado

agora ele fala 'i can not change your vocation' por mais que eu tenha a storage ele não muda e aparece a mensagem.

 

Será que não é melhor tirar a storage e eu colocar em alguma porta ou piso? porque o objetivo dela seria que o player precise ter completado uma missão para conseguir trocar a vocação.

Bem mais fácil, aí poupa de colocar pro npc atender só se com o storage.

e assim o player vai ter acesso ao npc só se tiver o storage, ajuda bastante o suicide, na minha opinião...

Se quiser sua dúvida tirada, mande PM com os links, e não com a dúvida (outros podem ter a mesma dúvida, e o fórum serve para ser usado).

 

Tópicos:


 

yNlhRVC.png

 

55px-Judo_yellow_belt.svg.png

Postado

agora ele fala 'i can not change your vocation' por mais que eu tenha a storage ele não muda e aparece a mensagem.

Cara, você fez merda.

Eu testei esse NPC e todas as funções estão executando perfeitamente.

Na tabela, coloque um valor no parâmetro da storage necessária como sendo maior ou diferente de -1. Pois esse será o novo valor aplicado da storage, ao player, assim que ele aceitar a proposta do NPC.

Editado por Suicide (veja o histórico de edições)

The corrupt fear us.

The honest support us.

The heroic join us.

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