Turbe$Z Posted April 20, 2017 Share Posted April 20, 2017 I want create a last login script, what output to the chatbox my last login, with date, and hours, when i login. But how to create? Link to comment
NeXuS™ Posted April 20, 2017 Share Posted April 20, 2017 addEventHandler("onPlayerLogin", getRootElement(), function(_, theAccount) local lastLogin = getAccountData(theAccount, "acc:lastLogin") or 0 local lastTime = getRealTime(lastLogin) local timeText = lastTime.year + 1900 .. ". " .. string.format("%02d", lastTime.month+1) .. ". " .. string.format("%02d", lastTime.monthday) .. " " .. string.format("%02d", lastTime.hour) .. ":" .. string.format("%02d", lastTime.minute) .. ":" .. string.format("%02d", lastTime.second) outputChatBox("Last login date: " .. timeText, source, 255, 255, 255, true) local timeAtm = getRealTime().timestamp setAccountData(theAccount, "acc:lastLogin", timeAtm) end) I had this done already. If you need explanations, feel free to ask. Link to comment
Turbe$Z Posted April 21, 2017 Author Share Posted April 21, 2017 13 hours ago, NeXuS™ said: addEventHandler("onPlayerLogin", getRootElement(), function(_, theAccount) local lastLogin = getAccountData(theAccount, "acc:lastLogin") or 0 local lastTime = getRealTime(lastLogin) local timeText = lastTime.year + 1900 .. ". " .. string.format("%02d", lastTime.month+1) .. ". " .. string.format("%02d", lastTime.monthday) .. " " .. string.format("%02d", lastTime.hour) .. ":" .. string.format("%02d", lastTime.minute) .. ":" .. string.format("%02d", lastTime.second) outputChatBox("Last login date: " .. timeText, source, 255, 255, 255, true) local timeAtm = getRealTime().timestamp setAccountData(theAccount, "acc:lastLogin", timeAtm) end) I had this done already. If you need explanations, feel free to ask. doesn't working this "Last login date: 1970. 01. 01 01:00:00" how to fix? Link to comment
Fist Posted April 21, 2017 Share Posted April 21, 2017 (edited) 9 minutes ago, Turbo777 said: doesn't working this "Last login date: 1970. 01. 01 01:00:00" how to fix? try this, but you will have to clear previous account data that saved lastlogin otherwise it will still show same thing. addEventHandler("onPlayerLogin", getRootElement(), function(_, theAccount) local timeAtm = getRealTime().timestamp local lastLogin = getAccountData(theAccount, "acc:lastLogin") or timeAtm local lastTime = getRealTime(lastLogin) local timeText = lastTime.year + 1900 .. ". " .. string.format("%02d", lastTime.month+1) .. ". " .. string.format("%02d", lastTime.monthday) .. " " .. string.format("%02d", lastTime.hour) .. ":" .. string.format("%02d", lastTime.minute) .. ":" .. string.format("%02d", lastTime.second) outputChatBox("Last login date: " .. timeText, source, 255, 255, 255, true) setAccountData(theAccount, "acc:lastLogin", timeAtm) end) Edited April 21, 2017 by Fist 1 Link to comment
Turbe$Z Posted April 21, 2017 Author Share Posted April 21, 2017 15 minutes ago, Fist said: try this, but you will have to clear previous account data that saved lastlogin otherwise it will still show same thing. addEventHandler("onPlayerLogin", getRootElement(), function(_, theAccount) local timeAtm = getRealTime().timestamp local lastLogin = getAccountData(theAccount, "acc:lastLogin") or timeAtm local lastTime = getRealTime(lastLogin) local timeText = lastTime.year + 1900 .. ". " .. string.format("%02d", lastTime.month+1) .. ". " .. string.format("%02d", lastTime.monthday) .. " " .. string.format("%02d", lastTime.hour) .. ":" .. string.format("%02d", lastTime.minute) .. ":" .. string.format("%02d", lastTime.second) outputChatBox("Last login date: " .. timeText, source, 255, 255, 255, true) setAccountData(theAccount, "acc:lastLogin", timeAtm) end) Thank you:D Link to comment
NeXuS™ Posted April 21, 2017 Share Posted April 21, 2017 @Turbo777, you just had to relogin once, and it would have outputted your last login, thats how it works. If you haven't logged in once before this script started running, it could output "First login" (or in my case, it outputs 1970.) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now