Ir para conteúdo

Baú com tempo (Recompensa aleatória)


Tingasgo

Posts Recomendados

Testado em TFS 0.3.6l 8.54

 

Estou apenas trazendo para o fórum pois não encontrei ^^ caso tenha eu removo... explicando o sistema seria um baú que a cada determinado tempo ele pode ser aberto novamente mas sempre irá vir algum item diferente (configurável)...

 

Vamos ao script...

 

Primeiro adicione isso em

 

actions.xml

 

<action uniqueid="4005" event="script" value="quests/timechest.lua"/>

 

Dentro da pasta scripts crie um arquivo chamado "timechest.lua" e adicione isso dentro

 

 

 


-- Time Chest by Limos
local config = {
    exhausttime = 7200, -- time in seconds
    exhauststorage = 2301,
    level = 50 -- minimum level to open the chest
}
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
 
local rewarditems = {
    {id = 2152, count = math.random(1, 50)},
    {id = 2498, count = 1},
    {id = 2492, count = 1},
    {id = 2488, count = 1}
}
 
    if(getPlayerLevel(cid) < config.level) then
        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
        doPlayerSendCancel(cid, "You need to be level "..config.level.." to open the chest.")
        return true
    end
    if(exhaustion.check(cid, config.exhauststorage)) then
        local time = exhaustion.get(cid, config.exhauststorage)
        local hours, minutes, seconds = math.floor (time / 3600), math.floor ((time - ((math.floor (time / 3600)) * 3600))/ 60), time - ((math.floor (time/60)) * 60)
        if time >= 3600 then
            text = hours.." "..(hours > 1 and "hours" or "hour")..", "..minutes.." "..(minutes > 1 and "minutes" or "minute").." and "..seconds.." "..(seconds > 1 and "seconds" or "second")
        elseif time >= 120 then
            text = minutes.." "..(minutes > 1 and "minutes" or "minute").." and "..seconds.." "..(seconds > 1 and "seconds" or "second")
        else
            text = seconds.." "..(seconds > 1 and "seconds" or "second")
        end
        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "It is empty. You need to wait "..text.." before you can get a reward again.")
        return true
    end
    local i = math.random(1, #rewarditems)
    local info = getItemInfo(rewarditems.id)
    if(rewarditems.count > 1) then  
        text = rewarditems.count .. " " .. info.plural
    else
                text = info.article .. " " .. info.name
    end
    local item = doCreateItemEx(rewarditems.id, rewarditems.count)
    if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
        text = "You have found a reward. It is to heavy or you have not enough space."
    else
        text = "You have found " .. text .. "."
        exhaustion.set(cid, config.exhauststorage, config.exhausttime)
    end
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
    return true
end

 

 

 

Versão com chance:

 

 

 

 


-- Time Chest by Limos
local config = {
    exhausttime = 7200, -- time in seconds
    exhauststorage = 2301,
    level = 50 -- minimum level to open the chest
}
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
 
local rewarditems = {
    {id = 2492, chance = 5, count = 1}, -- start with the lowest chances
    {id = 2498, chance = 10, count = 1},
    {id = 2488, chance = 15, count = 1},
    {id = 2152, chance = 70, count = math.random(1, 50)}
}
 
    if(getPlayerLevel(cid) < config.level) then
        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
        doPlayerSendCancel(cid, "You need to be level "..config.level.." to open the chest.")
        return true
    end
 
    if(exhaustion.check(cid, config.exhauststorage)) then
        local time = exhaustion.get(cid, config.exhauststorage)
        local hours, minutes, seconds = math.floor (time / 3600), math.floor ((time - ((math.floor (time / 3600)) * 3600))/ 60), time - ((math.floor (time/60)) * 60)
        if time >= 3600 then
            text = hours.." "..(hours > 1 and "hours" or "hour")..", "..minutes.." "..(minutes > 1 and "minutes" or "minute").." and "..seconds.." "..(seconds > 1 and "seconds" or "second")
        elseif time >= 120 then
            text = minutes.." "..(minutes > 1 and "minutes" or "minute").." and "..seconds.." "..(seconds > 1 and "seconds" or "second")
        else
            text = seconds.." "..(seconds > 1 and "seconds" or "second")
        end
        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "It is empty. You need to wait "..text.." before you can get a reward again.")
        return true
    end
 
    local chance = math.random(1,100)
    for i = 1, #rewarditems, 1 do
        if(chance < rewarditems.chance) then
            local info = getItemInfo(rewarditems.id)
            if(rewarditems.count > 1) then  
                text = rewarditems.count .. " " .. info.plural
            else
                        text = info.article .. " " .. info.name
            end
 
            local item = doCreateItemEx(rewarditems.id, rewarditems.count)
            if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
                doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                text = "You have found a reward. It is to heavy or you have not enough space."
            else
                text = "You have found " .. text .. "."
                exhaustion.set(cid, config.exhauststorage, config.exhausttime)
            end
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
            return true
        else
            chance = chance - rewarditems.chance
        end
    end
