Ir para conteúdo

Featured Replies

Postado

galera, preciso de um Npc que summone um monstro em tal posição x,y,z em troca de uma pequena quantia de items "ID". e para ele summonar outro novamente precisa esperar algumas horas. 

 

para tfs 0.4 8.60

 

quem poder ajuda ficarei mt grato. e darei aquele gostozu REP+

Resolvido por Dwarfer

Ir para solução
Postado
  • Solução

Em npcs/scripts crie um arquivo.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

function mathtime(table) -- by dwarfer
local unit = {"sec", "min", "hour", "day"}
for i, v in pairs(unit) do
if v == table[2] then
return table[1]*(60^(v == unit[4] and 2 or i-1))*(v == unit[4] and 24 or 1)
end
end
return error("Bad declaration in mathtime function.")
end

local t = {
monster = {"Dwarf", {x=1,y=1,z=1}}, -- monstro, posição
item = {2160, 1}, --id do item, quantidade
summon_again = {2, "hour"} -- tempo para sumonar novamente
}

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)
            npcHandler:say("Hi, ".. getPlayerName(cid).."! I have a {challenge} for you.", cid)
            npcTopic[cid] = 1
        else
            return false 
        end
    elseif msgcontains(msg, "challenge") and npcTopic[cid] == 1 then
        if getPlayerStorageValue(cid, 77853) <= os.time() then
            npcHandler:say("I need ".. t.item[2] .. " " .. getItemNameById(t.item[1])..". Do you have it?", cid)
            npcTopic[cid] = 2
        else
            npcHandler:say("You need to wait until "..os.date("%d %B %Y %X", getPlayerStorageValue(cid, 77853)).." to face the challenge again.", cid)
            npcTopic[cid] = 0
            npcHandler:releaseFocus(cid)
        end
    elseif msgcontains(msg, "yes") and npcTopic[cid] == 2 then
        if doPlayerRemoveItem(cid, t.item[1], t.item[2]) then
            setPlayerStorageValue(cid, 77853, mathtime(t.summon_again) + os.time())
            doSendMagicEffect(t.monster[2], CONST_ME_TELEPORT)
            local m = doCreateMonster(t.monster[1], t.monster[2])
            doCreatureSay(m, "MUAHAHAHA!", TALKTYPE_ORANGE_1)
            npcHandler:say("HahAHAh! Prove your strength!", cid)
            npcTopic[cid] = 0
        else
            npcHandler:say("Sorry but you don't have the item I need.", cid)
            npcTopic[cid] = 1
        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)

 

 

Um arquivo.xml como base:

<?xml version="1.0" encoding="UTF-8"?>
<npc name="Dwarfer" script="NOMEDOARQUIVO.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="66"/>
</npc>

 

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