Script Npc Recursos para un Reward

Alex

Miembro del equipo
Webdesigner
LV
58
 
Awards
38
Hola a todos,

Alguien me pregunto por mensaje un NPC en el cual por ejemplo le diéramos recursos de piratas, para obtener una, pirate bag.

Ustedes crear un NPC dentro de scripts/npc, copian y pegan cualquier otro, le cambian el nombre/looktype.
Luego entramos en la carpeta scripts y ahí copiamos y pegamos cualquier otro y lo renombramos por el mismo nombre del primer NPC.

Ahí le pegaremos el siguiente código,

Código:
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 pirate_items = {5462, 5918, 5927, 6095, 6096}

local function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if npcHandler.topic[cid] == 0 then
        if msgcontains(msg, 'backpack') then
            npcHandler:say('You want me to make {pirate}, {fur}, {minotaur} or {expedition} backpack for you?', cid)
        elseif msgcontains(msg, 'pirate') then
            npcHandler:say('Do you have all 4 pieces of pirate set and pirate bag?', cid)
            npcHandler.topic[cid] = 1
        end
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "yes") then
            for key, itemid in pairs(pirate_items) do
                if player:getItemCount(itemid) < 1 then
                    npcHandler:say('HEY! You don\'t have them!', cid)
                    npcHandler.topic[cid] = 0
                    return true
                end
            end
            for key, itemid in pairs(pirate_items) do
                player:removeItem(itemid, 1)
            end
            player:addItem(5926, 1)
            npcHandler:say('Here You go! I\'ll use your ingredients to make second backpack and sell it to Tom.', cid)
        else
            npcHandler:say("Okay then.", cid)
        end
        npcHandler.topic[cid] = 0
    end
    return true
end

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

En
Código:
local pirate_items = {5462, 5918, 5927, 6095, 6096}
Indicaremos los recursos, en este caso, 1 de cada.

Y el reward, estaría en esta línea:
Código:
player:addItem(5926, 1)
 

Sasketoon

Miembro
LV
12
 
Awards
12
Hola Alex. Por decir si quiero que el npc requiera 2 o más items iguales y aparte que le cobre x cantidad de dinero como podría ser?
 
Arriba