end

 

 

 

Versão com level e chance:

 

 

 

 


-- Time Chest by Limos
local config = {
    exhausttime = 7200, -- time in seconds
    exhauststorage = 2301,
    level = 25 -- minimum level to open the chest
}
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
 
local rewarditems = {
    [25] = {
        tilllevel = 50,
        {id = 3982, chance = 5, count = 1}, -- start with the lowest chances
        {id = 2476, chance = 10, count = 1},
        {id = 2479, chance = 15, count = 1},
        {id = 2148, chance = 70, count = math.random(1, 50)}
    },
    [50] = {
        tilllevel = 100,
        {id = 7730, chance = 5, count = 1},
        {id = 2466, chance = 10, count = 1},
        {id = 2497, chance = 15, count = 1},
        {id = 2152, chance = 70, count = math.random(1, 20)}
    },
    [100] = {
        tilllevel = 200,
        {id = 2492, chance = 5, count = 1},
        {id = 2498, chance = 10, count = 1},
        {id = 2195, chance = 15, count = 1},
        {id = 2152, chance = 70, count = math.random(20, 50)}
    },
    [200] = {
        tilllevel = 10000,
        {id = 2472, chance = 5, count = 1},
        {id = 2470, chance = 10, count = 1},
        {id = 2157, chance = 15, count = 1},
        {id = 2160, chance = 70, count = math.random(1, 5)}
    }
}
 
    if(getPlayerLevel(cid) < config.level) then
        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
        doPlayerSendCancel(cid, "You need to be level "..config.level.." to open the chest.")
        return true
    end
 
    if(exhaustion.check(cid, config.exhauststorage)) then
        local time = exhaustion.get(cid, config.exhauststorage)
        local hours, minutes, seconds = math.floor (time / 3600), math.floor ((time - ((math.floor (time / 3600)) * 3600))/ 60), time - ((math.floor (time/60)) * 60)
        if time >= 3600 then
            text = hours.." "..(hours == 1 and "hour" or "hours")..", "..minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
        elseif time >= 120 then
            text = minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
        else
            text = seconds.." "..(seconds == 1 and "second" or "seconds")
        end
        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "It is empty. You need to wait "..text.." before you can get a reward again.")
        return true
    end
 
    local chance = math.random(1,100)
    for v, x in pairs(rewarditems) do
        if(getPlayerLevel(cid) >= v and getPlayerLevel(cid) < x.tilllevel) then
            level = v
        end
    end
 
    for i = 1, #rewarditems[level], 1 do
        if(chance < rewarditems[level].chance) then
            local info = getItemInfo(rewarditems[level].id)
            if(rewarditems[level].count > 1) then   
                text = rewarditems[level].count .. " " .. info.plural
            else
                        text = info.article .. " " .. info.name
            end
 
            local item = doCreateItemEx(rewarditems[level].id, rewarditems[level].count)
            if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
                doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                text = "You have found a reward. It is to heavy or you have not enough space."
            else
                text = "You have found " .. text .. "."
                exhaustion.set(cid, config.exhauststorage, config.exhausttime)
            end
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
            return true
        else
            chance = chance - rewarditems[level].chance
        end
    end
end

 

 

 

Creio que seja facíl de configurar é só da uma lida ali no começo do script estou sem tempo de ficar explicando muito tempo só queria trazer pra k esse conteúdo ^^

 

Créditos: Limos "Otland"

 
 

 

Editado por Tingasgo
Link para o comentário
Compartilhar em outros sites

  • 2 weeks later...

Ola amigo, estou tentando usar o com level e chance mas da este erro:

 

[17/08/2017 19:12:46] [Error - Action Interface] [17/08/2017 19:12:46] data/actions/scripts/timechest.lua:onUse[17/08/2017 19:12:46] Description: [17/08/2017 19:12:46] data/actions/scripts/timechest.lua:70: attempt to compare number with nil[17/08/2017 19:12:46] stack traceback:[17/08/2017 19:12:46]     data/actions/scripts/timechest.lua:70: in function <data/actions/scripts/timechest.lua:8>

