Ir para conteúdo
  • Cadastre-se

(Resolvido)[Creaturescript] tempo pra avançar um level ----> "you advanced from level 227 to level 228 in 20 minutes and 40 seconds"


Ir para solução Resolvido por edaegonis,

Posts Recomendados

Diga em poucas palavras a base utilizada (Nome do servidor ou nome do website).

tfs 0.4

Base: 

bom dia, algum lindão poderia desbugar essa script que mostrasse o tempo pra upar um nivel?

EXEMPLO: "you advanced from level 227 to level 228 in 20 minutes and 40 seconds"

 

 

recentemente eu achei um script em outro forum mas aparece um bugzinho
126997375_Semttulo.thumb.png.16f3e58143075e60f75241bf2e8bff38.png

 

 

Segue abaixo o script:


050-Function.xml

Spoiler

 

  1. STORAGE_FOR_TIMESTAMP = 15854 -- Some storage that will save the times of player's level advancements
  2.    
  3. -- Description of function below:
  4. -- Returns inputted seconds as a formatted string in HH:MM:SS format.
  5. -- If the parameter "worded" is set to true, it returns a string like: "HH hours, MM minutes, and SS seconds" instead.
  6.  
  7. local function secondsToClock(seconds, worded) -- Returns inputted seconds as a formatted string
  8.   local seconds = tonumber(seconds)
  9.  
  10.   if seconds <= 0 then
  11.     if worded == true then return "0 seconds."; else return "00:00:00"; end
  12.   else
  13.     local hours = string.format("%02.f", math.floor(seconds/3600));
  14.     local mins = string.format("%02.f", math.floor(seconds/60 - (hours*60)));
  15.     local secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60));
  16.     if worded == true then
  17.         return ((seconds<3600 and "") or ((math.floor(seconds/3600) == 1 and "1 hour, ") or (math.floor(seconds/3600)) .. " hours, ")) .. ((seconds < 60 and "") or ((math.floor(seconds/60 - (hours*60)) == 1 and "1 minute, and ") or (math.floor(seconds/60 - (hours*60)).. " minutes, and "))) .. ((math.floor(seconds - hours*3600 - mins *60) == 1 and "1 second") or (math.floor(seconds - hours*3600 - mins *60).. " seconds")) .. "."
  18.     else
  19.     return hours..":"..mins..":"..secs
  20.     end
  21.   end
  22. end

 

 

 

Creaturescript (onlogin)

Spoiler

 

  1. -- If this is the first time the player is logging in, we timestamp the time when he logged in.
  2. function onLogin(cid)
  3.     if getPlayerStorageValue(cid, STORAGE_FOR_TIMESTAMP) == -1 then
  4.         setPlayerStorageValue(cid, STORAGE_FOR_TIMESTAMP, os.time())
  5.     end
  6.     return true
  7. end

 

 

 

Creaturescript (onadvanced)

Spoiler

 

  1. -- Description:
  2. -- If player advances in level, we check the saved timestamp and compare it to current time.
  3. -- The difference between these 2 times is how many seconds passed since he last got timestamped for leveling up.
  4. -- Important: Make sure to timestamp the player when he logs in for the first time. We will do this in an onLogin script.
  5.  
  6. function onAdvance(cid, skill, oldLevel, newLevel)
  7.    
  8.     local seconds = os.time() - getPlayerStorageValue(cid, STORAGE_FOR_TIMESTAMP)
  9.     if newLevel > oldLevel and skill == SKILL__LEVEL then
  10.         doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You advanced from level " ..oldLevel.. " to level " ..newLevel.. " in " .. secondsToClock(seconds, true))
  11.     end
  12.     setPlayerStorageValue(cid, STORAGE_FOR_TIMESTAMP, os.time())
  13.     return true
  14. end

 

 
Editado por poko360 (veja o histórico de edições)
Link para o post
Compartilhar em outros sites
  • Solução

Esse erro está no arquivo newadvance.lua, na linha 10.

 

No final dessa linha está chamando a função secondsToClock, mas essa função não é global e não está nesse arquivo.

 

Solução:

Acho essa linha deveria estar no início do arquivo newadvance.lua:

STORAGE_FOR_TIMESTAMP = 15854

 

Insira essa função no final do arquivo newadvance.lua:

local function secondsToClock(seconds, worded) -- Returns inputted seconds as a formatted string
  local seconds = tonumber(seconds)
 
  if seconds <= 0 then
    if worded == true then return "0 seconds."; else return "00:00:00"; end
  else
    local hours = string.format("%02.f", math.floor(seconds/3600));
    local mins = string.format("%02.f", math.floor(seconds/60 - (hours*60)));
    local secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60));
    if worded == true then
        return ((seconds<3600 and "") or ((math.floor(seconds/3600) == 1 and "1 hour, ") or (math.floor(seconds/3600)) .. " hours, ")) .. ((seconds < 60 and "") or ((math.floor(seconds/60 - (hours*60)) == 1 and "1 minute, and ") or (math.floor(seconds/60 - (hours*60)).. " minutes, and "))) .. ((math.floor(seconds - hours*3600 - mins *60) == 1 and "1 second") or (math.floor(seconds - hours*3600 - mins *60).. " seconds")) .. "."
    else
    return hours..":"..mins..":"..secs
    end
  end
end

 

 

Link para o post
Compartilhar em outros sites

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

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo