Was about to say the same but
@heba already did
About the other script, I'll explain:
In your 050-functions.lib, add this new function to your library, it will come handy. Also notice STORAGE_FOR_TIMESTAMP here is being added as new constant, make sure to set it to some number of storage that you haven't used before.
Lua:
STORAGE_FOR_TIMESTAMP = 15854 -- Some storage that will save the times of player's level advancements
-- Description of function below:
-- Returns inputted seconds as a formatted string in HH:MM:SS format.
-- If the parameter "worded" is set to true, it returns a string like: "HH hours, MM minutes, and SS seconds" instead.
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
Now make a new
advance type creaturescript, description included:
Lua:
-- Description:
-- If player advances in level, we check the saved timestamp and compare it to current time.
-- The difference between these 2 times is how many seconds passed since he last got timestamped for leveling up.
-- Important: Make sure to timestamp the player when he logs in for the first time. We will do this in an onLogin script.
function onAdvance(cid, skill, oldLevel, newLevel)
local seconds = os.time() - getPlayerStorageValue(cid, STORAGE_FOR_TIMESTAMP)
if newLevel > oldLevel and skill == SKILL__LEVEL then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You advanced from level " ..oldLevel.. " to level " ..newLevel.. " in " .. secondsToClock(seconds, true))
end
setPlayerStorageValue(cid, STORAGE_FOR_TIMESTAMP, os.time())
return true
end
And lastly we need a bit of onLogin code to take care of when player logs in for the first time.
Lua:
-- If this is the first time the player is logging in, we timestamp the time when he logged in.
function onLogin(cid)
if getPlayerStorageValue(cid, STORAGE_FOR_TIMESTAMP) == -1 then
setPlayerStorageValue(cid, STORAGE_FOR_TIMESTAMP, os.time())
end
return true
end
I'm pretty sure this time (first time the player has logged in) is already saved somewhere, i think database, but it's easier to write this than make a db query for me, sue me.
That should do the trick.