Linha numero 70:

 

if(chance < rewarditems[level].chance) then

 

Tem como me ajudar?

Link para o comentário
Compartilhar em outros sites

56 minutos atrás, PxN disse:

Ola amigo, estou tentando usar o com level e chance mas da este erro:

 

[17/08/2017 19:12:46] [Error - Action Interface] [17/08/2017 19:12:46] data/actions/scripts/timechest.lua:onUse[17/08/2017 19:12:46] Description: [17/08/2017 19:12:46] data/actions/scripts/timechest.lua:70: attempt to compare number with nil[17/08/2017 19:12:46] stack traceback:[17/08/2017 19:12:46]     data/actions/scripts/timechest.lua:70: in function <data/actions/scripts/timechest.lua:8>

Linha numero 70:

 

if(chance < rewarditems[level].chance) then

 

Tem como me ajudar?

Envia o script inteiro caso tenha feito alguma alteração

Link para o comentário
Compartilhar em outros sites

5 minutos atrás, PxN disse:

Ok. Desculpe o encomodo. Obrigado por tudo.

Retired.

Desculpa, tenta me marcar quando perguntar algo pra mim eu nunca entro aqui e se você não me marcar não vou ver... O meu ta funcionando... eu testei que base você usa?

Link para o comentário
Compartilhar em outros sites

Dei uma revisada no script, ta ai

-- Time Chest by Limoslocal config = {    exhausttime = 7200, -- time in seconds    exhauststorage = 2301,    level = 25 -- minimum level to open the chest} function onUse(cid, item, fromPosition, itemEx, toPosition) local rewarditems = {    [25] = {        tilllevel = 50,        {id = 3982, chance = 5, count = 1}, -- start with the lowest chances        {id = 2476, chance = 10, count = 1},        {id = 2479, chance = 15, count = 1},        {id = 2148, chance = 70, count = math.random(1, 50)}    },    [50] = {        tilllevel = 100,        {id = 7730, chance = 5, count = 1},        {id = 2466, chance = 10, count = 1},        {id = 2497, chance = 15, count = 1},        {id = 2152, chance = 70, count = math.random(1, 20)}    },    [100] = {        tilllevel = 200,        {id = 2492, chance = 5, count = 1},        {id = 2498, chance = 10, count = 1},        {id = 2195, chance = 15, count = 1},        {id = 2152, chance = 70, count = math.random(20, 50)}    },    [200] = {        tilllevel = 500,        {id = 2472, chance = 5, count = 1},        {id = 2470, chance = 10, count = 1},        {id = 2157, chance = 15, count = 1},        {id = 2160, chance = 70, count = math.random(1, 5)}    }}     if(getPlayerLevel(cid) < config.level) then        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)        doPlayerSendCancel(cid, "You need to be level "..config.level.." to open the chest.")        return true    end    if getPlayerStorageValue(cid, config.exhauststorage) and getPlayerStorageValue(cid, config.exhauststorage) - os.time(t) > 0 then        local time = getPlayerStorageValue(cid, config.exhauststorage) - os.time(t)        local hours, minutes, seconds = math.floor (time / 3600), math.floor ((time - ((math.floor (time / 3600)) * 3600))/ 60), time - ((math.floor (time/60)) * 60)        if time >= 3600 then            text = hours.." "..(hours == 1 and "hour" or "hours")..", "..minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")        elseif time >= 120 then            text = minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")        else            text = seconds.." "..(seconds == 1 and "second" or "seconds")        end        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "It is empty. You need to wait "..text.." before you can get a reward again.")        return true    end     local chance = math.random(1,100)    for v, x in pairs(rewarditems) do        if(getPlayerLevel(cid) >= v and getPlayerLevel(cid) < x.tilllevel) then            level = v			till = x.tilllevel        end    end    for a, b in pairs(rewarditems[level]) do	if b == till then return true end        if(chance < b.chance) then            local info = getItemInfo(b.id)            if(b.count > 1) then   				text = b.count .. " " .. info.plural            else				text = info.article .. " " .. info.name            end             local item = doCreateItemEx(b.id, b.count)            if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then                doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)                text = "You have found a reward. It is to heavy or you have not enough space."            else                text = "You have found " .. text .. "."                exhaustion.set(cid, config.exhauststorage, config.exhausttime)            end            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)            return true        else            chance = chance - b.chance        end    endend

 

Link para o comentário
Compartilhar em outros sites

17 horas atrás, Taiger disse:

