• Announcements

    • jhxp

      Forums are online again after a maintenance.   18/03/17

      MTA Forums maintenance is completed, although some automatic time-heavy tasks are still in process and will be finished eventually in background. Expect some features such as Forum Search to not display all results until all processes are finished. Please let us know if you spot a forum feature that worked correctly before the maintenance but does not work anymore now. Thanks. --MTA Team
    • jhxp

      Multi Theft Auto: San Andreas 1.5.4 is out!   21/04/17

      Click the link in the announcement for more details.  
Turbo777

How can i create last login script?

6 posts in this topic

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?

Share this post


Link to post
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. :D If you need explanations, feel free to ask.

Share this post


Link to post
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. :D If you need explanations, feel free to ask.

doesn't working this :/ 

"Last login date: 1970. 01. 01 01:00:00"
how to fix?

Share this post


Link to post
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 by Fist
1 person likes this

Share this post


Link to post
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

Share this post


Link to post

@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.)

Share this post


Link to post

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 account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.