GU
pedido

Item aleatorio

Por GuuhMaster, 26 de jan. de 2014 em Scripts

item aleatorio
resolvido
script
4
1k
GuuhMasterG
26 de janeiro de 2014 às 18:01

Eu gostaria de um script que ao falar no NPC lhe daria items aleatorio, exemplo.

 

Caso você tenha;

1 Golden trophy (7369), trocaria por 3 items aleatorios. (xxx, xxx, xxx)

1 Silver trophy (7370), trocaria por 2 items aleatorios. (xxx, xxx)

1 Bronze trophy (7371), trocaria por 1 item aleatorio. (xxx)

 

Os items que viriam seriam;

2158

2156

2154

 

Caso alguem ja tenha visto um script fazendo tal função, link pf, pois nao achei.

Editado Janeiro 26 por GuuhMaster

zipter98Z
26 de janeiro de 2014 às 19:07

Como você não especificou a quantidade dos items aleatórios, coloquei 1 mesmo.

Bem, suponho que você saiba fazer o XML. Qualquer erro, só avisar.

 

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 trophy = {
    ["golden"] = {3, 7369},    --{Quantidade de items aleatórios, ID do troféu}, 
    ["silver"] = {2, 7370},
    ["bronze"] = {1, 7371}, 
}
local items = {2158, 2156, 2154}
 
    if msgcontains(msg, "trophy") or msgcontains(msg, "trofeu") then
        selfSay("Oh, vejo que você quer trocar algum troféu por recompensas. Qual troféu seria este: {golden}, {silver} ou {bronze}?", cid)
        talkState[talkUser] = 1
        return true
    elseif talkState[talkUser] == 1 then
        if trophy[msg:lower()] then
            local trofeu = trophy[msg:lower()]
            local id = trofeu[2]
            if getPlayerItemCount(cid, id) > 0 then
                for i = 1, trofeu[1] do
                    doPlayerAddItem(cid, items[math.random(#items)], 1)
                end
                doPlayerRemoveItem(cid, id, 1)
                selfSay("Obrigado, aqui estão seus items!", cid)
                talkState[talkUser] = 0
                return true
            else
                selfSay("Desculpe, mas você não tem este troféu.", cid)
                talkState[talkUser] = 0
                return true
            end
        else
            selfSay("Desculpe, este troféu não existe.", cid)
            talkState[talkUser] = 0
            return true
        end
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Editado Janeiro 26 por zipter98

GuuhMasterG
26 de janeiro de 2014 às 21:42

Funcionou! Podem mover.

zipter98Z
26 de janeiro de 2014 às 21:51

Tópico movido para a seção de dúvidas e pedidos resolvidos.