Svira
Active Member
- Joined
- Jan 27, 2008
- Messages
- 268
- Solutions
- 11
- Reaction score
- 36
Hello, I wanted to add the time in which the player reached the next level, unfortunately despite the registration in login.lua the script will not be triggered. It is read because when an error is specifically entered in it, it appears in the console.
Currently it looks like this and doesn't cause any errors, but also doesn't send print.
TFS 1.2+
Currently it looks like this and doesn't cause any errors, but also doesn't send print.
TFS 1.2+
Lua:
function onAdvance(player, skill, oldlevel, newlevel)
print("1")
if player:isPlayer() and skill == SKILL_LEVEL then
print("2")
return true
end
print("3")
oldtime = player:getStorageValue(3499)
timenow = os.time()
if oldtime == -1 then
player:setStorageValue(3499, timenow)
print("4")
else
player:sendTextMessage(MESSAGE_INFO_DESCR, "It took you " .. timeString(timenow - oldtime) .. " to advance in level from your last advance.")
player:setStorageValue(3499, timenow)
end
return true
end
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