Ir para conteúdo

Featured Replies

  • Respostas 17
  • Visualizações 1.1k
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

  • 1º pedido: local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} function onCreatureAppear(cid) npc

  • local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} function onCreatureAppear(cid) npcHandler:onCre

  • Tente assim o 2° Pedido. local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} function onCreatureA

Postado

Tente assim o 2° Pedido.

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 price = xxx                        --Preço para trocar o nome.
    local characters = {}                    --Configure nesta tabela os caracteres (ou palavras) proibidos.
    local delay = 5                          --Tempo para o jogador ser desconectado após trocar o nome.
    if msgcontains(msg:lower(), "name") or msgcontains(msg:lower(), "change") then
        selfSay("Do you wanna change your name? It will cost {"..price.." gold}.", cid)
        talkState[talkUser] = 1
        return true
    elseif msgcontains(msg:lower(), "yes") and talkState[talkUser] == 1 then
        if getPlayerMoney(cid) >= price then
            selfSay("OK, tell me your new name.", cid)
            talkState[talkUser] = 2
            return true
        else
            selfSay("You do not have enough money.", cid)
            talkState[talkUser] = 0
            return true
        end
    elseif talkState[talkUser] == 2 then
        local query = db.getResult("SELECT name FROM players")
        if query:getID() == -1 then
            selfSay("Database inexistent.", cid)
            talkState[talkUser] = 0
            return true
        end
        repeat
            local name = query:getDataString("name")
            if msg == name then
                selfSay("This name is already in use.", cid)
                talkState[talkUser] = 0
                return true
            end
        until not query:next()
        query:free()
        for i = 1, #characters do
            if msg:find(characters[i]) then
                selfSay("Sorry, this name isn't available.", cid)
                talkState[talkUser] = 0
                return true
            end
        end
        db.executeQuery('UPDATE `'..sqlDatabase..'`.`players` SET `name` = "'..msg..'" WHERE `players`.`id` ='..getPlayerGUID(cid)' AND CONVERT( `players`.`name` USING utf8 ) = "'..old..'" LIMIT 1 ;')
        doPlayerRemoveMoney(cid, price)
        selfSay("You changed your name to {"..msg.."}. In "..delay.." second"..(delay > 1 and "s" or "")..", you will be disconected.", cid)
        addEvent(function()
            if isPlayer(cid) then
                doRemoveCreature(cid)
            end
        end, delay * 1000)
        talkState[talkUser] = 0
        return true
    elseif msgcontains(msg:lower(), "no") and talkState[talkUser] == 1 then
        selfSay("Ok, bye.", cid)
        talkState[talkUser] = 0
        return true
    end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())       

Te ajudei?
Se você achar que eu mereço, me dê uma "rep+" e selecione meu post como "melhor resposta"

 

Skype: JoadsonAion

Postado

Aqui está, testado e funcioando perfeitamente.

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 price = 250                        --Preço para trocar o nome.
    local characters = {}                    --Configure nesta tabela os caracteres (ou palavras) proibidos.
    local delay = 5                          --Tempo para o jogador ser desconectado após trocar o nome.
    if msgcontains(msg:lower(), "name") or msgcontains(msg:lower(), "change") then
        selfSay("Do you wanna change your name? It will cost {"..price.." gold}.", cid)
        talkState[talkUser] = 1
        return true
    elseif msgcontains(msg:lower(), "yes") and talkState[talkUser] == 1 then
        if getPlayerMoney(cid) >= price then
            selfSay("OK, tell me your new name.", cid)
            talkState[talkUser] = 2
            return true
        else
            selfSay("You do not have enough money.", cid)
            talkState[talkUser] = 0
            return true
        end
    elseif talkState[talkUser] == 2 then
        local query = db.getResult("SELECT name FROM players")
        if query:getID() == -1 then
            selfSay("Database inexistent.", cid)
            talkState[talkUser] = 0
            return true
        end
        repeat
            local name = query:getDataString("name")
            if msg == name then
                selfSay("This name is already in use.", cid)
                talkState[talkUser] = 0
                return true
            end
        until not query:next()
        query:free()
        for i = 1, #characters do
            if msg:find(characters[i]) then
                selfSay("Sorry, this name isn't available.", cid)
                talkState[talkUser] = 0
                return true
            end
        end
        local guid = getPlayerGUID(cid)
        db.executeQuery("UPDATE `players` SET `name` = " .. db.escapeString(msg) .. " WHERE `id` = " .. guid .. " LIMIT 1;")
        doPlayerRemoveMoney(cid, price)
        selfSay("You changed your name to {"..msg.."}. In "..delay.." second"..(delay > 1 and "s" or "")..", you will be disconected.", cid)
        addEvent(function()
            if isPlayer(cid) then
                doRemoveCreature(cid)
            end
        end, delay * 1000)
        talkState[talkUser] = 0
        return true
    elseif msgcontains(msg:lower(), "no") and talkState[talkUser] == 1 then
        selfSay("Ok, bye.", cid)
        talkState[talkUser] = 0
        return true
    end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())  

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

Te ajudei?
Se você achar que eu mereço, me dê uma "rep+" e selecione meu post como "melhor resposta"

 

Skype: JoadsonAion

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.6k

Informação Importante

Confirmação de Termo