Postado Abril 3, 2020 5 anos Salve galera do tibia king. Precisava de ajuda com a minha script de donater, ela funciona assim quando o player digita !donaterdays mostra o tempo de donater que ele tem, porem ele ta pegando o total de dias e somando com o total de horas, ficando assim: Voce tem 19 dias, 473 horas, 2 minutos e 27 segundos de DNT no seu character. Queria que as horas aparecessem em formato de 24hrs, ficando assim: Voce tem 19 dias, 23 horas, 2 minutos e 27 segundos de DNT no seu character. Segue o script: 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 return false end function onSay(cid, words, param) if(words == "!donater") then if doPlayerRemoveItem(cid, 9663, 1) == TRUE then local days = 30 local daysvalue = days * 24 * 60 * 60 local storageplayer = getPlayerStorageValue(cid, 457382) local timenow = os.time() if getPlayerStorageValue(cid, 457382) - os.time() <= 0 then time = timenow + daysvalue else time = storageplayer + daysvalue end doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Foram adicionados ".. days .." dias de DNT no seu character.") setPlayerStorageValue(cid, 457382, time) local quantity = math.floor((getPlayerStorageValue(cid, 457382) - timenow)/(24 * 60 * 60)) doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Voce tem ".. quantity .." dias de DNT restantes.") else doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Voce precisa do item Donater Acess para usar este comando.") end elseif(words == "!donaterdays") then local timenow = os.time() local quantity = math.floor((getPlayerStorageValue(cid, 457382) - timenow)/(24 * 60 * 60)) doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Voce tem ".. (quantity < 0 and 0 or quantity) .." dias, "..convertTime(getPlayerStorageValue(cid, 457382) - timenow).." de DNT no seu character.") elseif(words == "/adddonater") then local t = string.explode(param, ",") if not t[2] then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid param specified.") end local player = getPlayerByName(t[1]) local name = getCreatureName(player) local days = t[2] local pid = getPlayerByNameWildcard(t[1]) if(not pid or (isPlayerGhost(pid) and getPlayerGhostAccess(pid) > getPlayerGhostAccess(cid))) then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player with this name doesn\'t exist or is offline.") return TRUE end local daysvalue = days * 24 * 60 * 60 local storageplayer = getPlayerStorageValue(player, 457382) local timenow = os.time() local time = storageplayer <= 0 and (timenow + daysvalue) or (storageplayer + daysvalue) doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, "Foram adicionados "..days.." dias de DNT no seu character.") setPlayerStorageValue(player, 457382, time) local quantity = math.floor((getPlayerStorageValue(player, 457382) - timenow)/(24 * 60 * 60)) doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, "Voce tem "..quantity.." dias de DNT restantes.") end return true end
Postado Abril 4, 2020 5 anos Solução function timeString(timeDiff) local dateFormat = { {"day", timeDiff / 60 / 60 / 24}, {"hour", timeDiff / 60 / 60 % 24}, {"minute", timeDiff / 60 % 60}, {"second", 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 ' and ') .. 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(" and ") ret = ret:sub(b+1) end return ret end function onSay(cid, words, param) if(words == "!donater") then if doPlayerRemoveItem(cid, 9663, 1) == TRUE then local days = 30 local daysvalue = days * 24 * 60 * 60 local storageplayer = getPlayerStorageValue(cid, 457382) local timenow = os.time() if getPlayerStorageValue(cid, 457382) - os.time() <= 0 then time = timenow + daysvalue else time = storageplayer + daysvalue end doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Foram adicionados ".. days .." dias de DNT no seu character.") setPlayerStorageValue(cid, 457382, time) local quantity = math.floor((getPlayerStorageValue(cid, 457382) - timenow)/(24 * 60 * 60)) doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Voce tem ".. quantity .." dias de DNT restantes.") else doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Voce precisa do item Donater Acess para usar este comando.") end elseif(words == "!donaterdays") then local time = timeString(-(os.time() - getPlayerStorageValue(cid, 457382))) local timenow = os.time() local quantity = math.floor((getPlayerStorageValue(cid, 457382) - timenow)/(24 * 60 * 60)) doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Voce tem ".. time .." de DNT no seu character.") elseif(words == "/adddonater") then local t = string.explode(param, ",") if not t[2] then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid param specified.") end local player = getPlayerByName(t[1]) local name = getCreatureName(player) local days = t[2] local pid = getPlayerByNameWildcard(t[1]) if(not pid or (isPlayerGhost(pid) and getPlayerGhostAccess(pid) > getPlayerGhostAccess(cid))) then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player with this name doesn\'t exist or is offline.") return TRUE end local daysvalue = days * 24 * 60 * 60 local storageplayer = getPlayerStorageValue(player, 457382) local timenow = os.time() local time = storageplayer <= 0 and (timenow + daysvalue) or (storageplayer + daysvalue) doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, "Foram adicionados "..days.." dias de DNT no seu character.") setPlayerStorageValue(player, 457382, time) local quantity = math.floor((getPlayerStorageValue(player, 457382) - timenow)/(24 * 60 * 60)) doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, "Voce tem "..quantity.." dias de DNT restantes.") end return true end testa ai, e me fala
Postado Abril 4, 2020 5 anos Autor @poko360 funcionou perfeitamente obrigado. rep + edit - Só ta com um problema, a dnt acaba e quando o player digita !donaterdays fala que ele ainda tem algumas horas de donater. edi2- consegui resolver, obrigado não tinha a função de verificar se o player era donater quando digitava o comando kkk' Editado Abril 4, 2020 5 anos por DouGlaS Mapper (veja o histórico de edições)
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.