Ir para conteúdo
  • 0
Entre para seguir isso  
LeoTK

Scripting [Dúvida] Como utilizar essa function

Pergunta

LeoTK    2
LeoTK

Base: TFS 0.3.6, Versão: 8.54

Salve galera bom eu achei essa function por lib feita pelo vodkart

Spoiler

function convertTime(a)
  if(type(tonumber(a)) == "number" and a > 0) then
    if (a <= 3599) then
      local minute = math.floor(a/60)
      local second = a - (60 * minute)

      if(second == 0) then
        return ((minute)..((minute > 1) and " minutos" or " minuto"))
      else
        return ((minute ~= 0) and ((minute>1) and minute.." minutos e " or minute.." minuto e ").. ((second>1) and second.." segundos" or second.." segundo") or ((second>1) and second.." segundos" or second.. " segundo"))
      end
    else
      local hour = math.floor(a/3600)
      local minute = math.floor((a - (hour * 3600))/60)
      local second = (a - (3600 * hour) - (minute * 60))

      if (minute == 0 and second > 0) then
        return (hour..((hour > 1) and " horas e " or " hora e "))..(second..((second > 1) and " segundos" or " segundo"))
      elseif (second == 0 and minute > 0) then
        return (hour..((hour > 1) and " horas e " or " hora e "))..(minute..((minute > 1) and " minutos" or " minuto"))
      elseif (second == 0 and minute == 0) then
        return (hour..((hour > 1) and " horas" or " hora"))
      end
      return (hour..((hour > 1) and " horas, " or " hora, "))..(minute..((minute > 1) and " minutos e " or " minuto e "))..(second..((second > 1) and " segundos" or " segundo"))
    end
  end
end

 


 

E gostaria muito de usar neste script para aparecer a hora, minutos e os segundos que falta pra poder usar novamente

Spoiler

local config = {
    tempo = 120, -- Tempo em minutos
    effect = 592,
    remove_on_use = "yes",
      stamina_full = 42 * 60 -- aqui é o valor da stamina completa em MINUTOS
}

function onUse(cid, item, frompos, item2, topos)
local waittime = 43200
local storage = 65486

if exhaustion.check(cid, storage) then
doPlayerSendChannelMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Aguarde ".. exhaustion.get(cid, storage) .. " segundos para usar o refil de stamina novamente.", TALKTYPE_CHANNEL_O, CHANNEL_INFO)
return false
end
    -- se a stamina do jogador for maior ou igual ao valor de stamina_full
    if(getPlayerStamina(cid) >= config.stamina_full) then
        doPlayerSendCancel(cid, "Sua stamina ja esta cheia!")
    else
        doPlayerAddStamina(cid, config.tempo)
        doSendMagicEffect(getThingPos(cid), config.effect)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sua stamina foi regenerada em 2 horas.")
        if config.remove_on_use == "yes" then
            doRemoveItem(item.uid, 1)
			exhaustion.set(cid, storage, waittime)
        end
    end
    return true
end

 

 

Como podem ver eu tentei fazer um porém consegui deixar apenas em segundos se alguém puder fazer essa modificação pra mim ajudaria muito obrigado desde já

 

Script sem a verificação em segundos

Spoiler

local config = {
    tempo = 120, -- Tempo em minutos
    effect = 592,
    remove_on_use = "yes",
      stamina_full = 42 * 60 -- aqui é o valor da stamina completa em MINUTOS
}

function onUse(cid, item, frompos, item2, topos)
    if(getPlayerStamina(cid) >= config.stamina_full) then
        doPlayerSendCancel(cid, "Sua stamina ja esta cheia!")
    else
        doPlayerAddStamina(cid, config.tempo)
        doSendMagicEffect(getThingPos(cid), config.effect)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sua stamina foi regenerada em 2 horas.")
        if config.remove_on_use == "yes" then
            doRemoveItem(item.uid, 1)
        end
    end
    return true
end

 

 

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

1 resposta a esta questão

Recommended Posts

  • 0
Majesty    1755
Majesty
Spoiler

local config = {
	storage = 62163, -- Storage para após usar começar a contagem de tempo após o próximo uso
	tempo = 120, -- Tempo em minutos que vai curar a stamina 120 = 2 horas
	delay = 12, -- Tempo em horas que vai demorar para usar novamente 1 = 1 hora
	effect = 592, -- Efeito que vai aparecer ao usar o item para regenerar a stamina
	remove_on_use = true, -- Se o item vai sumir ao usar ou não sendo true = sim e false = nao
	stamina_full = 42 * 60 -- aqui é o valor da stamina completa em MINUTOS OBS: NÃO MEXER
}

function timeString(timeDiff)
	local dateFormat = {
		{"dia", timeDiff / 60 / 60 / 24},
		{"hora", timeDiff / 60 / 60 % 24},
		{"minuto", timeDiff / 60 % 60},
		{"segundo", timeDiff % 60}
	}
	local out = {}
	for k, t in ipairs(dateFormat) do
		local v = math.floor(t[2])
		if(v > 0) then
			table.insert(out, (k < #dateFormat and (#out > 0 and ', ' or '') or ' e ') .. v .. ' ' .. t[1] .. (v ~= 1 and 's' or ''))
		end
	end
	local ret = table.concat(out)
	if ret:len() < 16 and ret:find("second") then
		local a, b = ret:find(" e ")
		ret = ret:sub(b+1)
	end	
	return ret
end
function onUse(cid, item, frompos, item2, topos)
	if (getPlayerStorageValue(cid, config.storage) >= os.time()) then
		return doPlayerSendChannelMessage(cid, MESSAGE_STATUS_CONSOLE, "Voce precisa esperar " .. timeString(getPlayerStorageValue(cid, config.storage) - os.time()) ..", para regenerar a stamina novamente.", TALKTYPE_CHANNEL_O, CHANNEL_INFO)
	elseif getPlayerStamina(cid) >= config.stamina_full then
		return doPlayerSendCancel(cid, "Sua stamina ja esta cheia!")
	end
	doPlayerAddStamina(cid, config.tempo)
	doSendMagicEffect(getThingPos(cid), config.effect)
	setPlayerStorageValue(cid, config.storage, os.time() + config.delay * 60 * 60)
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sua stamina foi regenerada em 2 horas.") -- Mensagem quando a stamina for regenerada
	if config.remove_on_use then
		doRemoveItem(item.uid, 1)
	end
	return true
end

 

Créditos: Vodkart.

Compartilhar este post


Link para o post
Compartilhar em outros sites
Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×