Dekonpriv Posted March 25, 2023 Share Posted March 25, 2023 I'm looking for some mod that can return me the date of the last player login, but I can't find it. How would it be possible to save the date of some login? Example: person ID 10 logs in today: March 25, 2023. and this is stored when I mentalize "/lastlogin 10" it will return the last time the person logged in. I need a light Link to comment
Spakye Posted March 28, 2023 Share Posted March 28, 2023 Do you use the default mta account system or do you have your own? 1 Link to comment
chris1384 Posted March 28, 2023 Share Posted March 28, 2023 On 26/03/2023 at 00:48, Dekonpriv said: I'm looking for some mod that can return me the date of the last player login, but I can't find it. How would it be possible to save the date of some login? Example: person ID 10 logs in today: March 25, 2023. and this is stored when I mentalize "/lastlogin 10" it will return the last time the person logged in. I need a light since you mentioned that you would use IDs for the players, perhaps you are using (My)SQL for your saves use dbExec to insert or update a database column, dbQuery and dbPoll to get the results, use os.date() to retrieve the exact date and time (it's using servers time) or.. use getPlayerAccount, setAccountData and os.date() to set an accounts last login data then use getPlayerFromName, getPlayerAccount and getAccountData for /lastlogin 1 Link to comment
Dekonpriv Posted March 30, 2023 Author Share Posted March 30, 2023 (edited) On 28/03/2023 at 01:43, Spakye said: Do you use the default mta account system or do you have your own? I use the MTA pattern, which gives access to internal.db Edited March 30, 2023 by Dekonpriv Link to comment
AngelAlpha Posted March 31, 2023 Share Posted March 31, 2023 addEventHandler ("onPlayerLogin", root, function(_, acc) setAccountData(acc, "lastlogin:timestamp", getRealTime().timestamp) end) addEventHandler ("onResourceStart", resourceRoot, function() for i, v in ipairs (getAccounts()) do if not getAccountData (v, "lastlogin:timestamp") then setAccountData(acc, "lastlogin:timestamp", getRealTime().timestamp) end end end) ------------------------- addEventHandler ("onPlayerLogin", root, function(_, acc) local timestamp = getAccountData(acc, "lastlogin:timestamp") local time = getRealTime(timestamp) local day = time.monthday local month = time.month + 1 local year = time.year + 1900 local id = getElementData(source, "your ID data") or "N/A" outputDebugString ("person ID "..id.." logs in "..day.." "..month..", "..year) end) Link to comment
FLUSHBICEPS Posted April 3, 2023 Share Posted April 3, 2023 On 31/03/2023 at 16:02, AngelAlpha said: addEventHandler ("onPlayerLogin", root, function(_, acc) setAccountData(acc, "lastlogin:timestamp", getRealTime().timestamp) end) addEventHandler ("onResourceStart", resourceRoot, function() for i, v in ipairs (getAccounts()) do if not getAccountData (v, "lastlogin:timestamp") then setAccountData(acc, "lastlogin:timestamp", getRealTime().timestamp) end end end) ------------------------- addEventHandler ("onPlayerLogin", root, function(_, acc) local timestamp = getAccountData(acc, "lastlogin:timestamp") local time = getRealTime(timestamp) local day = time.monthday local month = time.month + 1 local year = time.year + 1900 local id = getElementData(source, "your ID data") or "N/A" outputDebugString ("person ID "..id.." logs in "..day.." "..month..", "..year) end) Bro what lol -- locate ur internal db db = dbConnect("sqlite", "internal.db") dbExec(db, "CREATE TABLE IF NOT EXISTS player_login_data (playerID INTEGER PRIMARY KEY, lastLoginDate TEXT)") function savePlayerLoginDate(playerID) local currentDate = os.date("%Y-%m-%d") dbExec(db, "INSERT OR REPLACE INTO player_login_data (playerID, lastLoginDate) VALUES (?, ?)", playerID, currentDate) end function getLastLoginDate(playerID, callback) dbQuery( function(qh) local result = dbPoll(qh, 0) if result and #result > 0 then callback(result[1]["lastLoginDate"]) else callback(false) end end, db, "SELECT lastLoginDate FROM player_login_data WHERE playerID=?", playerID ) end function onLastLoginCommandHandler(playerSource, command, playerID) if not playerID then outputChatBox("Usage: /lastlogin [playerID]", playerSource) return end getLastLoginDate(tonumber(playerID), function(lastLoginDate) if lastLoginDate then outputChatBox("Player ID " .. playerID .. " last logged in on: " .. lastLoginDate, playerSource) else outputChatBox("No login data found for player ID " .. playerID, playerSource) end end) end addCommandHandler("lastlogin", onLastLoginCommandHandler) addEventHandler("onPlayerLogin", root, function() local playerID = getElementData(source, "account:id") savePlayerLoginDate(playerID) end) Add the script to your mtaserver.conf Link to comment
P[ow]er Posted April 13, 2023 Share Posted April 13, 2023 On 25/03/2023 at 17:48, Dekonpriv said: I'm looking for some mod that can return me the date of the last player login, but I can't find it. How would it be possible to save the date of some login? Example: person ID 10 logs in today: March 25, 2023. and this is stored when I mentalize "/lastlogin 10" it will return the last time the person logged in. I need a light function onPlayerLogin() local playerID = getPlayerID(source) local currentDate = getDateString() -- get the current date in string format -- save the login information to the database dbExec("INSERT INTO player_logins (player_id, last_login_date) VALUES (?, ?)", playerID, currentDate) end function onCommandLastLogin(player, cmd, targetPlayerID) if not targetPlayerID then outputChatBox("Usage: /lastlogin <playerID>") return end -- retrieve the last login date from the database local result = dbQuery("SELECT last_login_date FROM player_logins WHERE player_id=?", targetPlayerID) local row = dbPoll(result, -1)[1] if not row then outputChatBox("Player not found or has not logged in before.") else local lastLoginDate = row.last_login_date outputChatBox("Player "..targetPlayerID.." last logged in on "..lastLoginDate) end end 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