Ué, deletaram as criticas pq? E até a advertencia do membro da equipe? Não estou entendendo mais nada.

@Tingasgo É PDA amigo, ele me pediu ajuda mas não sou programador.

 

Deletei porquê eu quis, e eu já tinha avisado que não queria mais nada sobre o ocorrido.

 

14 horas atrás, Drakopoulos disse:

Dei uma revisada no script, ta ai

-- Time Chest by Limoslocal config = {    exhausttime = 7200, -- time in seconds    exhauststorage = 2301,    level = 25 -- minimum level to open the chest} function onUse(cid, item, fromPosition, itemEx, toPosition) local rewarditems = {    [25] = {        tilllevel = 50,        {id = 3982, chance = 5, count = 1}, -- start with the lowest chances        {id = 2476, chance = 10, count = 1},        {id = 2479, chance = 15, count = 1},        {id = 2148, chance = 70, count = math.random(1, 50)}    },    [50] = {        tilllevel = 100,        {id = 7730, chance = 5, count = 1},        {id = 2466, chance = 10, count = 1},        {id = 2497, chance = 15, count = 1},        {id = 2152, chance = 70, count = math.random(1, 20)}    },    [100] = {        tilllevel = 200,        {id = 2492, chance = 5, count = 1},        {id = 2498, chance = 10, count = 1},        {id = 2195, chance = 15, count = 1},        {id = 2152, chance = 70, count = math.random(20, 50)}    },    [200] = {        tilllevel = 500,        {id = 2472, chance = 5, count = 1},        {id = 2470, chance = 10, count = 1},        {id = 2157, chance = 15, count = 1},        {id = 2160, chance = 70, count = math.random(1, 5)}    }}     if(getPlayerLevel(cid) < config.level) then        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)        doPlayerSendCancel(cid, "You need to be level "..config.level.." to open the chest.")        return true    end    if getPlayerStorageValue(cid, config.exhauststorage) and getPlayerStorageValue(cid, config.exhauststorage) - os.time(t) > 0 then        local time = getPlayerStorageValue(cid, config.exhauststorage) - os.time(t)        local hours, minutes, seconds = math.floor (time / 3600), math.floor ((time - ((math.floor (time / 3600)) * 3600))/ 60), time - ((math.floor (time/60)) * 60)        if time >= 3600 then            text = hours.." "..(hours == 1 and "hour" or "hours")..", "..minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")        elseif time >= 120 then            text = minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")        else            text = seconds.." "..(seconds == 1 and "second" or "seconds")        end        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "It is empty. You need to wait "..text.." before you can get a reward again.")        return true    end     local chance = math.random(1,100)    for v, x in pairs(rewarditems) do        if(getPlayerLevel(cid) >= v and getPlayerLevel(cid) < x.tilllevel) then            level = v			till = x.tilllevel        end    end    for a, b in pairs(rewarditems[level]) do	if b == till then return true end        if(chance < b.chance) then            local info = getItemInfo(b.id)            if(b.count > 1) then   				text = b.count .. " " .. info.plural            else				text = info.article .. " " .. info.name            end             local item = doCreateItemEx(b.id, b.count)            if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then                doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)                text = "You have found a reward. It is to heavy or you have not enough space."            else                text = "You have found " .. text .. "."                exhaustion.set(cid, config.exhauststorage, config.exhausttime)            end            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)            return true        else            chance = chance - b.chance        end    endend

 

Grato por tentar ajudar :)

Link para o comentário
Compartilhar em outros sites

  • 1 month later...

corrigindo uma parte do tempo, e uma pequena otimização, que ele mostraria os segundos errados se estivesse entre 60 e 119 segundos faltando, que cairia no 3 caso, o else, mas os segundos variam só de 0 a 59
use %(modulo) para obter o resto inteiro da divisão, exemplo de como funciona esse operador : 3%3 = 0, 4%3  = 1, 5%3 = 2, 6%3 = 0
 

Spoiler



	if(exhaustion.check(cid, config.exhauststorage)) then
		local time = exhaustion.get(cid, config.exhauststorage)
		local hours, minutes, seconds = math.floor(time / 3600), math.floor(time / 60) % 60, time % 60
		if time >= 3600 then
			text = hours.." "..(hours == 1 and "hour" or "hours")..", "..minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
		elseif time >= 120 then
			text = minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
		else
			seconds = time % 120
			text = seconds.." "..(seconds == 1 and "second" or "seconds")
		end
		doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
		doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "It is empty. You need to wait "..text.." before you can get a reward again.")
		return true
	end


 

 

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...