Ir para conteúdo

(Resolvido)(PEDIDO) Adicionar tempo para usar o item novamente

Featured Replies

Postado

Preciso adicionar para que o jogador só possa usar o item novamente após X HORAS ( 24HORAS POR EXEMPLO)

 

Segue script atual:

 

local config = {
	time = 4,
	storage = 123456,
	}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
	if player:getStorageValue(config.storage) >= os.time() then
		player:sendTextMessage(MESSAGE_INFO_DESCR, "You still have extra experience time left.")
		return true
	end

	player:setStorageValue(config.storage, os.time() + config.time * 3600)
	player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You have activated %d hour%s of 10x experience.", config.time, config.time ~= 1 and "s" or ""))
	item:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
	item:remove(1)
	return true
end

Agradeço des de ja <3

Resolvido por Leohige

Ir para solução
  • Respostas 9
  • Visualizações 1.4k
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

Posted Images

Postado

@Andreeyyy

 

time = 24

 aqui??

Postado
  • Solução

Teste ai, o tempo é configurável

 

Demonstração

 

Spoiler

xp.thumb.gif.131eae7c6daac03477fa82ecc472bc2c.gif

 

Script

 

Spoiler

local config = {
    time = 4,          -- Tempo de double xp (em horas)
    cd = 24,           -- Tempo para usar o item novamente (em horas)
    storage = 123456, 
    cdstorage = 123457
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(config.cdstorage) >= os.time() then
        player:sendTextMessage(MESSAGE_INFO_DESCR, remainTime(player:getStorageValue(config.cdstorage) - os.time()))
        return true
    end
    
    if player:getStorageValue(config.storage) >= os.time() then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You still have extra experience time left.")
        return true
    end
    
    player:setStorageValue(config.cdstorage, os.time() + config.cd * 3600)
    player:setStorageValue(config.storage, os.time() + config.time * 3600)
    player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You have activated %d hour%s of 10x experience.", config.time, config.time ~= 1 and "s" or ""))
    item:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    item:remove(1)
    return true
end

function remainTime(seconds)
    hrs = math.floor(seconds / 3600)
    mins = math.floor((seconds - (hrs * 3600)) / 60)
    secs = math.floor(seconds - (hrs * 3600) - mins * 60)
    return string.format("Sorry, you can only use this item again in %d hour(s), %d minute(s) and %d second(s).", hrs, mins, secs)
end

 

 

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

  • 1 month later...

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